-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.py
More file actions
54 lines (39 loc) · 1.79 KB
/
test.py
File metadata and controls
54 lines (39 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import numpy as np
import pyDONEc
#test function to minimize
def paraboloid(x):
centers=np.linspace(-10.0,10.0,degrees_of_freedom)
parab= np.sum((x-centers)**2)
noise=np.random.normal(0.0,1.0)
return parab+noise
#hyperparameters, see readme
degrees_of_freedom=10
initial_guess=np.ones(degrees_of_freedom)*0.3
lower_bounds=np.ones(degrees_of_freedom)*(-20.0)
upper_bounds=np.ones(degrees_of_freedom)*(20.0)
cosine_number=1000
regularization_factor=1.0
cosine_sigma=0.05
expl_factors=np.ones(degrees_of_freedom)*0.5
memory_size=100
#initial guess
min_pos=np.linspace(-10.0,10.0,degrees_of_freedom)
#use with direct function call
opt=pyDONEc.optimizer(initial_guess,degrees_of_freedom,lower_bounds,upper_bounds,cosine_number,regularization_factor,cosine_sigma,expl_factors,memory_size)
for i in range(200):
opt.step(paraboloid)
print "iteration: "+str(i)+" rms error= "+str(np.sqrt(np.mean((opt.getmin()-min_pos)**2/degrees_of_freedom)))
print "minimum location: "+str(min_pos)
print "estimated minimum: "+str(opt.getmin())
print "final rms error: "+str(np.sqrt(np.mean((opt.getmin()-min_pos)**2/degrees_of_freedom)))
#use with separate metric measurement
opt=pyDONEc.optimizer(initial_guess,degrees_of_freedom,lower_bounds,upper_bounds,cosine_number,regularization_factor,cosine_sigma,expl_factors,memory_size)
a=np.ones(degrees_of_freedom)*0.3
for i in range(200):
met=paraboloid(a)
opt.nullstep(a,met)
a=opt.getlaststep()[0]
print "iteration: "+str(i)+" rms error= "+str(np.sqrt(np.mean((opt.getmin()-min_pos)**2/degrees_of_freedom)))
print "minimum location: "+str(min_pos)
print "estimated minimum: "+str(opt.getmin())
print "final rms error: "+str(np.sqrt(np.mean((opt.getmin()-min_pos)**2/degrees_of_freedom)))