Last change
on this file since 73 was
73,
checked in by Peter, 18 years ago
|
changes to match svm class
|
-
Property svn:eol-style set to
native
-
Property svn:keywords set to
Author Date Id Revision
|
File size:
1.4 KB
|
Line | |
---|
1 | // $Id: test_svm.cc 73 2004-05-03 10:13:24Z peter $ |
---|
2 | |
---|
3 | // C++ tools include |
---|
4 | //////////////////// |
---|
5 | #include "matrix.h" |
---|
6 | #include "vector.h" |
---|
7 | #include "SVM.h" |
---|
8 | #include "Kernel.h" |
---|
9 | #include "PolynomialKernelFunction.h" |
---|
10 | |
---|
11 | // Standard includes |
---|
12 | //////////////////// |
---|
13 | #include <fstream> |
---|
14 | #include <iostream> |
---|
15 | #include <cstdlib> |
---|
16 | |
---|
17 | using namespace std; |
---|
18 | |
---|
19 | int main() |
---|
20 | |
---|
21 | { |
---|
22 | cout << "reading data/nm_kernel.txt" << endl; |
---|
23 | ifstream is("data/nm_kernel.txt"); |
---|
24 | theplu::gslapi::matrix kernel(is); |
---|
25 | is.close(); |
---|
26 | |
---|
27 | theplu::gslapi::matrix k(kernel); |
---|
28 | |
---|
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; |
---|
50 | |
---|
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; |
---|
60 | |
---|
61 | return 0; |
---|
62 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.