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

Function test_upper_bound_function

dlib/test/global_optimization.cpp:28–84  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

26// ----------------------------------------------------------------------------------------
27
28 void test_upper_bound_function(double relative_noise_magnitude, double solver_eps)
29 {
30 print_spinner();
31
32 dlog << LINFO << "test_upper_bound_function, relative_noise_magnitude="<< relative_noise_magnitude << ", solver_eps=" << solver_eps;
33
34 auto rosen = [](const matrix<double,0,1>& x) { return -1*( 100*std::pow(x(1) - x(0)*x(0),2.0) + std::pow(1 - x(0),2)); };
35
36 dlib::rand rnd;
37 auto make_rnd = [&rnd]() { matrix<double,0,1> x(2); x = 2*rnd.get_random_double(), 2*rnd.get_random_double(); return x; };
38
39
40 std::vector<function_evaluation> evals;
41 for (int i = 0; i < 100; ++i)
42 {
43 auto x = make_rnd();
44 evals.emplace_back(x,rosen(x));
45 }
46
47 upper_bound_function ub(evals, relative_noise_magnitude, solver_eps);
48 DLIB_TEST(ub.num_points() == (long)evals.size());
49 DLIB_TEST(ub.dimensionality() == 2);
50 for (auto& ev : evals)
51 {
52 dlog << LINFO << ub(ev.x) - ev.y;
53 DLIB_TEST_MSG(ub(ev.x) - ev.y > -1e10, ub(ev.x) - ev.y);
54 }
55
56
57 for (int i = 0; i < 100; ++i)
58 {
59 auto x = make_rnd();
60 evals.emplace_back(x,rosen(x));
61 ub.add(evals.back());
62 }
63
64 DLIB_TEST(ub.num_points() == (long)evals.size());
65 DLIB_TEST(ub.dimensionality() == 2);
66
67 for (auto& ev : evals)
68 {
69 dlog << LINFO << ub(ev.x) - ev.y;
70 DLIB_TEST_MSG(ub(ev.x) - ev.y > -1e10, ub(ev.x) - ev.y);
71 }
72
73
74 if (solver_eps < 0.001)
75 {
76 dlog << LINFO << "out of sample points: ";
77 for (int i = 0; i < 10; ++i)
78 {
79 auto x = make_rnd();
80 dlog << LINFO << ub(x) - rosen(x);
81 DLIB_TEST_MSG(ub(x) - rosen(x) > 1e-10, ub(x) - rosen(x));
82 }
83 }
84 }
85

Callers 1

perform_testMethod · 0.85

Calls 9

print_spinnerFunction · 0.85
xFunction · 0.85
get_random_doubleMethod · 0.80
num_pointsMethod · 0.80
rosenFunction · 0.70
sizeMethod · 0.45
dimensionalityMethod · 0.45
addMethod · 0.45
backMethod · 0.45

Tested by

no test coverage detected