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

Function test_dense

dlib/test/svm_c_linear.cpp:246–277  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

244// ----------------------------------------------------------------------------------------
245
246 void test_dense (
247 )
248 {
249 print_spinner();
250 dlog << LINFO << "test with dense vectors";
251 std::vector<sample_type> samples;
252 std::vector<double> labels;
253
254 sample_type samp;
255
256 get_simple_points(samples,labels);
257
258 svm_c_linear_trainer<linear_kernel<sample_type> > trainer;
259 trainer.set_c(1e4);
260 //trainer.be_verbose();
261 trainer.set_epsilon(1e-11);
262
263
264 double obj;
265 decision_function<linear_kernel<sample_type> > df = trainer.train(samples, labels, obj);
266 dlog << LDEBUG << "obj: "<< obj;
267 DLIB_TEST_MSG(abs(obj - 0.72222222222) < 1e-7, abs(obj - 0.72222222222));
268 // There shouldn't be any margin violations since this dataset is so trivial. So that means the objective
269 // should be exactly the squared norm of the decision plane (times 0.5).
270 DLIB_TEST_MSG(abs(length_squared(df.basis_vectors(0))*0.5 + df.b*df.b*0.5 - 0.72222222222) < 1e-7,
271 length_squared(df.basis_vectors(0))*0.5 + df.b*df.b*0.5);
272
273 DLIB_TEST(abs(df(samples[0]) - (-1)) < 1e-6);
274 DLIB_TEST(abs(df(samples[1]) - (-1)) < 1e-6);
275 DLIB_TEST(abs(df(samples[2]) - (1)) < 1e-6);
276 DLIB_TEST(abs(df(samples[3]) - (1)) < 1e-6);
277 }
278
279// ----------------------------------------------------------------------------------------
280

Callers 1

perform_testMethod · 0.85

Calls 7

print_spinnerFunction · 0.85
get_simple_pointsFunction · 0.85
absFunction · 0.85
length_squaredFunction · 0.50
set_cMethod · 0.45
set_epsilonMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected