Changeset 335 for trunk/test/nni_test.cc


Ignore:
Timestamp:
Jun 2, 2005, 11:46:55 PM (18 years ago)
Author:
Jari Häkkinen
Message:

Added WeNNI test with binary weights (i.e. kNNI mode).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/nni_test.cc

    r301 r335  
    102102          ok=false; // calucaltion error detected
    103103        }
    104   if(ok)
    105     return 0;
    106   return -1;
     104  control_stream.close();
     105  data_stream.close();
     106  weight_stream.close();
     107
     108  // test WeNNI with binary weights
     109  data_stream.open(knni_data.c_str());
     110  data=gslapi::matrix(data_stream);
     111  weight_stream.open(knni_weight.c_str());
     112  weight=gslapi::matrix(weight_stream);
     113  utility::WeNNI wenni2(data,weight,neighbours);
     114  wenni2.estimate();
     115  control_stream.open(knni_result.c_str());
     116  control=gslapi::matrix(control_stream);
     117  control-=wenni2.imputed_data();
     118  for (unsigned int i=0; i<control.rows(); i++)
     119    for (unsigned int j=0; j<control.columns(); j++)
     120      // Jari, should we use GSL defined round off errors? Anyway, the
     121      // hardcoded number below should be changed.
     122      if (fabs(control(i,j))>error_bound) {
     123        if (print)
     124          std::cerr << "WeNNI binary weight test FAILED.\nError on row " << i
     125                    << " and column " << j << " is " << fabs(control(i,j))
     126                    << ". Expected less than " << error_bound << std::endl;
     127        ok=false; // calculation result out of accepted error bounds
     128      }
     129      else
     130        if (!((control(i,j)==control(i,j)))) {
     131          if (print)
     132            std::cerr << "WeNNI binary wieght test FAILED.\n"
     133                      << "nan (not a number) encountered in test on row " << i
     134                      << " and column " << j << std::endl;
     135          ok=false; // calucaltion error detected
     136        }
     137  control_stream.close();
     138  data_stream.close();
     139  weight_stream.close();
     140
     141  return (ok ? 0 : -1);
    107142}
Note: See TracChangeset for help on using the changeset viewer.