MCPcopy Create free account
hub / github.com/davisking/dlib / test_kcentroid_with_sparse_linear_kernel

Function test_kcentroid_with_sparse_linear_kernel

dlib/test/kcentroid.cpp:356–529  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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" ;

Callers

nothing calls this directly

Calls 11

testFunction · 0.70
approx_equalFunction · 0.70
sqrtFunction · 0.50
lengthFunction · 0.50
length_squaredFunction · 0.50
distanceFunction · 0.50
squared_normMethod · 0.45
trainMethod · 0.45
clearMethod · 0.45
get_distance_functionMethod · 0.45
inner_productMethod · 0.45

Tested by

no test coverage detected