| 193 | // ---------------------------------------------------------------------------------------- |
| 194 | |
| 195 | void test_global_function_search() |
| 196 | { |
| 197 | |
| 198 | function_spec spec{{-10,-10}, {10,10}}; |
| 199 | function_spec spec2{{-10,-10, -50}, {10,10, 50}}; |
| 200 | global_function_search opt({spec, spec, spec2}); |
| 201 | |
| 202 | dlib::rand rnd; |
| 203 | bool found_optimal_point = false; |
| 204 | for (int i = 0; i < 400 && !found_optimal_point; ++i) |
| 205 | { |
| 206 | print_spinner(); |
| 207 | std::vector<function_evaluation_request> nexts; |
| 208 | for (int k = 0; k < rnd.get_integer_in_range(1,4); ++k) |
| 209 | nexts.emplace_back(opt.get_next_x()); |
| 210 | |
| 211 | for (auto& next : nexts) |
| 212 | { |
| 213 | switch (next.function_idx()) |
| 214 | { |
| 215 | case 0: next.set( -complex_holder_table(next.x()(0), next.x()(1))); break; |
| 216 | case 1: next.set( -10*complex_holder_table(next.x()(0), next.x()(1))); break; |
| 217 | case 2: next.set( -2*complex_holder_table(next.x()(0), next.x()(1))); break; |
| 218 | default: DLIB_TEST(false); break; |
| 219 | } |
| 220 | |
| 221 | matrix<double,0,1> x; |
| 222 | double y; |
| 223 | size_t function_idx; |
| 224 | opt.get_best_function_eval(x,y,function_idx); |
| 225 | /* |
| 226 | cout << "\ni: "<< i << endl; |
| 227 | cout << "best eval x: "<< trans(x); |
| 228 | cout << "best eval y: "<< y << endl; |
| 229 | cout << "best eval function index: "<< function_idx << endl; |
| 230 | */ |
| 231 | |
| 232 | if (std::abs(y - 10*21.9210397) < 0.0001) |
| 233 | { |
| 234 | found_optimal_point = true; |
| 235 | break; |
| 236 | } |
| 237 | } |
| 238 | } |
| 239 | |
| 240 | DLIB_TEST(found_optimal_point); |
| 241 | } |
| 242 | |
| 243 | // ---------------------------------------------------------------------------------------- |
| 244 |
no test coverage detected