| 354 | |
| 355 | template <typename kernel_type> |
| 356 | void test_kcentroid_with_sparse_linear_kernel( |
| 357 | ) |
| 358 | /*! |
| 359 | requires |
| 360 | - kernel_type::sample_type == a std::map<unsigned long,double> |
| 361 | - kernel_type == a kernel that just computes a dot product |
| 362 | between its inputs. I.e. a linear kernel |
| 363 | ensures |
| 364 | - tests the kcentroid object with the given kernel |
| 365 | !*/ |
| 366 | { |
| 367 | // Here we declare that our samples will be 2 dimensional column vectors. |
| 368 | typedef typename kernel_type::sample_type sample_type; |
| 369 | |
| 370 | kernel_type default_kernel; |
| 371 | kcentroid<kernel_type> test(default_kernel,0.001,20); |
| 372 | |
| 373 | dlog << LDEBUG << "AAAA 1" ; |
| 374 | |
| 375 | sample_type temp, temp2; |
| 376 | |
| 377 | temp[0] = 2; |
| 378 | dlog << LDEBUG << test(temp) ; |
| 379 | dlog << LDEBUG << "squared_norm(): " << test.squared_norm() ; |
| 380 | |
| 381 | DLIB_TEST(approx_equal(test(temp), 2)); |
| 382 | DLIB_TEST(approx_equal(test.squared_norm(), 0)); |
| 383 | |
| 384 | // make test store the point(2,0,0,0,0) |
| 385 | test.train(temp, 0, 1); |
| 386 | dlog << LDEBUG << test(temp) ; |
| 387 | dlog << LDEBUG << "squared_norm(): " << test.squared_norm() ; |
| 388 | DLIB_TEST(approx_equal(test(temp), 0)); |
| 389 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 390 | |
| 391 | dlog << LDEBUG << "AAAA 2" ; |
| 392 | temp.clear(); |
| 393 | temp[1] = 2; |
| 394 | dlog << LDEBUG << test(temp) ; |
| 395 | DLIB_TEST(approx_equal(test(temp), std::sqrt(2*2 + 2*2.0))); |
| 396 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 397 | |
| 398 | // make test store the point(0,2,0,0,0) |
| 399 | test.train(temp, 0, 1); |
| 400 | |
| 401 | dlog << LDEBUG << test(temp) ; |
| 402 | DLIB_TEST(approx_equal(test(temp), 0)); |
| 403 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 404 | |
| 405 | temp.clear(); |
| 406 | temp[0] = 2; |
| 407 | DLIB_TEST(approx_equal(test(temp), std::sqrt(2*2 + 2*2.0))); |
| 408 | DLIB_TEST(approx_equal(test.squared_norm(), 4)); |
| 409 | |
| 410 | // make test store the point(1,1,0,0,0) |
| 411 | test.train(temp, 0.5, 0.5); |
| 412 | |
| 413 | dlog << LDEBUG << "AAAA 3" ; |
nothing calls this directly
no test coverage detected