Upper Confidence Bound BO¶
In [1]:
Copied!
from xopt import Xopt
# Ignore all warnings
import warnings
warnings.filterwarnings("ignore")
from xopt import Xopt
# Ignore all warnings
import warnings
warnings.filterwarnings("ignore")
The Xopt object can be instantiated from a JSON or YAML file, or a dict, with the proper structure.
Here we will make one
In [2]:
Copied!
# Make a proper input file.
YAML = """
generator:
name: upper_confidence_bound
beta: 0.1
vocs:
variables:
x1: [0, 6.28]
objectives:
y1: 'MINIMIZE'
evaluator:
function: xopt.resources.test_functions.sinusoid_1d.evaluate_sinusoid
"""
# Make a proper input file.
YAML = """
generator:
name: upper_confidence_bound
beta: 0.1
vocs:
variables:
x1: [0, 6.28]
objectives:
y1: 'MINIMIZE'
evaluator:
function: xopt.resources.test_functions.sinusoid_1d.evaluate_sinusoid
"""
In [3]:
Copied!
X = Xopt.from_yaml(YAML)
X
X = Xopt.from_yaml(YAML)
X
Out[3]:
Xopt
________________________________
Version: 0.1.dev1+g6d6c7f050
Data size: 0
Config as YAML:
dump_file: null
evaluator:
function: xopt.resources.test_functions.sinusoid_1d.evaluate_sinusoid
function_kwargs: {}
max_workers: 1
vectorized: false
generator:
beta: 0.1
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: upper_confidence_bound
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
shift: 0.0
supports_batch_generation: true
supports_constraints: true
supports_discrete_variables: true
supports_single_objective: true
turbo_controller: null
use_cuda: false
vocs:
constants: {}
constraints: {}
objectives:
y1:
dtype: null
type: MinimizeObjective
observables: {}
variables:
x1:
default_value: null
domain:
- 0.0
- 6.28
dtype: null
type: ContinuousVariable
serialize_inline: false
serialize_torch: false
stopping_condition: null
strict: true
Run Optimization¶
In [4]:
Copied!
X.random_evaluate(3)
for i in range(5):
print(i)
X.step()
X.random_evaluate(3)
for i in range(5):
print(i)
X.step()
0
1
2
3
4
View output data¶
In [5]:
Copied!
X.data
X.data
Out[5]:
| x1 | y1 | c1 | xopt_runtime | xopt_error | |
|---|---|---|---|---|---|
| 0 | 5.539629 | -0.676910 | -15.387945 | 0.000020 | False |
| 1 | 3.174953 | -0.033354 | -10.064945 | 0.000004 | False |
| 2 | 1.712268 | 0.990010 | -0.148343 | 0.000003 | False |
| 3 | 5.305276 | -0.829331 | -18.326337 | 0.000009 | False |
| 4 | 4.769933 | -0.998345 | -18.563484 | 0.000010 | False |
| 5 | 4.702937 | -0.999955 | -18.501741 | 0.000009 | False |
| 6 | 4.706586 | -0.999983 | -18.500657 | 0.000010 | False |
| 7 | 4.708326 | -0.999992 | -18.500322 | 0.000009 | False |
Visualize model¶
In [6]:
Copied!
fig, ax = X.generator.visualize_model(n_grid=100)
fig, ax = X.generator.visualize_model(n_grid=100)