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

Method perform_test

dlib/test/isotonic_regression.cpp:36–97  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34 {}
35
36 void perform_test (
37 )
38 {
39 dlib::rand rnd;
40
41 for (int round = 0; round < 100; ++round)
42 {
43 print_spinner();
44 std::vector<double> vect;
45 for (int i = 0; i < 5; ++i)
46 vect.push_back(put_in_range(-1,1,rnd.get_random_gaussian()));
47
48
49 auto f = [&](const matrix<double,0,1>& x)
50 {
51 double dist = 0;
52 double sum = 0;
53 for (long i = 0; i < x.size(); ++i)
54 {
55 sum += x(i);
56 dist += (sum-vect[i])*(sum-vect[i]);
57 }
58 return dist;
59 };
60
61 auto objval = [vect](const matrix<double,0,1>& x)
62 {
63 return sum(squared(mat(vect)-x));
64 };
65
66 auto is_monotonic = [](const matrix<double,0,1>& x)
67 {
68 for (long i = 1; i < x.size(); ++i)
69 {
70 if (x(i-1) > x(i))
71 return false;
72 }
73 return true;
74 };
75
76 matrix<double,0,1> lower(5), upper(5);
77 lower = 0;
78 lower(0) = -4;
79 upper = 4;
80 // find the solution with find_min_global() and then check that it matches
81 auto result = find_min_global(f, lower, upper, max_function_calls(40));
82
83 for (long i = 1; i < result.x.size(); ++i)
84 result.x(i) += result.x(i-1);
85
86 isotonic_regression mr;
87 mr(vect);
88
89 dlog << LINFO << "err: "<< objval(mat(vect)) - objval(result.x);
90
91 DLIB_CASSERT(is_monotonic(mat(vect)));
92 DLIB_CASSERT(is_monotonic(result.x));
93 // isotonic_regression should be at least as good as find_min_global().

Callers

nothing calls this directly

Calls 11

print_spinnerFunction · 0.85
put_in_rangeFunction · 0.85
xFunction · 0.85
squaredFunction · 0.85
find_min_globalFunction · 0.85
get_random_gaussianMethod · 0.80
sumFunction · 0.50
matFunction · 0.50
max_function_callsClass · 0.50
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected