-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample6.py
30 lines (24 loc) · 834 Bytes
/
example6.py
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
# minimize new problem with algometer algorithm
from algormeter import *
# define my problem parameters dependent
class MyProb (Kernel):
def __inizialize__(self, dimension):
self.XStart = np.ones(dimension)*K # K param
def _f1(self, x):
return np.sum(np.array(x,dtype=float)**2)
def _gf1(self, x):
return 2.*x
def _f2(self,x) :
return H # H param
def _gf2(self, x):
return np.zeros(self.dimension)
# ...define my algorithm
def myAlgo(p, **kwargs):
for k in p.loop():
p.Xkp1 = p.Xk - 1/(k+1) * p.gfXk / np.linalg.norm(p.gfXk)
# ...apply my algorithm to my problem
for H in [3,5]:
for K in [1,2,4]:
p = MyProb(2)
result, x, y = p.minimize(myAlgo, iterations=300)
print(f'With K:{K}, H:{H} result:{result}, y is {y} at {x}')