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+gb834d2348
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 0.372702 1.603577 dummy_constant 0.372702 1.603577 1.797529 1.234086 1 2.687890 0.321705 dummy_constant 2.687890 0.321705 6.361136 4.818652 2 2.680850 1.659769 dummy_constant 2.680850 1.659769 9.026778 6.101170 3 0.824223 1.549378 dummy_constant 0.824223 1.549378 2.076752 1.206315 4 1.148696 0.620725 dummy_constant 1.148696 0.620725 0.712075 0.435382 5 0.499558 0.049395 dummy_constant 0.499558 0.049395 -0.747389 0.203045 6 0.830241 0.797661 dummy_constant 0.830241 0.797661 0.230645 0.197661 7 1.181657 0.218973 dummy_constant 1.181657 0.218973 0.542067 0.543632 8 0.122538 0.990489 dummy_constant 0.122538 0.990489 0.034900 0.383056 9 0.845814 0.683646 dummy_constant 0.845814 0.683646 0.194682 0.153314 xopt_runtime xopt_error 0 0.005960 False 1 0.000156 False 2 0.000149 False 3 0.000138 False 4 0.000147 False 5 0.007296 False 6 0.015073 False 7 0.003142 False 8 0.005872 False 9 0.005673 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)