-
Notifications
You must be signed in to change notification settings - Fork 0
/
grid_search.py
49 lines (37 loc) · 1.73 KB
/
grid_search.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
from experiment import Experiment
def grid_search(exp_params, num_steps):
"""Perform optimization with various parameter values."""
funcs = ['sphere', 'ackley', 'levy', 'michalewicz', 'rastrigin', 'rosenbrock', 'schwefel']
dists = ['normal', 'uniform', 'logistic', 't']
sigmas = [1e+2, 3e+1, 1e+1, 3e+0, 1e+0, 3e-1, 1e-1, 3e-2,
1e-2, 3e-3, 1e-3, 3e-4, 1e-4, 3e-5, 1e-5, 3e-6, 1e-6]
lrs = [1e+1, 3e+0, 1e+0, 3e-1, 1e-1, 3e-2, 1e-2, 3e-3,
1e-3, 3e-4, 1e-4, 3e-5, 1e-5, 3e-6, 1e-6]
# run search for all distributions and parameters
for func in funcs:
exp_params['function_name'] = func
for dist in dists:
# modify experiment parameters for the current function and distribution
exp_params['exp_name'] = f'{func}_{dist}'
exp_params['num_steps'] = num_steps[func]
distribution_parameters = []
# form parameter list
for i, sigma in enumerate(sigmas):
for j, lr in enumerate(lrs):
distribution_parameters.append(
{f'{dist}_{i:02d}{j:02d}': {'sigma': sigma, 'lr': lr}})
# run experiment with these parameters
exp = Experiment(exp_params)
exp.run(distribution_parameters)
if __name__ == '__main__':
# experiment parameters
exp_params = {'dim': 100, 'num_mc': 100, 'num_tests': 25, 'random_seed': 0}
# number of iterations for each function
num_steps = {'sphere': 100,
'ackley': 10000,
'levy': 3000,
'michalewicz': 10000,
'rastrigin': 100,
'rosenbrock': 200,
'schwefel': 100}
grid_search(exp_params, num_steps)