Changeset 1246


Ignore:
Timestamp:
Mar 17, 2008, 1:58:43 PM (13 years ago)
Author:
Peter
Message:

working in #223

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/roc_test.cc

    r1145 r1246  
    2222*/
    2323
     24#include "Suite.h"
     25
    2426#include "yat/classifier/DataLookupWeighted1D.h"
    2527#include "yat/classifier/Target.h"
     
    3537using namespace theplu::yat;
    3638
    37 int main(const int argc,const char* argv[])
     39int main(int argc, char* argv[])
    3840
    39   std::ostream* error;
    40   if (argc>1 && argv[1]==std::string("-v"))
    41     error = &std::cerr;
    42   else {
    43     error = new std::ofstream("/dev/null");
    44     if (argc>1)
    45       std::cout << "roc_test -v : for printing extra information\n";
    46   }
    47   bool ok = true;
     41  test::Suite suite(argc, argv);
    4842
    49   *error << "testing ROC" << std::endl;
     43  suite.err() << "testing ROC" << std::endl;
    5044  utility::Vector value(31);
    5145  std::vector<std::string> label(31,"negative");
     
    5852  add(roc, value.begin(), value.end(), target);
    5953  double area = roc.area();
    60   if (area!=0.0){
    61     *error << "test_roc: area is " << area << " should be 0.0"
     54  if (!suite.equal(area,0.0)){
     55    suite.err() << "test_roc: area is " << area << " should be 0.0"
    6256           << std::endl;
    63     ok = false;
     57    suite.add(false);
    6458  }
    6559  target.set_binary(0,false);
     
    6862  add(roc, value.begin(), value.end(), target);
    6963  area = roc.area();
    70   if (area!=1.0){
    71     *error << "test_roc: area is " << area << " should be 1.0"
     64  if (!suite.equal(area,1.0)){
     65    suite.err() << "test_roc: area is " << area << " should be 1.0"
    7266           << std::endl;
    73     ok = false;
     67    suite.add(false);
    7468  }
    7569 
     
    7771  double p2 = roc.p_value();
    7872  double p_matlab = 0.00000115;
    79   if (p/p_matlab > 1.01 | p/p_matlab < 0.99){
    80     *error << "get_p_approx: p-value not correct" << std::endl;
    81     *error << p << " expected " << p_matlab << std::endl;
    82     ok = false;
     73  if (!(p/p_matlab < 1.01 && p/p_matlab > 0.99)){
     74    suite.err() << "get_p_approx: p-value not correct" << std::endl;
     75    suite.err() << p << " expected " << p_matlab << std::endl;
     76    suite.add(false);
    8377  }
    84   if (p2 != 2*p) {
    85     ok = false;
    86     *error << "Two-sided P-value should equal 2 * one-sided P-value.\n";
     78  if (!(p2==2*p)) {
     79    suite.add(false);
     80    suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n";
    8781  }
    8882  roc.minimum_size() = 20;
    8983  p = roc.p_value_one_sided();
    9084  p2 = roc.p_value();
    91   if (p > pow(10, -8.0) | p < pow(10, -9.0)){
    92     *error << "get_p_exact: p-value not correct" << std::endl;
    93     ok = false;
     85  if (!( p < 1e-8 && p > 1e-9) ){
     86    suite.err() << "get_p_exact: p-value not correct" << std::endl;
     87    suite.add(false);
    9488  }
    95   if (p2 != 2*p) {
    96     ok = false;
    97     *error << "Two-sided P-value should equal 2 * one-sided P-value.\n";
     89  if (!( p2==2*p)) {
     90    suite.add(false);
     91    suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n";
    9892  }
    9993 
     
    10195  add(roc, dlw.begin(), dlw.end(), target);
    10296
    103   if (ok)
    104     return 0;
    105   return -1;
     97  return suite.return_value();
    10698}
Note: See TracChangeset for help on using the changeset viewer.