# # Test code for nmm.py (ver.1.1) # # 2020-09-15 # by Kenar # import numpy as np import nmm def f(x): return sum(x**2) h=0.1 s = 0 s=0.001 x3 = (1,h) x2 = (1,0.9*h) x1 = (1-s,-0.8*h) x0 = [x1,x2,x3] #x0 = (x1,x2,x3) # OK def test1(): of = f search = nmm.snmsearch err = 1e-5 dim = 2 x0 = (0,1) + np.random.uniform(-.5, .5, dim) print(x0) mp = search(of,x0,err); print(dim,err,of(mp),mp) test1() def test2(): of = f search = nmm.snmsearch err = 1e-6 dim = 2 print(x0) mp = search(of,x0,err); print(dim,err,of(mp),mp,s) #test2() def test3(): of = f search = nmm.anmsearch err = 1e-6 dim = 2 print(x0) mp = search(of,x0,err); print(dim,err,of(mp),mp,s) #test3() def test4(): x0 = [(-1,),(2,)] of = f search = nmm.anmsearch err = 1e-6 dim = 1 print(x0) mp = search(of,x0,err); print(dim,err,of(mp),mp) #test4()