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

Function test_normal_1_sample

dlib/test/svm_c_linear_dcd.cpp:341–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

339// ----------------------------------------------------------------------------------------
340
341 void test_normal_1_sample(double label)
342 {
343 typedef matrix<double,10,1> sample_type;
344
345
346 typedef linear_kernel<sample_type> kernel_type;
347
348
349
350 svm_c_linear_dcd_trainer<kernel_type> linear_trainer;
351
352 svm_c_linear_dcd_trainer<kernel_type>::optimizer_state state;
353
354 const double C = 10;
355 linear_trainer.set_epsilon(1e-10);
356 linear_trainer.set_c(C);
357
358
359 linear_trainer.force_last_weight_to_1(true);
360 linear_trainer.include_bias(false);
361
362 std::vector<sample_type> samples;
363 std::vector<double> labels;
364
365 // make an instance of a sample vector so we can use it below
366 sample_type sample;
367
368 sample = 0;
369 sample(0) = -1;
370 sample(1) = -1;
371 sample(9) = 4;
372
373 samples.push_back(sample);
374 labels.push_back(label);
375
376 for (int i = 0; i < 4; ++i)
377 {
378 decision_function<kernel_type> df;
379 df = linear_trainer.train(samples, labels);
380
381 if (label > 0)
382 {
383 DLIB_TEST(std::abs(df(samples[0])-4) < 1e-8);
384 }
385 else
386 {
387 DLIB_TEST(std::abs(df(samples[0])+1) < 1e-8);
388 }
389 }
390 }
391
392// ----------------------------------------------------------------------------------------
393

Callers 1

perform_testMethod · 0.85

Calls 7

absFunction · 0.85
include_biasMethod · 0.80
set_epsilonMethod · 0.45
set_cMethod · 0.45
push_backMethod · 0.45
trainMethod · 0.45

Tested by

no test coverage detected