Commit 60a4af67 authored by Davis King's avatar Davis King

Added more unit tests

parent 2cff3f4e
from dlib import find_max_global, find_min_global
import dlib
from pytest import raises
from math import sin,cos,pi,exp,sqrt,pow
def test_global_optimization_nargs():
......@@ -23,9 +25,39 @@ def test_global_optimization_nargs():
find_min_global(lambda a, b, c, d, *args: 0, [0, 0, 0], [1, 1, 1], 10)
def F(a,b):
return -pow(a-2,2.0) - pow(b-4,2.0);
def G(x):
return 2-pow(x-5,2.0);
def test_global_function_search():
spec_F = dlib.function_spec([-10,-10], [10,10])
spec_G = dlib.function_spec([-2], [6])
opt = dlib.global_function_search([spec_F, spec_G])
for i in range(15):
next = opt.get_next_x()
#print("next x is for function {} and has coordinates {}".format(next.function_idx, next.x))
if (next.function_idx == 0):
a = next.x[0]
b = next.x[1]
next.set(F(a,b))
else:
x = next.x[0]
next.set(G(x))
[x,y,function_idx] = opt.get_best_function_eval()
#print("\nbest function was {}, with y of {}, and x of {}".format(function_idx,y,x))
assert(abs(y-2) < 1e-7)
assert(abs(x[0]-5) < 1e-7)
assert(function_idx==1)
from math import sin,cos,pi,exp,sqrt
def holder_table(x0,x1):
return -abs(sin(x0)*cos(x1)*exp(abs(1-sqrt(x0*x0+x1*x1)/pi)))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment