| 71 | } |
| 72 | |
| 73 | void run_prior_sparse_test() |
| 74 | { |
| 75 | typedef std::map<unsigned long,double> sample_type; |
| 76 | typedef sparse_linear_kernel<sample_type> kernel_type; |
| 77 | |
| 78 | svm_c_linear_trainer<kernel_type> trainer; |
| 79 | |
| 80 | std::vector<sample_type> samples; |
| 81 | std::vector<double> labels; |
| 82 | |
| 83 | sample_type samp; |
| 84 | samp[0] = 1; samples.push_back(samp); labels.push_back(+1); samp.clear(); |
| 85 | samp[1] = 1; samples.push_back(samp); labels.push_back(-1); samp.clear(); |
| 86 | |
| 87 | trainer.set_c(10); |
| 88 | decision_function<kernel_type> df = trainer.train(samples, labels); |
| 89 | |
| 90 | trainer.set_prior(df); |
| 91 | |
| 92 | samples.clear(); |
| 93 | labels.clear(); |
| 94 | samp[2] = 1; samples.push_back(samp); labels.push_back(+1); samp.clear(); |
| 95 | samp[1] = 1; samples.push_back(samp); labels.push_back(-1); samp.clear(); |
| 96 | |
| 97 | df = trainer.train(samples, labels); |
| 98 | |
| 99 | matrix<double,1,2> rs = test_binary_decision_function(df, samples, labels); |
| 100 | dlog << LINFO << rs; |
| 101 | DLIB_TEST(rs(0) == 1); |
| 102 | DLIB_TEST(rs(1) == 1); |
| 103 | |
| 104 | matrix<double,0,1> w = sparse_to_dense(df.basis_vectors(0)); |
| 105 | dlog << LINFO << trans(w); |
| 106 | DLIB_TEST(w(0) > 0.1); |
| 107 | DLIB_TEST(w(1) < -0.1); |
| 108 | DLIB_TEST(w(2) > 0.1); |
| 109 | } |
| 110 | |
| 111 | void get_simple_points ( |
| 112 | std::vector<sample_type>& samples, |
no test coverage detected