-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathnormalization.py
69 lines (50 loc) · 2.06 KB
/
normalization.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
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
67
68
69
import numpy as np
def update_ideal_point(costs,z_min, j):
new_ideal = np.min(costs[:, j])
z_min[j] = min(new_ideal, z_min[j])
# Normalize objective functions of St (Structured points)
def normalize(combined_evaluations, structured_points, num_objs, target_functions, z_min, z_max):
evaluations = combined_evaluations[structured_points]
#print('Structured points costs: ', evaluations)
for M in np.arange(num_objs):
update_ideal_point(evaluations,z_min, M)
perform_scalarizing(evaluations, z_max, M)
translated_objectives = evaluations - z_min
a = find_hyperplane_intercepts(evaluations, z_max)
#print('Ideal point: ', z_min)
#print('Extreme points: ', z_max)
#print('Translated objetives: ', translated_objectives)
#print('Intercepts: ', a)
normalized_evaluations = np.zeros((len(structured_points), num_objs))
#before speed up
'''
for i in np.arange(len(structured_points)):
normalized_evaluations[i] = translated_objectives[i] / a
'''
normalized_evaluations = translated_objectives / a
#print('Normalized costs: ', normalized_evaluations)
return normalized_evaluations
def perform_scalarizing(evaluations, z_max, j):
ind = find_extreme_point_objective(evaluations, j)
if evaluations[ind][j] > z_max[j][j]:
z_max[j] = evaluations[ind]
def find_extreme_point_objective(evaluations, j):
#Finds the invidivuals with extreme values for each objective function.
return np.argmax(evaluations[:, j])
def find_hyperplane_intercepts(evaluations, z_max):
num_objs = evaluations.shape[1]
intercepts = np.zeros(num_objs)
#check if duplicated individuals
if np.all(evaluations == np.unique(evaluations, axis=0)):
for j in range(num_objs):
intercepts[j] = z_max[j][j]
else:
b = np.ones(num_objs)
try:
x = np.linalg.solve(z_max,b)
except np.linalg.LinAlgError:
for j in range(num_objs):
intercepts[j] = z_max[j][j]
else:
intercepts = 1/x
return intercepts