Changeset 73
- Timestamp:
- May 3, 2004, 12:13:24 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/test_svm.cc
r57 r73 6 6 #include "vector.h" 7 7 #include "SVM.h" 8 #include "Kernel.h" 9 #include "PolynomialKernelFunction.h" 8 10 9 11 // Standard includes … … 18 20 19 21 { 20 cout << "reading data/nm_kernel.txt" << endl; 21 //ifstream is("k.txt"); 22 ifstream is("data/nm_kernel.txt"); 23 theplu::gslapi::matrix kernel(is); 24 is.close(); 22 cout << "reading data/nm_kernel.txt" << endl; 23 ifstream is("data/nm_kernel.txt"); 24 theplu::gslapi::matrix kernel(is); 25 is.close(); 25 26 26 27 theplu::gslapi::matrix k(kernel); 27 28 28 cout << "reading data/nm_target_bin.txt" << endl; 29 is.open("data/nm_target_bin.txt"); 29 cout << "reading data/nm_target_bin.txt" << endl; 30 is.open("data/nm_target_bin.txt"); 31 theplu::gslapi::vector target(is); 32 is.close(); 33 34 cout << "reading data/nm_alpha_linear_matlab.txt" << endl; 35 is.open("data/nm_alpha_linear_matlab.txt"); 36 theplu::gslapi::vector alpha_matlab(is); 37 is.close(); 38 39 40 cout << "create svm" << endl; 41 theplu::cpptools::SVM svm(kernel, target); 42 cout << "train" << endl; 43 svm.train(); 44 cout << "get alpha" << endl; 45 theplu::gslapi::vector alpha = svm.get_alpha(); 46 47 // Comparing alpha to alpha_matlab 48 theplu::gslapi::vector diff_alpha = alpha - alpha_matlab; 49 cout << diff_alpha*diff_alpha << endl; 30 50 31 theplu::gslapi::vector target(is); 32 is.close(); 51 // Comparing output to target 52 theplu::gslapi::vector output = svm.get_output(); 53 double slack = 0; 54 for (unsigned int i=0; i<target.size(); i++){ 55 if (output[i]*target[i] < 1){ 56 slack += 1 - output[i]*target[i]; 57 } 58 } 59 cout << "slack:" << slack << endl; 33 60 34 cout << "data/nm_alpha_linear_matlab.txt" << endl;35 is.open("data/nm_alpha_linear_matlab.txt");36 theplu::gslapi::vector alpha_matlab(is);37 is.close();38 39 //training the SVM40 cout << "Training the SVM" << endl;41 theplu::cpptools::SVM svm(kernel, target);42 cout << "Training the SVM" << endl;43 svm.train();44 45 //getting alpha46 cout << "getting alpha" << endl;47 theplu::gslapi::vector alpha;48 alpha = svm.get_alpha();49 50 // Comparing alpha to alpha_matlab51 theplu::gslapi::vector diff_alpha = alpha - alpha_matlab;52 cout << "Checking difference" << endl;53 cout << diff_alpha*diff_alpha << endl;54 55 // Comparing output to target56 theplu::gslapi::vector output = svm.get_output();57 double slack = 0;58 for (unsigned int i=0; i<target.size(); i++){59 if (output[i]*target[i] < 1){60 slack += 1 - output[i]*target[i];61 }62 }63 cout << "slack:" << slack << endl;64 65 //training the SVM66 cout << "Training the SVM" << endl;67 svm.train(1);68 69 70 61 return 0; 71 62 }
Note: See TracChangeset
for help on using the changeset viewer.