| 692 | // ---------------------------------------------------------------------------------------- |
| 693 | |
| 694 | void test_single_variable_function ( |
| 695 | const double p |
| 696 | ) |
| 697 | { |
| 698 | const double eps = 1e-7; |
| 699 | |
| 700 | |
| 701 | dlog << LINFO << "testing with single_variable_function and the start point: " << p; |
| 702 | double out, x; |
| 703 | |
| 704 | total_count = 0; |
| 705 | x = p; |
| 706 | out = find_min_single_variable(single_variable_function, x, -1e100, 1e100, eps, 1000); |
| 707 | DLIB_TEST_MSG(std::abs(out-5) < 1e-6, out-5); |
| 708 | DLIB_TEST_MSG(std::abs(x) < 1e-6, x); |
| 709 | dlog << LINFO << "find_min_single_variable(): got single_variable_function in " << total_count; |
| 710 | |
| 711 | |
| 712 | total_count = 0; |
| 713 | x = p; |
| 714 | out = -find_max_single_variable(negate_function(single_variable_function), x, -1e100, 1e100, eps, 1000); |
| 715 | DLIB_TEST_MSG(std::abs(out-5) < 1e-6, out-5); |
| 716 | DLIB_TEST_MSG(std::abs(x) < 1e-6, x); |
| 717 | dlog << LINFO << "find_max_single_variable(): got single_variable_function in " << total_count; |
| 718 | |
| 719 | |
| 720 | if (p > 0) |
| 721 | { |
| 722 | total_count = 0; |
| 723 | x = p; |
| 724 | out = find_min_single_variable(single_variable_function, x, -1e-4, 1e100, eps, 1000); |
| 725 | DLIB_TEST_MSG(std::abs(out-5) < 1e-6, out-5); |
| 726 | DLIB_TEST_MSG(std::abs(x) < 1e-6, x); |
| 727 | dlog << LINFO << "find_min_single_variable(): got single_variable_function in " << total_count; |
| 728 | |
| 729 | |
| 730 | if (p > 3) |
| 731 | { |
| 732 | total_count = 0; |
| 733 | x = p; |
| 734 | out = -find_max_single_variable(negate_function(single_variable_function), x, 3, 1e100, eps, 1000); |
| 735 | DLIB_TEST_MSG(std::abs(out - (3*3*3+5)) < 1e-6, out-(3*3*3+5)); |
| 736 | DLIB_TEST_MSG(std::abs(x-3) < 1e-6, x); |
| 737 | dlog << LINFO << "find_max_single_variable(): got single_variable_function in " << total_count; |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | if (p < 0) |
| 742 | { |
| 743 | total_count = 0; |
| 744 | x = p; |
| 745 | out = find_min_single_variable(single_variable_function, x, -1e100, 1e-4, eps, 1000); |
| 746 | DLIB_TEST_MSG(std::abs(out-5) < 1e-6, out-5); |
| 747 | DLIB_TEST_MSG(std::abs(x) < 1e-6, x); |
| 748 | dlog << LINFO << "find_min_single_variable(): got single_variable_function in " << total_count; |
| 749 | |
| 750 | if (p < -3) |
| 751 | { |
no test coverage detected