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

Function test_global_function_search

tools/python/test/test_global_optimization.py:33–57  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31 return 2-pow(x-5,2.0);
32
33def 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

Callers

nothing calls this directly

Calls 7

absFunction · 0.85
function_specMethod · 0.80
FFunction · 0.70
GFunction · 0.70
rangeFunction · 0.50
setMethod · 0.45

Tested by

no test coverage detected