Changeset 1076


Ignore:
Timestamp:
Feb 12, 2008, 2:51:11 PM (16 years ago)
Author:
Markus Ringnér
Message:

NCC done for ticket:259

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/ncc_test.cc

    r1075 r1076  
    134134  }
    135135
    136  
     136  //////////////////////////////////////////////////////////////////////////
     137  // A test of predictions using weighted training resulting in NaN's
     138  // in centroids and unweighted test data
     139  //////////////////////////////////////////////////////////////////////////
     140  *error << "test of predictions using nan centroids and unweighted test data\n";
     141  utility::matrix weights2(3,4,1.0);
     142  weights2(1,0)=weights2(1,1)=0.0;
     143  classifier::MatrixLookupWeighted mlw2(data1,weights2);
     144  classifier::NCC<statistics::EuclideanDistance> ncc2(mlw2,target1);
     145  ncc2.train();
     146  ncc2.predict(ml1,prediction1); 
     147  result1(0,0)=result1(0,1)=result1(1,2)=result1(1,3)=sqrt(3.0);
     148  result1(1,0)=result1(1,1)=sqrt(11.0);
     149  result1(0,2)=result1(0,3)=sqrt(15.0);
     150  slack = deviation(prediction1,result1);
     151  if (slack > slack_bound || std::isnan(slack)){
     152    *error << "Difference to expected prediction too large\n";
     153    *error << "slack: " << slack << std::endl;
     154    *error << "expected less than " << slack_bound << std::endl;
     155    ok = false;
     156  }
    137157
    138158  //////////////////////////////////////////////////////////////////////////
  • trunk/yat/classifier/NCC.h

    r1050 r1076  
    198198        }
    199199        for(size_t c=0;c<target_.nof_classes();c++) {
    200           (*centroids_)(i,c) = class_averager[c].mean();
    201           if(class_averager[c].sum_w()==0)
     200          if(class_averager[c].sum_w()==0) {
    202201            centroids_nan_=true;
     202            (*centroids_)(i,c) = std::numeric_limits<double>::quiet_NaN();
     203          }
     204          else {
     205            (*centroids_)(i,c) = class_averager[c].mean();
     206          }
    203207        }
    204208      }
     
    235239    if (const MatrixLookup* test_unweighted =
    236240        dynamic_cast<const MatrixLookup*>(&test)) {
    237       // If weighted training data resulting in NaN in centroids: weighted calculations
     241      // If weighted training data has resulted in NaN in centroids: weighted calculations
    238242      if(centroids_nan_) {
    239         //        predict_weighted(MatrixLookupWeighted(*test_unweighted),prediction);
    240         std::string str =
    241         "Error in NCC<Distance>::predict: weighted training unweighted test not implemented yet";
    242       throw std::runtime_error(str);
     243        predict_weighted(MatrixLookupWeighted(*test_unweighted),prediction);
    243244      }
    244245      // If unweighted training data: unweighted calculations
Note: See TracChangeset for help on using the changeset viewer.