| 40 | |
| 41 | |
| 42 | void perform_test ( |
| 43 | ) |
| 44 | { |
| 45 | print_spinner(); |
| 46 | typedef std::map<unsigned long,double> sample_type; |
| 47 | |
| 48 | typedef matrix<double,0,1> dense_sample_type; |
| 49 | |
| 50 | typedef sparse_linear_kernel<sample_type> kernel_type; |
| 51 | typedef linear_kernel<dense_sample_type> dense_kernel_type; |
| 52 | |
| 53 | |
| 54 | svm_nu_trainer<kernel_type> linear_trainer; |
| 55 | linear_trainer.set_nu(0.2); |
| 56 | svm_nu_trainer<dense_kernel_type> dense_linear_trainer; |
| 57 | dense_linear_trainer.set_nu(0.2); |
| 58 | |
| 59 | std::vector<sample_type> samples; |
| 60 | std::vector<double> labels; |
| 61 | |
| 62 | // make an instance of a sample vector so we can use it below |
| 63 | sample_type sample; |
| 64 | |
| 65 | // Now lets go into a loop and randomly generate 300 samples. |
| 66 | double label = +1; |
| 67 | for (int i = 0; i < 300; ++i) |
| 68 | { |
| 69 | // flip this flag |
| 70 | label *= -1; |
| 71 | |
| 72 | sample.clear(); |
| 73 | |
| 74 | // now make a random sparse sample with at most 10 non-zero elements |
| 75 | for (int j = 0; j < 10; ++j) |
| 76 | { |
| 77 | int idx = rnd.get_random_32bit_number()%100; |
| 78 | double value = rnd.get_random_double(); |
| 79 | |
| 80 | sample[idx] = label*value; |
| 81 | } |
| 82 | |
| 83 | // Also save the samples we are generating so we can let the svm_c_linear_trainer |
| 84 | // learn from them below. |
| 85 | samples.push_back(sample); |
| 86 | labels.push_back(label); |
| 87 | } |
| 88 | |
| 89 | |
| 90 | { |
| 91 | print_spinner(); |
| 92 | dlog << LINFO << " test with sparse samples "; |
| 93 | decision_function<kernel_type> df = linear_trainer.train(samples, labels); |
| 94 | |
| 95 | dlog << LINFO << "df.basis_vectors.size(): "<< df.basis_vectors.size(); |
| 96 | DLIB_TEST(df.basis_vectors.size() > 4); |
| 97 | |
| 98 | dlog << LINFO << "test scores: "<< test_binary_decision_function(df, samples, labels); |
| 99 |
nothing calls this directly
no test coverage detected