.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/02_algorithms/plot_02_cmaes_pso_de.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_02_cmaes_pso_de.py: CMA-ES, interactive PSO and pairwise differential evolution =========================================================== Three continuous optimizers adapted to judged fitness. The interactive CMA-ES needs only the *order* of the candidates, so a ranking or a selection suffices (Hansen, 2016). The interactive PSO of Madár, Abonyi and Szeifert (2005) moves the swarm towards the candidates the user picks as personal and global bests. Differential evolution asks a single question per trial vector — *is the offspring better than its parent?* — which makes it a natural pairwise method. .. GENERATED FROM PYTHON SOURCE LINES 14-16 Convergence on a rotated multimodal landscape --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-31 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import SyntheticPreference from easyiec.strategies import InteractiveCMAES, InteractiveDE, InteractivePSO, RandomSearch from easyiec.validation import run_benchmark bench = run_benchmark( problems={"multimodal-5": lambda: SyntheticPreference(dim=5, kind="multimodal", seed=1)}, strategies={"CMA-ES (rank)": lambda: InteractiveCMAES(pop_size=8, protocol="rank"), "IPSO (select 1)": lambda: InteractivePSO(pop_size=8), "DE (pairs)": lambda: InteractiveDE(pop_size=8), "random": lambda: RandomSearch(pop_size=8)}, users={"user": lambda p, s: ei.SimulatedUser(p, target="random", noise=0.05, seed=s)}, seeds=range(10), max_items=200, generations=None) print(bench.summary.groupby("strategy")[["best_true", "items", "queries"]].mean().round(3)) .. rst-class:: sphx-glr-script-out .. code-block:: none best_true items queries strategy CMA-ES (rank) 0.973 200.0 25.0 DE (pairs) 0.865 208.0 13.0 IPSO (select 1) 0.869 200.0 25.0 random 0.692 200.0 25.0 .. GENERATED FROM PYTHON SOURCE LINES 32-37 Items shown versus elementary decisions --------------------------------------- Counting shown items favours methods that show many candidates at once; counting elementary decisions (one per pair, one per item looked at in a gallery) gives a fairer picture of the evaluator's effort. .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: Python from easyiec.validation import curve_frame # noqa: E402 labels = [r.strategy for r in bench.results] fig, axes = plt.subplots(1, 2, figsize=(10, 3.6)) ei.viz.plot_convergence(curve_frame(bench.results, "n_items", labels), ax=axes[0], title="vs. items shown") ei.viz.plot_convergence(curve_frame(bench.results, "n_decisions", labels), x="n_decisions", ax=axes[1], title="vs. elementary decisions") .. image-sg:: /auto_examples/02_algorithms/images/sphx_glr_plot_02_cmaes_pso_de_001.png :alt: vs. items shown, vs. elementary decisions :srcset: /auto_examples/02_algorithms/images/sphx_glr_plot_02_cmaes_pso_de_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 46-50 Inside the strategies --------------------- After 20 generations the CMA-ES covariance has elongated along the valley of the landscape, and the swarm of the PSO has gathered around the global best. .. GENERATED FROM PYTHON SOURCE LINES 50-58 .. code-block:: Python problem = SyntheticPreference(dim=5, kind="ellipsoid", seed=1) cma, pso = InteractiveCMAES(pop_size=8), InteractivePSO(pop_size=8) for s in (cma, pso): ei.run(problem, s, ei.SimulatedUser(problem, target="random", noise=0.05, seed=3), generations=20, seed=3) fig, axes = plt.subplots(1, 2, figsize=(9, 3.4)) ei.viz.plot_strategy_state(cma, ax=axes[0]) ei.viz.plot_strategy_state(pso, ax=axes[1]) plt.show() .. image-sg:: /auto_examples/02_algorithms/images/sphx_glr_plot_02_cmaes_pso_de_002.png :alt: InteractiveCMAES: axis lengths σ·√λ_i (σ=0.064), InteractivePSO: swarm (first two genes) :srcset: /auto_examples/02_algorithms/images/sphx_glr_plot_02_cmaes_pso_de_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.895 seconds) .. _sphx_glr_download_auto_examples_02_algorithms_plot_02_cmaes_pso_de.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_02_cmaes_pso_de.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_02_cmaes_pso_de.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_02_cmaes_pso_de.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_02_cmaes_pso_de.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_