-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathinit.py
78 lines (69 loc) · 2.61 KB
/
init.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
70
71
72
73
74
75
76
77
78
#encoding: utf-8
import random
import numpy as np
from public import pareto,NDsort,glo
NUM_ELE = glo.NUM_ELE
def init_designparams(particals,in_min,in_max):
if glo.type == 'ti':
in_dim = len(in_max)
solution = np.zeros((1, 6))
solution[0, 0] = 0.5 + glo.prior[4]/NUM_ELE
solution[0, 1] = 0.5 - glo.prior[4]/NUM_ELE
solution[0, 2] = glo.prior[0] / (NUM_ELE-1)
solution[0, 3] = glo.prior[1] / (NUM_ELE-1)
solution[0, 4] = glo.prior[2] / (NUM_ELE-1)
solution[0, 5] = glo.prior[3] / (NUM_ELE-1)
print(solution)
solution=np.repeat(solution, 5, axis=0)
in_temp = np.random.uniform(-5, 5, (particals-5, in_dim))
in_temp[-1 > in_temp] = 0
in_temp[in_temp > 1] = 0
in_temp = np.vstack([in_temp,solution])
print(in_temp)
if glo.type == 'mti':
in_dim = len(in_max) #输入参数维度
print(in_dim)
print(glo.prior)
solution = np.zeros(150)
solution[glo.prior[0]] = 1
solution[glo.prior[1]] = 1
solution[glo.prior[2]] = -1
solution[glo.prior[3]] = -1
solution[glo.prior[0]+NUM_ELE] = 1
solution[glo.prior[1]+NUM_ELE] = 1
solution[glo.prior[2]+NUM_ELE] = -1
solution[glo.prior[3]+NUM_ELE] = -1
print(solution)
solution=np.repeat([solution], 5, axis=0)
in_temp = np.random.uniform(-9, 9, (particals-5, in_dim))
in_temp[-1 > in_temp] = 0
in_temp[in_temp > 1] = 0
in_temp = np.vstack([in_temp,solution])
print(in_temp)
if glo.type == 'tdcs':
in_dim = len(in_max) #输入参数维度
print(in_dim)
print(glo.prior)
solution = np.zeros(NUM_ELE)
solution[glo.prior[0]] = 1
solution[glo.prior[1]] = 1
solution[glo.prior[2]] = -1
solution[glo.prior[3]] = -1
print(solution)
solution=np.repeat([solution],5, axis=0)
in_temp = np.random.uniform(-5, 5, (particals-5, in_dim))
in_temp[-1 > in_temp] = 0
in_temp[in_temp > 1] = 0
in_temp = np.vstack([in_temp,solution])
print(in_temp)
return in_temp
def init_v(particals,v_max,v_min):
v_dim = len(v_max)
v_ = np.random.uniform(0,1,(particals,v_dim))*(v_max-v_min)+v_min
return v_
def init_pbest(in_,fitness_):
return in_,fitness_
def init_archive(in_,fitness_):
pareto_c = pareto.Pareto_(in_,fitness_)
curr_archiving_in,curr_archiving_fit = pareto_c.pareto()
return curr_archiving_in,curr_archiving_fit