Changeset 217


Ignore:
Timestamp:
Dec 29, 2004, 10:37:24 AM (18 years ago)
Author:
Peter
Message:

test_regression_local added

Location:
trunk/test
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/Makefile.am

    r210 r217  
    77  test_inputranker                                                  \
    88  test_kernel test_merge test_nni test_pca test_regression_linear \
    9   test_rnd test_roc       \
     9  test_regression_local test_rnd test_roc       \
    1010  test_statistics test_svd test_svm test_vector
    1111
     
    4646    $(GSL_LIB) $(CBLAS_LIB) $(MATH_LIB)
    4747
     48test_regression_local_SOURCES = test_regression_local.cc
     49test_regression_local_LDADD = @top_srcdir@/$(CPP_TOOLS_LIB_LOCATION)/$(CPP_TOOLS_LIB) \
     50    $(GSL_LIB) $(CBLAS_LIB) $(MATH_LIB)
     51
    4852test_rnd_SOURCES = test_rnd.cc
    4953test_rnd_LDADD = @top_srcdir@/$(CPP_TOOLS_LIB_LOCATION)/$(CPP_TOOLS_LIB) \
  • trunk/test/test_regression_linear.cc

    r212 r217  
    3636  w(3)=0.4;
    3737
    38   double c0, c1, cov00, cov01, cov11, chisq;
    39   int n=4;
    40   int i=4;
    41   gsl_fit_wlinear(x.gsl_vector_pointer()->data, x.gsl_vector_pointer()->stride,
    42                   w.gsl_vector_pointer()->data, w.gsl_vector_pointer()->stride,
    43                   y.gsl_vector_pointer()->data, y.gsl_vector_pointer()->stride,
    44                   x.gsl_vector_pointer()->size,
    45                   &c0, &c1,
    46                   &cov00, &cov01, &cov11, &chisq);
     38  theplu::statistics::RegressionLinear r;
     39  r.fit_weighted(x,w,y);
     40  printf("# best fit: Y = %g + %g X\n", r.m(), r.k());
    4741
    48   printf("# best fit: Y = %g + %g X\n", c0, c1);
    49   printf("# covariance matrix:\n");
    50   printf("# [ %g, %g\n#   %g, %g]\n", cov00, cov01, cov01, cov11);
    51   printf("# chisq = %g\n", chisq);
    52 
    53   for (i = 0; i < n; i++)
    54     printf("data: %g %g %g\n", x[i], y[i], 1/sqrt(w[i]));
    55 
    56   printf("\n");
    57 
    58   for (i = -30 ; i < 130 ; i++)
    59     {
    60       double xf = x[0] + (i/100.0) * (x[n-1] - x[0]);
    61       double yf, yf_err;
    62 
    63       gsl_fit_linear_est (xf, c0, c1, cov00, cov01, cov11, &yf, &yf_err);
    64 
    65       printf("fit: %g %g\n", xf, yf);
    66       printf("hi : %g %g\n", xf, yf + yf_err);
    67       printf("lo : %g %g\n", xf, yf - yf_err);
    68     }
    69 
     42  r.fit(x,y);
     43  printf("# best fit: Y = %g + %g X\n", r.m(), r.k());
    7044
    7145  if (ok)
Note: See TracChangeset for help on using the changeset viewer.