Ignore:
Timestamp:
Sep 9, 2008, 6:03:15 PM (13 years ago)
Author:
Peter
Message:

refs #396 - removing a constructor in MatrixLookupWeighted? - needed to re-organize tests in ncc_test to track down an error

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ncc_test.cc

    r1437 r1483  
    4646using namespace theplu::yat;
    4747
     48void predict_nan_data_unweighted_data(test::Suite& suite);
     49
    4850int main(int argc,char* argv[])
    4951
    5052  test::Suite suite(argc, argv);
    5153  suite.err() << "testing ncc" << std::endl;
     54
     55  predict_nan_data_unweighted_data(suite);
    5256
    5357  /////////////////////////////////////////////
     
    253257  return suite.return_value();
    254258}
     259
     260void predict_nan_data_unweighted_data(test::Suite& suite)
     261{
     262  //////////////////////////////////////////////////////////////////////////
     263  // A test of predictions using weighted training resulting in NaN's
     264  // in centroids and unweighted test data
     265  //////////////////////////////////////////////////////////////////////////
     266  suite.err() << "test of predictions using nan centroids and unweighted test data\n";
     267  utility::Matrix data1(3,4);
     268  for(size_t i=0;i<3;i++) {
     269    data1(i,0)=3-i;
     270    data1(i,1)=5-i;
     271    data1(i,2)=i+1;
     272    data1(i,3)=i+3;
     273  }
     274  std::vector<std::string> vec1(4, "pos");
     275  vec1[0]="neg";
     276  vec1[1]="neg";
     277
     278  classifier::MatrixLookup ml1(data1);
     279  classifier::Target target1(vec1);
     280  utility::Matrix prediction1;
     281  utility::Matrix result1(2,4);
     282
     283  utility::Matrix weights2(3,4,1.0);
     284  weights2(1,0)=weights2(1,1)=0.0;
     285
     286  classifier::MatrixLookupWeighted mlw2(data1,weights2);
     287  classifier::NCC<statistics::EuclideanDistance> ncc2;
     288  ncc2.train(mlw2,target1);
     289  ncc2.predict(ml1,prediction1); 
     290  result1(0,0)=result1(0,1)=result1(1,2)=result1(1,3)=sqrt(3.0);
     291  result1(1,0)=result1(1,1)=sqrt(11.0);
     292  result1(0,2)=result1(0,3)=sqrt(15.0);
     293  if(!std::isnan(ncc2.centroids()(1,0)))
     294    suite.add(false);
     295  if (!suite.equal_range(prediction1.begin(), prediction1.end(),
     296                         result1.begin())) {
     297    suite.add(false);
     298    suite.err() << "Difference to expected prediction too large\n";
     299  }
     300}
Note: See TracChangeset for help on using the changeset viewer.