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+g3385ef356
Data size: 0
Config as YAML:
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:
max_iter: 2000
max_time: 5.0
n_restarts: 20
name: LBFGS
returns_id: false
supports_batch_generation: true
supports_constraints: true
supports_multi_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
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 c2 \ 0 1.472321 0.074442 dummy_constant 1.472321 0.074442 1.104196 1.126507 1 0.304019 3.068013 dummy_constant 0.304019 3.068013 8.506083 6.633097 2 1.731476 0.676010 dummy_constant 1.731476 0.676010 2.360317 1.547513 3 1.856030 0.643523 dummy_constant 1.856030 0.643523 2.800247 1.859416 4 2.241388 1.641485 dummy_constant 2.241388 1.641485 6.795483 4.335421 5 0.000000 0.000000 dummy_constant 0.000000 0.000000 -1.100000 0.500000 6 3.141590 0.000000 dummy_constant 3.141590 0.000000 8.769588 7.227998 7 0.728417 0.860487 dummy_constant 0.728417 0.860487 0.246879 0.182126 8 1.081259 0.798299 dummy_constant 1.081259 0.798299 0.879515 0.426844 9 0.499710 0.965958 dummy_constant 0.499710 0.965958 0.161406 0.217117 xopt_runtime xopt_error 0 0.002917 False 1 0.000146 False 2 0.000130 False 3 0.000122 False 4 0.000125 False 5 0.006124 False 6 0.005397 False 7 0.001317 False 8 0.000224 False 9 0.000140 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)