| 33 | // ---------------------------------------------------------------------------------------- |
| 34 | |
| 35 | void run_prior_test() |
| 36 | { |
| 37 | typedef matrix<double,3,1> sample_type; |
| 38 | typedef linear_kernel<sample_type> kernel_type; |
| 39 | |
| 40 | svm_c_linear_trainer<kernel_type> trainer; |
| 41 | |
| 42 | std::vector<sample_type> samples; |
| 43 | std::vector<double> labels; |
| 44 | |
| 45 | sample_type samp; |
| 46 | samp = 0, 0, 1; samples.push_back(samp); labels.push_back(+1); |
| 47 | samp = 0, 1, 0; samples.push_back(samp); labels.push_back(-1); |
| 48 | |
| 49 | trainer.set_c(10); |
| 50 | decision_function<kernel_type> df = trainer.train(samples, labels); |
| 51 | |
| 52 | trainer.set_prior(df); |
| 53 | |
| 54 | samples.clear(); |
| 55 | labels.clear(); |
| 56 | samp = 1, 0, 0; samples.push_back(samp); labels.push_back(+1); |
| 57 | samp = 0, 1, 0; samples.push_back(samp); labels.push_back(-1); |
| 58 | |
| 59 | df = trainer.train(samples, labels); |
| 60 | |
| 61 | samp = 0, 0, 1; samples.push_back(samp); labels.push_back(+1); |
| 62 | matrix<double,1,2> rs = test_binary_decision_function(df, samples, labels); |
| 63 | dlog << LINFO << rs; |
| 64 | DLIB_TEST(rs(0) == 1); |
| 65 | DLIB_TEST(rs(1) == 1); |
| 66 | |
| 67 | dlog << LINFO << trans(df.basis_vectors(0)); |
| 68 | DLIB_TEST(df.basis_vectors(0)(0) > 0); |
| 69 | DLIB_TEST(df.basis_vectors(0)(1) < 0); |
| 70 | DLIB_TEST(df.basis_vectors(0)(2) > 0); |
| 71 | } |
| 72 | |
| 73 | void run_prior_sparse_test() |
| 74 | { |
no test coverage detected