MCPcopy Create free account
hub / github.com/davisking/dlib / perform_test

Method perform_test

dlib/test/oca.cpp:38–237  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36 }
37
38 void perform_test(
39 )
40 {
41 print_spinner();
42
43 typedef matrix<double,0,1> w_type;
44 w_type w;
45
46 decision_function<linear_kernel<w_type> > df;
47 svm_c_linear_trainer<linear_kernel<w_type> > trainer;
48 trainer.set_c_class1(2);
49 trainer.set_c_class1(3);
50 trainer.set_learns_nonnegative_weights(true);
51 trainer.set_epsilon(1e-12);
52
53 std::vector<w_type> x;
54 w_type temp(2);
55 temp = -1, 1;
56 x.push_back(temp);
57 temp = 1, -1;
58 x.push_back(temp);
59
60 std::vector<double> y;
61 y.push_back(+1);
62 y.push_back(-1);
63
64 w_type true_w(3);
65
66 oca solver;
67
68 // test the version without a non-negativity constraint on w.
69 solver(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 0.0, 40, max_index_plus_one(x)), w, 0);
70 dlog << LINFO << trans(w);
71 true_w = -0.5, 0.5, 0;
72 dlog << LINFO << "error: "<< max(abs(w-true_w));
73 DLIB_TEST(max(abs(w-true_w)) < 1e-10);
74
75 solver.solve_with_elastic_net(make_oca_problem_c_svm<w_type>(2.0, 3.0, mat(x), mat(y), false, 1e-12, 0.0, 40, max_index_plus_one(x)), w, 0.5);
76 dlog << LINFO << trans(w);
77 true_w = -0.5, 0.5, 0;
78 dlog << LINFO << "error: "<< max(abs(w-true_w));
79 DLIB_TEST(max(abs(w-true_w)) < 1e-10);
80
81 print_spinner();
82
83 w_type prior = true_w;
84 solver(make_oca_problem_c_svm<w_type>(20.0, 30.0, mat(x), mat(y), false, 1e-12, 0.0, 40, max_index_plus_one(x)), w, prior);
85 dlog << LINFO << trans(w);
86 true_w = -0.5, 0.5, 0;
87 dlog << LINFO << "error: "<< max(abs(w-true_w));
88 DLIB_TEST(max(abs(w-true_w)) < 1e-10);
89
90 prior = 0,0,0;
91 solver(make_oca_problem_c_svm<w_type>(20.0, 30.0, mat(x), mat(y), false, 1e-12, 0.0, 40, max_index_plus_one(x)), w, prior);
92 dlog << LINFO << trans(w);
93 true_w = -0.5, 0.5, 0;
94 dlog << LINFO << "error: "<< max(abs(w-true_w));
95 DLIB_TEST(max(abs(w-true_w)) < 1e-10);

Callers

nothing calls this directly

Calls 15

print_spinnerFunction · 0.85
absFunction · 0.85
join_colsFunction · 0.85
matFunction · 0.50
max_index_plus_oneFunction · 0.50
transFunction · 0.50
maxFunction · 0.50
set_c_class1Method · 0.45
set_epsilonMethod · 0.45
push_backMethod · 0.45

Tested by

no test coverage detected