| 517 | {} |
| 518 | |
| 519 | void run_test ( |
| 520 | const std::vector<sample_type>& samples, |
| 521 | const std::vector<scalar_type>& labels, |
| 522 | const double true_obj |
| 523 | ) |
| 524 | { |
| 525 | typedef linear_kernel<sample_type> kernel_type; |
| 526 | svm_multiclass_linear_trainer<kernel_type> trainer1; |
| 527 | test_svm_multiclass_linear_trainer2<kernel_type> trainer2; |
| 528 | test_svm_multiclass_linear_trainer3<kernel_type> trainer3; |
| 529 | test_svm_multiclass_linear_trainer4<kernel_type> trainer4; |
| 530 | test_svm_multiclass_linear_trainer5<kernel_type> trainer5; |
| 531 | |
| 532 | trainer1.set_epsilon(1e-4); |
| 533 | trainer1.set_c(10); |
| 534 | |
| 535 | |
| 536 | multiclass_linear_decision_function<kernel_type,double> df1, df2, df3, df4, df5; |
| 537 | double obj1, obj2, obj3, obj4, obj5; |
| 538 | |
| 539 | // Solve a multiclass SVM a whole bunch of different ways and make sure |
| 540 | // they all give the same answer. |
| 541 | print_spinner(); |
| 542 | df1 = trainer1.train(samples, labels, obj1); |
| 543 | print_spinner(); |
| 544 | df2 = trainer2.train(samples, labels, obj2); |
| 545 | print_spinner(); |
| 546 | df3 = trainer3.train(samples, labels, obj3); |
| 547 | print_spinner(); |
| 548 | df4 = trainer4.train(samples, labels, obj4); |
| 549 | print_spinner(); |
| 550 | df5 = trainer5.train(samples, labels, obj5); |
| 551 | print_spinner(); |
| 552 | |
| 553 | dlog << LINFO << "obj1: "<< obj1; |
| 554 | dlog << LINFO << "obj2: "<< obj2; |
| 555 | dlog << LINFO << "obj3: "<< obj3; |
| 556 | dlog << LINFO << "obj4: "<< obj4; |
| 557 | dlog << LINFO << "obj5: "<< obj5; |
| 558 | DLIB_TEST(std::abs(obj1 - obj2) < 1e-2); |
| 559 | DLIB_TEST(std::abs(obj1 - obj3) < 1e-2); |
| 560 | DLIB_TEST(std::abs(obj1 - obj4) < 1e-2); |
| 561 | DLIB_TEST(std::abs(obj1 - obj5) < 1e-2); |
| 562 | DLIB_TEST(std::abs(obj1 - true_obj) < 1e-2); |
| 563 | DLIB_TEST(std::abs(obj2 - true_obj) < 1e-2); |
| 564 | DLIB_TEST(std::abs(obj3 - true_obj) < 1e-2); |
| 565 | DLIB_TEST(std::abs(obj4 - true_obj) < 1e-2); |
| 566 | DLIB_TEST(std::abs(obj5 - true_obj) < 1e-2); |
| 567 | |
| 568 | dlog << LINFO << "weight error: "<< max(abs(df1.weights - df2.weights)); |
| 569 | dlog << LINFO << "weight error: "<< max(abs(df1.weights - df3.weights)); |
| 570 | dlog << LINFO << "weight error: "<< max(abs(df1.weights - df4.weights)); |
| 571 | dlog << LINFO << "weight error: "<< max(abs(df1.weights - df5.weights)); |
| 572 | |
| 573 | DLIB_TEST(max(abs(df1.weights - df2.weights)) < 1e-2); |
| 574 | DLIB_TEST(max(abs(df1.weights - df3.weights)) < 1e-2); |
| 575 | DLIB_TEST(max(abs(df1.weights - df4.weights)) < 1e-2); |
| 576 | DLIB_TEST(max(abs(df1.weights - df5.weights)) < 1e-2); |
nothing calls this directly
no test coverage detected