Skip to content

Commit 2301475

Browse files
committed
added distortion
1 parent 8fd02e4 commit 2301475

File tree

3 files changed

+35
-16
lines changed

3 files changed

+35
-16
lines changed

bore/plugins/hpbandster.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import tensorflow as tf
33

44
from tensorflow.keras.losses import BinaryCrossentropy
5+
import scipy.stats as sps
56

67
from ..engine import Ledger, minimize_multi_start, is_duplicate
78
from ..types import DenseConfigurationSpace, DenseConfiguration
@@ -19,7 +20,7 @@ def __init__(self, config_space, eta=3, min_budget=0.01, max_budget=1,
1920
num_restarts=10, batch_size=64, num_steps_per_iter=1000,
2021
optimizer="adam", num_layers=2, num_units=32,
2122
activation="relu", normalize=True, method="L-BFGS-B",
22-
max_iter=100, ftol=1e-2, seed=None, **kwargs):
23+
max_iter=100, ftol=1e-2, distortion=1e-3, seed=None, **kwargs):
2324

2425
if gamma is None:
2526
gamma = 1/eta
@@ -31,7 +32,7 @@ def __init__(self, config_space, eta=3, min_budget=0.01, max_budget=1,
3132
optimizer=optimizer, num_layers=num_layers,
3233
num_units=num_units, activation=activation,
3334
normalize=normalize, method=method,
34-
max_iter=max_iter, ftol=ftol, seed=seed)
35+
max_iter=max_iter, ftol=ftol, distortion=distortion, seed=seed)
3536
# (LT): Note this is using the *grandparent* class initializer to
3637
# replace the config_generator!
3738
super(HyperBand, self).__init__(config_generator=cg, **kwargs)
@@ -70,8 +71,8 @@ def __init__(self, config_space, gamma=1/3, num_random_init=10,
7071
random_rate=0.25, num_restarts=3, batch_size=64,
7172
num_steps_per_iter=1000, optimizer="adam", num_layers=2,
7273
num_units=32, activation="relu", normalize=True,
73-
method="L-BFGS-B", max_iter=100, ftol=1e-2, seed=None,
74-
**kwargs):
74+
method="L-BFGS-B", max_iter=100, ftol=1e-2, distortion=1e-3,
75+
seed=None, **kwargs):
7576

7677
super(RatioEstimator, self).__init__(**kwargs)
7778

