-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOptimizationTask.py
More file actions
66 lines (55 loc) · 1.81 KB
/
OptimizationTask.py
File metadata and controls
66 lines (55 loc) · 1.81 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
55
56
57
58
59
60
61
62
63
64
65
66
import numpy as np
from sklearn.naive_bayes import GaussianNB
class OptimizationTask:
objective_func = None
objective_func_prev = None
clf = GaussianNB()
coef_1 = 0
coef_2 = 0
# X = n.array['v': 10, 'p': 20]
#grad = np.array[0, 0]
def __init__(self, c1, c2):
self.coef_1 = c1
self.coef_2 = c2
def objective (self, x):
print "objective calculation X"
self.objective_func = self.coef_1*(1 - x[0])**2 + self.coef_2*(x[1] - x[0]**2)**2
print self.objective_func, x[0], x[1]
if self.objective_func_prev == None:
self.objective_func_prev = self.objective_func
if self.objective_func < self.objective_func_prev:
print "new func better!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
self.objective_func_prev = self.objective_func
else:
print "new func worse!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
return self.objective_func
def constrants (self,x):
print "calculation constrains values"
def criteria (self, x):
helper = np.array([0.0, 0.0, 0.0, 0.0])
cr = np.zeros_like(helper)
cr[0] = (1 - x[0]**2)
cr[1] = (x[1] - x[0]**2)
cr[2] = (x[0])
cr[3] = (x[1])
return cr
def criteria_1(self, x):
helper = np.array([0.0, 0.0, 0.0])
cr = np.zeros_like(helper)
cr[0] = x[0]
cr[1] = x[1]
cr[2] = self.coef_1*(1 - x[0])**2 + self.coef_2*(x[1] - x[0]**2)**2
return cr
def criteria_2(self, x):
helper = np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
cr = np.zeros_like(helper)
cr[0] = (1 - x[0]**2)
cr[1] = (x[1] - x[0]**2)
cr[2] = (x[0])
cr[3] = (x[1])
cr[4] = self.coef_1*(1 - x[0])**2 + self.coef_2*(x[1] - x[0]**2)**2
cr[5] = self.coef_1*(1 - x[0])**2 + self.coef_2*(x[1] - x[0]**2)**2
return cr
def gradient (self,x, strategy):
print "calculation OPTask gradient"
#return strategy.gradient(self.cells, x)