Changeset 209
 Timestamp:
 Nov 3, 2004, 9:24:41 AM (19 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/test_svm.cc
r127 r209 14 14 #include <iostream> 15 15 #include <cstdlib> 16 #include <limits.h> 16 17 17 18 using namespace std; … … 20 21 21 22 { 22 ifstream is("data/nm_kernel.txt"); 23 theplu::gslapi::matrix kernel_matrix(is); 24 is.close(); 23 std::cout << ULLONG_MAX << endl; 24 25 // ifstream is("data/nm_kernel.txt"); 26 // theplu::gslapi::matrix kernel_matrix(is); 27 // is.close(); 25 28 26 is.open("data/nm_target_bin.txt");27 theplu::gslapi::vector target(is);28 is.close();29 // is.open("data/nm_target_bin.txt"); 30 // theplu::gslapi::vector target(is); 31 // is.close(); 29 32 30 is.open("data/nm_alpha_linear_matlab.txt");31 theplu::gslapi::vector alpha_matlab(is);32 is.close();33 // is.open("data/nm_alpha_linear_matlab.txt"); 34 // theplu::gslapi::vector alpha_matlab(is); 35 // is.close(); 33 36 34 theplu::cpptools::SVM svm(kernel_matrix, target);35 svm.train();37 // theplu::cpptools::SVM svm(kernel_matrix, target); 38 // svm.train(); 36 39 37 theplu::gslapi::vector alpha = svm.get_alpha();40 // theplu::gslapi::vector alpha = svm.get_alpha(); 38 41 39 // Comparing alpha to alpha_matlab 40 theplu::gslapi::vector diff_alpha = alpha  alpha_matlab; 41 if (diff_alpha*diff_alpha> pow(10.0,10)){ 42 cerr << "Difference to matlab alphas too large/n"; 43 return 1; 44 } 45 // Comparing output to target 46 theplu::gslapi::vector output = svm.get_output(); 47 double slack = 0; 48 for (unsigned int i=0; i<target.size(); i++){ 49 if (output[i]*target[i] < 1){ 50 slack += 1  output[i]*target[i]; 51 } 52 } 53 if (slack > pow(10.0,10)){ 54 cerr << "Difference to matlab alphas too large/n"; 55 return 1; 56 } 57 58 // testing on XOR problem 59 cout << "testing XOR\n"; 60 theplu::gslapi::matrix data(4,2); 61 data(0,0)=1; 62 data(0,1)=1; 42 // // Comparing alpha to alpha_matlab 43 // theplu::gslapi::vector diff_alpha = alpha  alpha_matlab; 44 // if (diff_alpha*diff_alpha> pow(10.0,10)){ 45 // cerr << "Difference to matlab alphas too large/n"; 46 // return 1; 47 // } 48 // // Comparing output to target 49 // theplu::gslapi::vector output = svm.get_output(); 50 // double slack = 0; 51 // for (unsigned int i=0; i<target.size(); i++){ 52 // if (output[i]*target[i] < 1){ 53 // slack += 1  output[i]*target[i]; 54 // } 55 // } 56 // if (slack > pow(10.0,10)){ 57 // cerr << "Difference to matlab alphas too large/n"; 58 // return 1; 59 // } 63 60 64 data(1,0)=1; 65 data(1,1)=1; 66 67 data(2,0)=1; 68 data(2,1)=1; 69 70 data(3,0)=1; 71 data(3,1)=1; 72 73 target = theplu::gslapi::vector(4,1.0); 74 target(1)=1; 61 // testing on non solvable problem 62 cout << "testing \n"; 63 theplu::gslapi::matrix data(3,1); 64 data(0,0)=1; 65 data(1,0)=10; 66 data(2,0)=0; 67 68 theplu::gslapi::vector target(3,1.0); 75 69 target(2)=1; 76 70 std::cout << "target:\n" << target << "\n"; 77 71 theplu::cpptools::KernelFunction* kf = 78 72 new theplu::cpptools::PolynomialKernelFunction(); 79 73 theplu::cpptools::Kernel kernel(data,*kf); 80 svm = theplu::cpptools::SVM(kernel.get(),target); 81 // svm.train(); 82 cout << kernel.get() << "\n"; 74 theplu::gslapi::matrix m=kernel.get(); 75 std::cout << "kernel:\n" << m << "\n"; 76 theplu::cpptools::SVM svm(kernel.get(),target); 77 // svm.set_c(1); 78 svm.train(); 79 83 80 return 0; 84 81
Note: See TracChangeset
for help on using the changeset viewer.