Bayesian exploration from YAML¶
In [1]:
Copied!
from xopt import Xopt
# set values if testing
import os
import warnings
warnings.filterwarnings("ignore")
SMOKE_TEST = os.environ.get("SMOKE_TEST")
YAML = """
generator:
name: bayesian_exploration
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives:
y1: EXPLORE
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
"""
from xopt import Xopt
# set values if testing
import os
import warnings
warnings.filterwarnings("ignore")
SMOKE_TEST = os.environ.get("SMOKE_TEST")
YAML = """
generator:
name: bayesian_exploration
vocs:
variables:
x1: [0, 3.14159]
x2: [0, 3.14159]
objectives:
y1: EXPLORE
constraints:
c1: [GREATER_THAN, 0]
c2: [LESS_THAN, 0.5]
constants: {a: dummy_constant}
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
"""
In [2]:
Copied!
X = Xopt.from_yaml(YAML)
# for testing purposes only
if SMOKE_TEST:
X.generator.numerical_optimizer.n_restarts = 1
X.generator.n_monte_carlo_samples = 1
X
X = Xopt.from_yaml(YAML)
# for testing purposes only
if SMOKE_TEST:
X.generator.numerical_optimizer.n_restarts = 1
X.generator.n_monte_carlo_samples = 1
X
Out[2]:
Xopt
________________________________
Version: 0.1.dev1+gd4c488f75
Data size: 0
Config as YAML:
data_dump_file: null
evaluator:
function: xopt.resources.test_functions.tnk.evaluate_TNK
function_kwargs:
raise_probability: 0
random_sleep: 0
sleep: 0
max_workers: 1
vectorized: false
generator:
computation_time: null
custom_objective: null
fixed_features: null
gp_constructor:
covar_modules: {}
custom_noise_prior: null
mean_modules: {}
name: standard
train_config: null
train_kwargs: null
train_method: lbfgs
train_model: true
trainable_mean_keys: []
transform_inputs: true
use_cached_hyperparameters: false
use_low_noise_prior: false
max_travel_distances: null
model: null
n_candidates: 1
n_interpolate_points: null
n_monte_carlo_samples: 128
name: bayesian_exploration
numerical_optimizer:
discrete_max_batch_size: 2048
discrete_max_choices: 4096
max_iter: 1000
max_time: 5.0
mixed_max_discrete_configurations: 512
n_restarts: 20
name: LBFGS
returns_id: false
supports_batch_generation: true
supports_constraints: true
supports_contextual_variables: true
supports_discrete_variables: true
supports_multi_objective: true
supports_no_objective: true
supports_single_objective: true
turbo_controller: null
use_cuda: false
vocs:
constants:
a:
dtype: null
type: Constant
value: dummy_constant
constraints:
c1:
dtype: null
type: GreaterThanConstraint
value: 0.0
c2:
dtype: null
type: LessThanConstraint
value: 0.5
objectives:
y1:
dtype: null
type: ExploreObjective
observables: {}
variables:
x1:
default_value: null
domain:
- 0.0
- 3.14159
dtype: null
type: ContinuousVariable
x2:
default_value: null
domain:
- 0.0
- 3.14159
dtype: null
type: ContinuousVariable
serialize_inline: false
serialize_torch: false
stopping_condition: null
strict: true
xopt_dump_file: null
In [3]:
Copied!
X.random_evaluate(5)
for i in range(5):
print(f"step {i}")
X.step()
X.random_evaluate(5)
for i in range(5):
print(f"step {i}")
X.step()
step 0
step 1
step 2
step 3
step 4
In [4]:
Copied!
print(X.data)
print(X.data)
x1 x2 a y1 y2 c1 \
0 1.491314 2.980146 dummy_constant 1.491314 2.980146 10.063573
1 2.618642 1.540143 dummy_constant 2.618642 1.540143 8.290045
2 0.818589 1.948871 dummy_constant 0.818589 1.948871 3.368501
3 0.832503 0.543028 dummy_constant 0.832503 0.543028 0.086376
4 0.721562 1.901584 dummy_constant 0.721562 1.901584 3.047994
5 0.015710 1.250193 dummy_constant 0.015710 1.250193 0.465243
6 1.397211 0.312817 dummy_constant 1.397211 0.312817 1.142828
7 1.021698 0.451545 dummy_constant 1.021698 0.451545 0.154712
8 0.325497 1.134962 dummy_constant 0.325497 1.134962 0.418215
9 0.348956 1.051317 dummy_constant 0.348956 1.051317 0.186692
c2 xopt_runtime xopt_error
0 7.133827 0.008116 False
1 5.570540 0.000142 False
2 2.200727 0.000133 False
3 0.112410 0.000134 False
4 2.013526 0.000133 False
5 0.797326 0.004417 False
6 0.840025 0.000132 False
7 0.274516 0.006116 False
8 0.433628 0.011236 False
9 0.326765 0.000152 False
In [5]:
Copied!
# plot results
ax = X.data.plot("x1", "x2")
ax.set_aspect("equal")
# plot results
ax = X.data.plot("x1", "x2")
ax.set_aspect("equal")
In [6]:
Copied!
fig, ax = X.generator.visualize_model(show_feasibility=True, n_grid=100)
fig, ax = X.generator.visualize_model(show_feasibility=True, n_grid=100)