| 131 | |
| 132 | template <typename kernel_type> |
| 133 | void test_kcentroid_with_linear_kernel( |
| 134 | ) |
| 135 | /*! |
| 136 | requires |
| 137 | - kernel_type::sample_type == a matrix<double,5,1> |
| 138 | - kernel_type == a kernel that just computes a dot product |
| 139 | between its inputs. I.e. a linear kernel |
| 140 | ensures |
| 141 | - tests the kcentroid object with the given kernel |
| 142 | !*/ |
| 143 | { |
| 144 | // Here we declare that our samples will be 2 dimensional column vectors. |
| 145 | typedef typename kernel_type::sample_type sample_type; |
| 146 | |
| 147 | kernel_type default_kernel; |
| 148 | kcentroid<kernel_type> test(default_kernel,0.001,20); |
| 149 | |
| 150 | sample_type temp, temp2; |
| 151 | |
| 152 | temp = 2,0,0,0,0; |
| 153 | dlog << LDEBUG << test(temp) ; |
| 154 | dlog << LDEBUG << "squared_norm(): " << test.squared_norm() ; |
| 155 | |
| 156 | DLIB_TEST(approx_equal(test(temp), 2)); |
| 157 | DLIB_TEST(approx_equal(test.squared_norm(), 0)); |
| 158 | |
| 159 | // make test store the point(2,0,0,0,0) |
| 160 | test.train(temp, 0, 1); |
| 161 | dlog << LDEBUG << test(temp) ; |
| 162 | dlog << LDEBUG << "squared_norm(): " << test.squared_norm() ; |
| 163 | DLIB_TEST(approx_equal(test(temp), 0)); |
| 164 | DLIB_TEST(approx_equal(test.get_distance_function()(temp), 0)); |
| 165 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 166 | |
| 167 | temp = 0,2,0,0,0; |
| 168 | dlog << LDEBUG << test(temp) ; |
| 169 | DLIB_TEST(approx_equal(test(temp), std::sqrt(2*2 + 2*2.0))); |
| 170 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 171 | |
| 172 | // make test store the point(0,2,0,0,0) |
| 173 | test.train(temp, 0, 1); |
| 174 | |
| 175 | dlog << LDEBUG << test(temp) ; |
| 176 | DLIB_TEST(approx_equal(test(temp), 0)); |
| 177 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 178 | |
| 179 | temp = 2,0,0,0,0; |
| 180 | DLIB_TEST(approx_equal(test(temp), std::sqrt(2*2 + 2*2.0))); |
| 181 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 182 | |
| 183 | // make test store the point(1,1,0,0,0) |
| 184 | test.train(temp, 0.5, 0.5); |
| 185 | |
| 186 | temp = 0; |
| 187 | DLIB_TEST(approx_equal(test(temp), std::sqrt(2.0))); |
| 188 | DLIB_TEST(approx_equal(test.squared_norm(), 2)); |
| 189 | |
| 190 | // make test store the point(1,1,0,3,0) |
nothing calls this directly
no test coverage detected