| 625 | |
| 626 | |
| 627 | void test_neg_rosen ( |
| 628 | const matrix<double,2,1> p |
| 629 | ) |
| 630 | { |
| 631 | const double eps = 1e-15; |
| 632 | const double maxf = 10; |
| 633 | matrix<double,2,1> x, opt; |
| 634 | opt(0) = 1; |
| 635 | opt(1) = 1; |
| 636 | |
| 637 | double val = 0; |
| 638 | |
| 639 | dlog << LINFO << "testing with neg_rosen and the start point: " << trans(p); |
| 640 | |
| 641 | total_count = 0; |
| 642 | x = p; |
| 643 | val=find_max( |
| 644 | bfgs_search_strategy(), |
| 645 | objective_delta_stop_strategy(eps), neg_rosen, der_neg_rosen, x, maxf); |
| 646 | DLIB_TEST_MSG(dlib::equal(x,opt, 1e-7),opt-x); |
| 647 | DLIB_TEST(approx_equal(val , neg_rosen(x))); |
| 648 | dlog << LINFO << "find_max() bfgs: got neg_rosen in " << total_count; |
| 649 | |
| 650 | total_count = 0; |
| 651 | x = p; |
| 652 | val=find_max( |
| 653 | lbfgs_search_strategy(5), |
| 654 | objective_delta_stop_strategy(eps), neg_rosen, der_neg_rosen, x, maxf); |
| 655 | DLIB_TEST_MSG(dlib::equal(x,opt, 1e-7),opt-x); |
| 656 | DLIB_TEST(approx_equal(val , neg_rosen(x))); |
| 657 | dlog << LINFO << "find_max() lbfgs-5: got neg_rosen in " << total_count; |
| 658 | |
| 659 | total_count = 0; |
| 660 | x = p; |
| 661 | val=find_max( |
| 662 | lbfgs_search_strategy(5), |
| 663 | objective_delta_stop_strategy(eps), neg_rosen, derivative(neg_rosen), x, maxf); |
| 664 | DLIB_TEST_MSG(dlib::equal(x,opt, 1e-7),opt-x); |
| 665 | DLIB_TEST(approx_equal(val , neg_rosen(x))); |
| 666 | dlog << LINFO << "find_max() lbfgs-5: got neg_rosen/noder in " << total_count; |
| 667 | |
| 668 | |
| 669 | total_count = 0; |
| 670 | x = p; |
| 671 | val=find_max_using_approximate_derivatives( |
| 672 | cg_search_strategy(), |
| 673 | objective_delta_stop_strategy(eps), neg_rosen, x, maxf); |
| 674 | DLIB_TEST_MSG(dlib::equal(x,opt, 1e-7),opt-x); |
| 675 | DLIB_TEST(approx_equal(val , neg_rosen(x))); |
| 676 | dlog << LINFO << "find_max() cg: got neg_rosen/noder2 in " << total_count; |
| 677 | |
| 678 | |
| 679 | total_count = 0; |
| 680 | x = p; |
| 681 | val=find_max_bobyqa(neg_rosen, x, 2*x.size()+1, |
| 682 | uniform_matrix<double>(x.size(),1,-1e100), |
| 683 | uniform_matrix<double>(x.size(),1,1e100), |
| 684 | (max(abs(x))+1)/10, |
no test coverage detected