-
Notifications
You must be signed in to change notification settings - Fork 8
/
config.py
166 lines (125 loc) · 3.21 KB
/
config.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
class Cfg:
pass
class CfgSensors:
batch_size = 100
epochs = 500
loss = 'mean_squared_error'
task_type = 'approximation'
pop_size = 10
ngen = 30
MAX_LAYERS = 5
MAX_LAYER_SIZE = 100
MIN_LAYER_SIZE = 5
DROPOUT = [ 0.0, 0.2, 0.3, 0.4 ]
ACTIVATIONS = [ 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear' ]
class CfgSensorsES:
batch_size = 100
epochs = 500
loss = 'mean_squared_error'
task_type = 'approximation'
MU = 10
LAMBDA = 30
ngen = 100
MAX_LAYERS = 5
MAX_LAYER_SIZE = 100
MIN_LAYER_SIZE = 5
DROPOUT = [ 0.0, 0.2, 0.3, 0.4 ]
ACTIVATIONS = [ 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear' ]
SIZE_MIN_STRATEGY = 5
SIZE_MAX_STRATEGY = 50
DROPOUT_MIN_STRATEGY = 0.05
DROPOUT_MAX_STRATEGY = 0.2
class CfgMnist:
batch_size = 128
epochs = 10
loss = 'categorical_crossentropy'
#loss = 'mean_squared_error'
task_type = "classification"
pop_size = 20
ngen = 300
MAX_LAYERS = 5
MAX_LAYER_SIZE = 300
MIN_LAYER_SIZE = 10
DROPOUT = [ 0.0, 0.2, 0.3, 0.4 ]
ACTIVATIONS = [ 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear' ]
# for convolutional networks
MIN_FILTERS = 10
MAX_FILTERS = 50
MIN_KERNEL_SIZE = 2
MAX_KERNEL_SIZE = 5
MIN_POOL_SIZE = 2
MAX_POOL_SIZE = 3
MAX_CONV_LAYERS = 3
MAX_DENSE_LAYERS = 3
#DENSE_LAYER = 0.5
CONV_LAYER = 0.7
MAX_POOL_LAYER = 0.3
class CfgMnistES:
batch_size = 128
epochs = 20
#loss = 'categorical_crossentropy'
loss = 'mean_squared_error'
task_type = "classification"
MU = 5
LAMBDA = 10
ngen = 10
SIZE_MIN_STRATEGY = 5
SIZE_MAX_STRATEGY = 50
DROPOUT_MIN_STRATEGY = 0.05
DROPOUT_MAX_STRATEGY = 0.2
MAX_LAYERS = 5
MAX_LAYER_SIZE = 1000
MIN_LAYER_SIZE = 10
DROPOUT = [ 0.0, 0.2, 0.3, 0.4 ]
ACTIVATIONS = [ 'relu', 'tanh', 'sigmoid', 'hard_sigmoid', 'linear' ]
#Config = CfgSensors()
Config = CfgMnist()
#Config = CfgSensorsES()
#Config = CfgMnist()
import configparser
import re
def is_int(s):
if re.fullmatch(r'[0-9]+', s):
return True
else:
return False
def is_float(s):
if re.fullmatch(r'[0-9]+\.[0-9]+', s):
return True
else:
return False
def is_list(s):
if re.fullmatch(r'\[.+\]', s):
return True
else:
return False
def convert(s):
if is_int(s):
val = int(s)
elif is_float(s):
val = float(s)
elif is_list(s):
s = s.strip()
s = s.strip("[")
s = s.strip("]")
val = s.split(',')
newval = []
for v in val:
v = v.strip()
v = v.strip("'")
v = v.strip('"')
newval.append(convert(v))
val = newval
else:
val = s
return val
def load_config(name):
config = configparser.ConfigParser()
config.read(name)
global Config
Config = Cfg()
for sec in config.sections():
for key, val in config[sec].items():
val = convert(val)
setattr(Config, key.lower(), val)
setattr(Config, key.upper(), val)