{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Animations with PyALAF\n", "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. " ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "from PyALAF.models import inv_sphere\n", "import matplotlib.pyplot as plt\n", "\n", "random_state = 420\n", "\n", "model_sphere = inv_sphere(d=1, random_state=random_state)\n", "grid = np.linspace(-5,5,100).reshape(-1,1)\n", "\n", "y = model_sphere.evaluate(grid)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Disabled warnings\n", "Disabled warnings\n" ] }, { "name": "stderr", "output_type": "stream", "text": [ "2026-01-30 14:43:08,810 - matplotlib.animation - INFO - Animation.save using \n" ] } ], "source": [ "from PyALAF.animation import create_animation_continuous\n", "\n", "from sklearn.gaussian_process import GaussianProcessRegressor as GPR\n", "from sklearn.gaussian_process.kernels import RBF\n", "\n", "kernel = RBF()\n", "gpr = GPR(kernel)\n", "\n", "#Bayesian Optimization\n", "acquisition_function = 'ideal'\n", "\n", "anim = create_animation_continuous(\n", " model=model_sphere,\n", " gpr=gpr,\n", " acquisition_function=acquisition_function,\n", " grid_simple=grid,\n", " n_iterations=20,\n", " opt_method='PSO',\n", " n_observations=3,\n", " noise_level=0,\n", " alpha=1,\n", " random_state=42,\n", " legend=True,\n", " plot_std=True\n", ")" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "\n", "\n", "\n", "\n", "
\n", " \n", "
\n", " \n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "anim" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.0" } }, "nbformat": 4, "nbformat_minor": 2 }