Animations with PyALAF
It is very simple to create animations for 1D models (with only one feature and one objective) in PyALAF. This is demonstrated below for a very simple function. The animations can be helpful for illustrating how different acquisition functions select data.
[1]:
import numpy as np
from PyALAF.models import inv_sphere
import matplotlib.pyplot as plt
random_state = 420
model_sphere = inv_sphere(d=1, random_state=random_state)
grid = np.linspace(-5,5,100).reshape(-1,1)
y = model_sphere.evaluate(grid)
[2]:
from PyALAF.animation import create_animation_continuous
from sklearn.gaussian_process import GaussianProcessRegressor as GPR
from sklearn.gaussian_process.kernels import RBF
kernel = RBF()
gpr = GPR(kernel)
#Bayesian Optimization
acquisition_function = 'ideal'
anim = create_animation_continuous(
model=model_sphere,
gpr=gpr,
acquisition_function=acquisition_function,
grid_simple=grid,
n_iterations=20,
opt_method='PSO',
n_observations=3,
noise_level=0,
alpha=1,
random_state=42,
legend=True,
plot_std=True
)
Disabled warnings
Disabled warnings
2026-01-30 14:43:08,810 - matplotlib.animation - INFO - Animation.save using <class 'matplotlib.animation.HTMLWriter'>
[3]:
anim
[3]:
[ ]: