.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_algorithms/plot_03_bayesian.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code or to run this example in your browser via Binder. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_02_algorithms_plot_03_bayesian.py: Preferential Bayesian optimization, line search and gallery =========================================================== When every answer is expensive, a statistical model of the evaluator's preferences pays off. A Gaussian process is fitted to pairwise answers with the probit likelihood of Chu and Ghahramani (2005); the next comparison is chosen by an acquisition function (González et al., 2017). Sequential line search (Koyama et al., 2017) asks for the best point on a slider through the incumbent, and the sequential gallery (Koyama et al., 2020) for the best cell of a 2-D grid — far more information per question than a single pair. .. GENERATED FROM PYTHON SOURCE LINES 15-17 Three model-based strategies on a two-dimensional landscape ----------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 17-31 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np import easyiec as ei from easyiec.problems import SyntheticPreference from easyiec.strategies import PreferentialBO, SequentialGallery, SequentialLineSearch problem = SyntheticPreference(dim=2, kind="ellipsoid", seed=4) runs = {} for name, strategy in {"PBO (pairs)": PreferentialBO(), "line search (slider)": SequentialLineSearch(n_samples=7), "gallery (3×3 grid)": SequentialGallery(grid=3)}.items(): user = ei.SimulatedUser(problem, target="random", noise=0.03, seed=8) runs[name] = (strategy, user, ei.run(problem, strategy, user, generations=15, seed=8)) print(f"{name:22s} best utility {runs[name][2].best_true:.3f} after {runs[name][2].summary()['queries']} questions") .. rst-class:: sphx-glr-script-out .. code-block:: none PBO (pairs) best utility 0.900 after 15 questions line search (slider) best utility 0.710 after 15 questions gallery (3×3 grid) best utility 0.990 after 15 questions .. GENERATED FROM PYTHON SOURCE LINES 32-37 Learned utility versus the hidden one ------------------------------------- Top left: the hidden utility of the simulated user. The other panels show the GP posterior mean of each strategy with the shown points (white) and the chosen ones (circles). .. GENERATED FROM PYTHON SOURCE LINES 37-51 .. code-block:: Python fig, axes = plt.subplots(2, 2, figsize=(9.4, 8)) g = np.linspace(0, 1, 70) A, B = np.meshgrid(g, g) user = runs["PBO (pairs)"][1] U = np.array([problem.utility(problem.space.denormalize(np.array([a, b])), user.target) for a, b in zip(A.ravel(), B.ravel())]).reshape(A.shape) cs = axes[0, 0].contourf(A, B, U, levels=20, cmap="viridis") plt.colorbar(cs, ax=axes[0, 0], shrink=0.85, label="hidden utility") axes[0, 0].set_title("hidden utility of the simulated user", fontsize=9) for ax, (name, (strategy, _, res)) in zip(axes.flat[1:], runs.items()): ei.viz.plot_preference_landscape(strategy.model, problem, log=res.log, ax=ax) ax.set_title(name, fontsize=9) fig.tight_layout() .. image-sg:: /auto_examples/02_algorithms/images/sphx_glr_plot_03_bayesian_001.png :alt: hidden utility of the simulated user, PBO (pairs), line search (slider), gallery (3×3 grid) :srcset: /auto_examples/02_algorithms/images/sphx_glr_plot_03_bayesian_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 52-55 Utility per question -------------------- A line or gallery answer carries several pairwise preferences at once. .. GENERATED FROM PYTHON SOURCE LINES 55-62 .. code-block:: Python fig, ax = plt.subplots(figsize=(6.4, 3.4)) for k, (name, (_, _, res)) in enumerate(runs.items()): ei.viz.plot_anytime(res, ax=ax, x="n_queries", label=name, color=["#285780", "#D55E00", "#009E73"][k], show_shown=False) ax.legend(frameon=False, fontsize=8) ax.set_title("best utility vs. number of questions", fontsize=9) plt.show() .. image-sg:: /auto_examples/02_algorithms/images/sphx_glr_plot_03_bayesian_002.png :alt: best utility vs. number of questions :srcset: /auto_examples/02_algorithms/images/sphx_glr_plot_03_bayesian_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.792 seconds) .. _sphx_glr_download_auto_examples_02_algorithms_plot_03_bayesian.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: binder-badge .. image:: images/binder_badge_logo.svg :target: https://mybinder.org/v2/gh/ComplexSystemsIntelligence/easyiec/main?urlpath=lab/tree/notebooks/auto_examples/02_algorithms/plot_03_bayesian.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_bayesian.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_bayesian.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_bayesian.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_