Upper Confidence Bound BO¶
In [1]:
Copied!
# Ignore all warnings
import warnings
warnings.filterwarnings("ignore")
import torch
import matplotlib.pyplot as plt
from xopt import Xopt
# Ignore all warnings
import warnings
warnings.filterwarnings("ignore")
import torch
import matplotlib.pyplot as plt
from xopt import Xopt
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
evaluator:
function: xopt.resources.test_functions.sinusoid_1d.evaluate_sinusoid
vocs:
variables:
x1: [0, 6.28]
objectives:
y1: 'MINIMIZE'
"""
# Make a proper input file.
YAML = """
generator:
name: upper_confidence_bound
beta: 0.1
evaluator:
function: xopt.resources.test_functions.sinusoid_1d.evaluate_sinusoid
vocs:
variables:
x1: [0, 6.28]
objectives:
y1: 'MINIMIZE'
"""
In [3]:
Copied!
X = Xopt.from_yaml(YAML)
X
X = Xopt.from_yaml(YAML)
X
Out[3]:
Xopt ________________________________ Version: 0+untagged.1511.gf1c313f.dirty 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 fixed_features: null gp_constructor: covar_modules: {} custom_noise_prior: null mean_modules: {} name: standard trainable_mean_keys: [] transform_inputs: true use_low_noise_prior: true log_transform_acquisition_function: 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: max_iter: 2000 max_time: null n_restarts: 20 name: LBFGS supports_batch_generation: true turbo_controller: null use_cuda: false max_evaluations: null serialize_inline: false serialize_torch: false strict: true vocs: constants: {} constraints: {} objectives: y1: MINIMIZE observables: [] variables: x1: - 0.0 - 6.28
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 | 4.545877 | -0.986169 | -18.967475 | 0.000007 | False |
1 | 3.915465 | -0.698910 | -15.727310 | 0.000003 | False |
2 | 0.284073 | 0.280267 | -5.783307 | 0.000002 | False |
3 | 6.083269 | -0.198587 | -12.471220 | 0.000006 | False |
4 | 4.721365 | -0.999960 | -18.501570 | 0.000006 | False |
5 | 4.699943 | -0.999923 | -18.503018 | 0.000007 | False |
6 | 4.697728 | -0.999893 | -18.504187 | 0.000005 | False |
7 | 4.696545 | -0.999874 | -18.504889 | 0.000004 | False |
Visualize model¶
In [6]:
Copied!
fig, ax = X.generator.visualize_model(n_grid=100)
fig, ax = X.generator.visualize_model(n_grid=100)
In [ ]:
Copied!