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

Function test_global_function_search

dlib/test/global_optimization.cpp:107–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

105// ----------------------------------------------------------------------------------------
106
107 void test_global_function_search()
108 {
109
110 function_spec spec{{-10,-10}, {10,10}};
111 function_spec spec2{{-10,-10, -50}, {10,10, 50}};
112 global_function_search opt({spec, spec, spec2});
113
114 dlib::rand rnd;
115 bool found_optimal_point = false;
116 for (int i = 0; i < 400 && !found_optimal_point; ++i)
117 {
118 print_spinner();
119 std::vector<function_evaluation_request> nexts;
120 for (int k = 0; k < rnd.get_integer_in_range(1,4); ++k)
121 nexts.emplace_back(opt.get_next_x());
122
123 for (auto& next : nexts)
124 {
125 switch (next.function_idx())
126 {
127 case 0: next.set( -complex_holder_table(next.x()(0), next.x()(1))); break;
128 case 1: next.set( -10*complex_holder_table(next.x()(0), next.x()(1))); break;
129 case 2: next.set( -2*complex_holder_table(next.x()(0), next.x()(1))); break;
130 default: DLIB_TEST(false); break;
131 }
132
133 matrix<double,0,1> x;
134 double y;
135 size_t function_idx;
136 opt.get_best_function_eval(x,y,function_idx);
137 /*
138 cout << "\ni: "<< i << endl;
139 cout << "best eval x: "<< trans(x);
140 cout << "best eval y: "<< y << endl;
141 cout << "best eval function index: "<< function_idx << endl;
142 */
143
144 if (std::abs(y - 10*21.9210397) < 0.0001)
145 {
146 found_optimal_point = true;
147 break;
148 }
149 }
150 }
151
152 DLIB_TEST(found_optimal_point);
153 }
154
155// ----------------------------------------------------------------------------------------
156

Callers 1

perform_testMethod · 0.70

Calls 5

print_spinnerFunction · 0.85
complex_holder_tableFunction · 0.85
absFunction · 0.85
get_integer_in_rangeMethod · 0.80
setMethod · 0.45

Tested by

no test coverage detected