-
Notifications
You must be signed in to change notification settings - Fork 9
/
demo_simtime.py
90 lines (71 loc) · 3.05 KB
/
demo_simtime.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
"""
A simple demo for parallelised BO via Thompson sampling on synthetic functions and
simulated time units.
The time for each evaluation is sampled from the specified random distribution.
"""
# pylint: disable=relative-import
# Local imports
from bo.blackbox_optimiser import random_optimiser_from_func_caller
from bo.gp_bandit import gpb_from_func_caller
from bo.worker_manager import SyntheticWorkerManager
from utils.syn_functions import get_syn_function_caller_from_name
## Set the parameters in all caps ------------------------------------------------
NUM_WORKERS = 2
MAX_CAPITAL = 40
## Parameters for the Synthetic Experiment ---------------------------------------
# 1. Choose Synthetic Function
# EXP_NAME = 'Hartmann3'
# EXP_NAME = 'Hartmann6'
# EXP_NAME = 'CurrinExp'
EXP_NAME = 'Branin'
# EXP_NAME = 'Shekel'
# EXP_NAME = 'Hartmann12'
# EXP_NAME = 'Park1'
# EXP_NAME = 'Park2'
# EXP_NAME = 'Branin-4'
# EXP_NAME = 'CurrinExp-20'
# 2. Choose distribution for time
# TIME_DISTRO = 'uniform'
TIME_DISTRO = 'halfnormal'
# TIME_DISTRO = 'exponential'
# TIME_DISTRO = 'pareto';
## Other parameters that are not critical ----------------------------------------
NOISE_SCALE = 0.1 # standard deviation of gaussian noise
def main():
""" Main function. """
func_caller = get_syn_function_caller_from_name(EXP_NAME, noise_type='gauss',
noise_scale=NOISE_SCALE, time_distro=TIME_DISTRO)
worker_manager = SyntheticWorkerManager(func_caller, NUM_WORKERS)
# 1. random synchronous
worker_manager.reset()
syn_rand_opt_val, _, syn_rand_history = random_optimiser_from_func_caller(
func_caller, worker_manager, MAX_CAPITAL, 'syn')
syn_rand_true_opt_val = syn_rand_history.curr_true_opt_vals[-1]
# 2. random asynchronous
worker_manager.reset()
asy_rand_opt_val, _, asy_rand_history = random_optimiser_from_func_caller(
func_caller, worker_manager, MAX_CAPITAL, 'asy')
asy_rand_true_opt_val = asy_rand_history.curr_true_opt_vals[-1]
# 3. ts synchronous
worker_manager.reset()
syn_ts_opt_val, _, syn_ts_history = gpb_from_func_caller(
func_caller, worker_manager, MAX_CAPITAL, 'syn', 'TS')
syn_ts_true_opt_val = syn_ts_history.curr_true_opt_vals[-1]
# 4. ts asynchronous
worker_manager.reset()
asy_ts_opt_val, _, asy_ts_history = gpb_from_func_caller(
func_caller, worker_manager, MAX_CAPITAL, 'asy', 'TS')
asy_ts_true_opt_val = asy_ts_history.curr_true_opt_vals[-1]
# Print out results
print '\nExperiment: %s, true-max-value: %0.4f'%(EXP_NAME, func_caller.opt_val)
print 'Synchronous random: noisy-max-value: %0.4f, true-max-value: %0.4f'%(
syn_rand_opt_val, syn_rand_true_opt_val)
print 'Asynchronous random: noisy-max-value: %0.4f, true-max-value: %0.4f'%(
asy_rand_opt_val, asy_rand_true_opt_val)
print 'Synchronous ts: noisy-max-value: %0.4f, true-max-value: %0.4f'%(
syn_ts_opt_val, syn_ts_true_opt_val)
print 'Asynchronous ts: noisy-max-value: %0.4f, true-max-value: %0.4f'%(
asy_ts_opt_val, asy_ts_true_opt_val)
if __name__ == '__main__':
main()