@@ -100,6 +101,7 @@ def __init__(self, config_space, gamma=1/3, num_random_init=10,
100101
self.method = method
101102
self.ftol = ftol
102103
self.max_iter = max_iter
104+
self.distortion = distortion
103105

104106
self.batch_size = batch_size
105107
self.num_steps_per_iter = num_steps_per_iter
@@ -230,7 +232,20 @@ def get_config(self, budget):
230232

231233
self.logger.info(f"[Glob. maximum: value={-opt.fun:.3f}, x={opt.x}")
232234

233-
config_opt_arr = opt.x
235+
loc = opt.x
236+
237+
if self.distortion is None:
238+
239+
config_opt_arr = loc
240+
else:
241+
242+
# dist = multivariate_normal(mean=opt.x, cov=opt.hess_inv.todense())
243+
a = (self.bounds.lb - loc) / self.distortion
244+
b = (self.bounds.ub - loc) / self.distortion
245+
dist = sps.truncnorm(a=a, b=b, loc=loc, scale=self.distortion)
246+
247+
config_opt_arr = dist.rvs(random_state=self.random_state)
248+
234249
config_opt_dict = self._dict_from_array(config_opt_arr)
235250

236251
return (config_opt_dict, {})

scripts/plotting/plot_result.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@click.option('--num-runs', '-n', default=20)
2121
@click.option('--methods', '-m', multiple=True)
2222
@click.option('--ci')
23+
@click.option('--duration-key', default="info")
2324
@click.option('--context', default="paper")
2425
@click.option('--style', default="ticks")
2526
@click.option('--palette', default="muted")
@@ -29,8 +30,8 @@
2930
@click.option("--output-dir", default=OUTPUT_DIR,
3031
type=click.Path(file_okay=False, dir_okay=True),
3132
help="Output directory.")
32-
def main(benchmark_name, input_dir, num_runs, methods, ci, context, style,
33-
palette, width, aspect, extension, output_dir):
33+
def main(benchmark_name, input_dir, num_runs, methods, ci, duration_key,
34+
context, style, palette, width, aspect, extension, output_dir):
3435

3536
figsize = size(width, aspect)
3637
height = width / aspect
@@ -53,8 +54,8 @@ def main(benchmark_name, input_dir, num_runs, methods, ci, context, style,
5354
"bore": "BORE",
5455
"bore-steps-50": "BORE (50 steps)",
5556
"bore-steps": "BORE (250 steps)",
56-
# "boredom": "BORE II",
57-
# "boredom-real": "BORE III",
57+
"boredom": "BOREDOM",
58+
"boredom-real": "BORE",
5859
"bore-sigmoid-elu-ftol-1e-2-gamma-0.33333333333333333333": "BORE",
5960
"boredom-real": "BORE",
6061
"bore-logit-elu-ftol-1e-2-gamma-0.33333333333333333333": "BORE",
@@ -74,7 +75,8 @@ def main(benchmark_name, input_dir, num_runs, methods, ci, context, style,
7475

7576
path = input_path.joinpath(benchmark_name, method, f"{run:03d}.csv")
7677

77-
frame = load_frame(path, run, loss_min=loss_min)
78+
frame = load_frame(path, run, loss_min=loss_min,
79+
duration_key=duration_key)
7880
frames.append(frame.assign(method=method))
7981

8082
series[run] = extract_series(frame, index="elapsed", column="regret")
@@ -124,9 +126,9 @@ def main(benchmark_name, input_dir, num_runs, methods, ci, context, style,
124126
data=data_merged, ax=ax)
125127

126128
ax.set_xlabel("wall-clock time elapsed (s)")
127-
ax.set_ylabel("evaluations")
129+
ax.set_ylabel("simple regret")
128130

129-
# ax.set_yscale("log")
131+
ax.set_yscale("log")
130132

131133
for ext in extension:
132134
fig.savefig(output_path.joinpath(f"regret_elapsed_{context}_{suffix}.{ext}"),

scripts/run_bore.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
@click.option("--activation", default="elu")
3939
@click.option('--normalize/--no-normalize', default=True)
4040
@click.option("--method", default="L-BFGS-B")
41-
@click.option("--max-iter", default=100)
42-
@click.option("--ftol", default=1e-3)
41+
@click.option("--max-iter", default=1000)
42+
@click.option("--ftol", default=1e-9)
43+
@click.option("--distortion", default=1e-3)
4344
@click.option("--input-dir", default="datasets/fcnet_tabular_benchmarks",
4445
type=click.Path(file_okay=False, dir_okay=True),
4546
help="Input data directory.")
@@ -50,7 +51,7 @@ def main(benchmark_name, dataset_name, dimensions, method_name, num_runs,
5051
num_iterations, eta, min_budget, max_budget, gamma, num_random_init,
5152
random_rate, num_restarts, batch_size, num_steps_per_iter, optimizer,
5253
num_layers, num_units, activation, normalize, method, max_iter, ftol,
53-
input_dir, output_dir):
54+
distortion, input_dir, output_dir):
5455

5556
Worker, worker_kws = get_worker(benchmark_name, dimensions=dimensions,
5657
dataset_name=dataset_name,
@@ -68,7 +69,7 @@ def main(benchmark_name, dataset_name, dimensions, method_name, num_runs,
6869
optimizer=optimizer, num_layers=num_layers,
6970
num_units=num_units, activation=activation,
7071
normalize=normalize, method=method, max_iter=max_iter,
71-
ftol=ftol)
72+
ftol=ftol, distortion=distortion)
7273
with open(output_path.joinpath("options.json"), 'w') as f:
7374
json.dump(options, f, sort_keys=True, indent=2)
7475

@@ -105,6 +106,7 @@ def main(benchmark_name, dataset_name, dimensions, method_name, num_runs,
105106
method=method,
106107
max_iter=max_iter,
107108
ftol=ftol,
109+
distortion=distortion,
108110
seed=run_id,
109111
nameserver=ns_host,
110112
nameserver_port=ns_port,

0 commit comments

Comments
 (0)