| 392 | // ---------------------------------------------------------------------------------------- |
| 393 | |
| 394 | void test_sparse_1_sample(double label) |
| 395 | { |
| 396 | typedef std::vector<std::pair<unsigned long,double> > sample_type; |
| 397 | |
| 398 | |
| 399 | typedef sparse_linear_kernel<sample_type> kernel_type; |
| 400 | |
| 401 | |
| 402 | |
| 403 | svm_c_linear_dcd_trainer<kernel_type> linear_trainer; |
| 404 | |
| 405 | svm_c_linear_dcd_trainer<kernel_type>::optimizer_state state; |
| 406 | |
| 407 | const double C = 10; |
| 408 | linear_trainer.set_epsilon(1e-10); |
| 409 | linear_trainer.set_c(C); |
| 410 | |
| 411 | |
| 412 | linear_trainer.force_last_weight_to_1(true); |
| 413 | linear_trainer.include_bias(false); |
| 414 | |
| 415 | std::vector<sample_type> samples; |
| 416 | std::vector<double> labels; |
| 417 | |
| 418 | // make an instance of a sample vector so we can use it below |
| 419 | sample_type sample; |
| 420 | |
| 421 | sample.push_back(make_pair(0,-1)); |
| 422 | sample.push_back(make_pair(1,1)); |
| 423 | sample.push_back(make_pair(9,4)); |
| 424 | |
| 425 | for (int i = 0; i < 4; ++i) |
| 426 | { |
| 427 | samples.push_back(sample); |
| 428 | labels.push_back(label); |
| 429 | |
| 430 | decision_function<kernel_type> df; |
| 431 | df = linear_trainer.train(samples, labels); |
| 432 | |
| 433 | |
| 434 | if (label > 0) |
| 435 | { |
| 436 | DLIB_TEST(std::abs(df(samples[0])-4) < 1e-8); |
| 437 | } |
| 438 | else |
| 439 | { |
| 440 | DLIB_TEST(std::abs(df(samples[0])+1) < 1e-8); |
| 441 | } |
| 442 | } |
| 443 | } |
| 444 | |
| 445 | // ---------------------------------------------------------------------------------------- |
| 446 |
no test coverage detected