RMS error on the test set INPUT PARAMETERS: LM - linear model XY - test set NPoints - test set size RESULT: average relative error. -- ALGLIB -- Copyright 30.08.2008 by Bochkanov Sergey *************************************************************************/
| 565 | Copyright 30.08.2008 by Bochkanov Sergey |
| 566 | *************************************************************************/ |
| 567 | double lravgrelerror(const linearmodel& lm, |
| 568 | const ap::real_2d_array& xy, |
| 569 | int npoints) |
| 570 | { |
| 571 | double result; |
| 572 | int i; |
| 573 | int k; |
| 574 | double v; |
| 575 | int offs; |
| 576 | int nvars; |
| 577 | |
| 578 | ap::ap_error::make_assertion(ap::round_f(lm.w(1))==lrvnum, "LINREG: Incorrect LINREG version!"); |
| 579 | nvars = ap::round_f(lm.w(2)); |
| 580 | offs = ap::round_f(lm.w(3)); |
| 581 | result = 0; |
| 582 | k = 0; |
| 583 | for(i = 0; i <= npoints-1; i++) |
| 584 | { |
| 585 | if( ap::fp_neq(xy(i,nvars),0) ) |
| 586 | { |
| 587 | v = ap::vdotproduct(&xy(i, 0), 1, &lm.w(offs), 1, ap::vlen(0,nvars-1)); |
| 588 | v = v+lm.w(offs+nvars); |
| 589 | result = result+fabs((v-xy(i,nvars))/xy(i,nvars)); |
| 590 | k = k+1; |
| 591 | } |
| 592 | } |
| 593 | if( k!=0 ) |
| 594 | { |
| 595 | result = result/k; |
| 596 | } |
| 597 | return result; |
| 598 | } |
| 599 | |
| 600 | |
| 601 | /************************************************************************* |
no test coverage detected