Changeset 116 for trunk/test/test_svm.cc


Ignore:
Timestamp:
Jul 19, 2004, 4:40:11 PM (18 years ago)
Author:
Peter
Message:

test_crossvalidation and test_statistics added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/test_svm.cc

    r73 r116  
    2020
    2121
    22   cout << "reading data/nm_kernel.txt" << endl;
    2322  ifstream is("data/nm_kernel.txt");
    2423  theplu::gslapi::matrix kernel(is);
    2524  is.close();
    26 
    2725  theplu::gslapi::matrix k(kernel);
    2826 
    29   cout << "reading data/nm_target_bin.txt" << endl;
    3027  is.open("data/nm_target_bin.txt");
    3128  theplu::gslapi::vector target(is);
    3229  is.close();
    3330
    34   cout << "reading data/nm_alpha_linear_matlab.txt" << endl;
    3531  is.open("data/nm_alpha_linear_matlab.txt");
    3632  theplu::gslapi::vector alpha_matlab(is);
     
    3834
    3935
    40   cout << "create svm" << endl;
    4136  theplu::cpptools::SVM svm(kernel, target);
    42   cout << "train" << endl;
    4337  svm.train();
    44   cout << "get alpha" << endl;
     38
    4539  theplu::gslapi::vector alpha = svm.get_alpha();
    4640     
    4741  // Comparing alpha to alpha_matlab
    4842  theplu::gslapi::vector diff_alpha = alpha - alpha_matlab;
    49   cout << diff_alpha*diff_alpha << endl;
    50  
     43  if (diff_alpha*diff_alpha> pow(10.0,-10)){
     44    cerr << "Difference to matlab alphas too large/n";
     45    return -1;
     46  }
    5147  // Comparing output to target
    5248  theplu::gslapi::vector output = svm.get_output();
     
    5753    }
    5854  }
    59   cout << "slack:" << slack << endl;
    60 
     55  if (slack > pow(10.0,-10)){
     56    cerr << "Difference to matlab alphas too large/n";
     57    return -1;
     58  }
    6159  return 0;
     60 
    6261}
Note: See TracChangeset for help on using the changeset viewer.