()
| 31 | return 2-pow(x-5,2.0); |
| 32 | |
| 33 | def test_global_function_search(): |
| 34 | spec_F = dlib.function_spec([-10,-10], [10,10]) |
| 35 | spec_G = dlib.function_spec([-2], [6]) |
| 36 | |
| 37 | opt = dlib.global_function_search([spec_F, spec_G]) |
| 38 | |
| 39 | for i in range(15): |
| 40 | next = opt.get_next_x() |
| 41 | #print("next x is for function {} and has coordinates {}".format(next.function_idx, next.x)) |
| 42 | |
| 43 | if (next.function_idx == 0): |
| 44 | a = next.x[0] |
| 45 | b = next.x[1] |
| 46 | next.set(F(a,b)) |
| 47 | else: |
| 48 | x = next.x[0] |
| 49 | next.set(G(x)) |
| 50 | |
| 51 | [x,y,function_idx] = opt.get_best_function_eval() |
| 52 | |
| 53 | #print("\nbest function was {}, with y of {}, and x of {}".format(function_idx,y,x)) |
| 54 | |
| 55 | assert(abs(y-2) < 1e-7) |
| 56 | assert(abs(x[0]-5) < 1e-7) |
| 57 | assert(function_idx==1) |
| 58 | |
| 59 | |
| 60 |
nothing calls this directly
no test coverage detected