.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/04_validation/plot_04_benchmark.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_04_validation_plot_04_benchmark.py: A factorial benchmark with simulated users ========================================== Claims about IEC algorithms should rest on many runs, several problems and an honest statistical comparison. :func:`~easyiec.validation.run_benchmark` runs every combination of problems, strategies, simulated users and seeds and returns curves and a summary table; the Friedman test with the Nemenyi critical difference (Demšar, 2006) compares the strategies over the problem–seed blocks, and Vargha and Delaney's A12 effect size quantifies pairwise differences. .. GENERATED FROM PYTHON SOURCE LINES 14-16 Six strategies, three landscapes, eight seeds --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 16-38 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import SyntheticPreference from easyiec.strategies import EasyIEC, InteractiveCMAES, InteractiveDE, InteractiveGA, InteractivePSO, RandomSearch from easyiec.validation import compare_groups, friedman, nemenyi_cd, run_benchmark bench = run_benchmark( problems={k: (lambda k=k: SyntheticPreference(dim=6, kind=k, seed=5)) for k in ["sphere", "ellipsoid", "multimodal"]}, strategies={"GA": lambda: InteractiveGA(pop_size=9), "EASY-IEC": lambda: EasyIEC(pop_size=9), "CMA-ES": lambda: InteractiveCMAES(pop_size=9), "IPSO": lambda: InteractivePSO(pop_size=9), "DE": lambda: InteractiveDE(pop_size=8), "random": lambda: RandomSearch(pop_size=9)}, users={"user": lambda p, s: ei.SimulatedUser(p, target="random", noise=0.05, seed=s)}, seeds=range(8), max_items=135, generations=None) M = bench.summary.pivot_table(index=["problem", "seed"], columns="strategy", values="best_true") fr = friedman(M.to_numpy()) cd = nemenyi_cd(M.shape[1], M.shape[0]) print(f"Friedman p = {fr['p_value']:.2g}, Nemenyi CD = {cd:.2f}") table = bench.summary.assign(block=bench.summary["problem"] + "/" + bench.summary["seed"].astype(str)) print(compare_groups(table, "best_true", "strategy", block="block", reference="random").round(3).to_string()) ei.viz.plot_critical_difference(fr["avg_ranks"], list(M.columns), cd, title="average ranks over 24 problem–seed blocks (135 images each)") .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_04_benchmark_001.png :alt: average ranks over 24 problem–seed blocks (135 images each) :srcset: /auto_examples/04_validation/images/sphx_glr_plot_04_benchmark_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Friedman p = 8.9e-16, Nemenyi CD = 1.54 strategy mean ci_lo ci_hi A12_vs_ref p_vs_ref p_holm 0 GA 0.925 0.892 0.954 0.955 0.000 0.000 1 EASY-IEC 0.937 0.915 0.956 0.984 0.000 0.000 2 CMA-ES 0.930 0.914 0.944 0.991 0.000 0.000 3 IPSO 0.809 0.774 0.846 0.816 0.000 0.001 4 DE 0.685 0.624 0.745 0.575 0.491 0.491 5 random 0.654 0.601 0.706 0.500 NaN NaN .. GENERATED FROM PYTHON SOURCE LINES 39-41 Curves per landscape -------------------- .. GENERATED FROM PYTHON SOURCE LINES 41-47 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(13, 3.4), sharey=True) for ax, (prob, df) in zip(axes, bench.curves.groupby("problem")): ei.viz.plot_convergence(df, by="strategy", ax=ax, title=prob) if ax is not axes[0]: ax.get_legend().remove() plt.show() .. image-sg:: /auto_examples/04_validation/images/sphx_glr_plot_04_benchmark_002.png :alt: ellipsoid, multimodal, sphere :srcset: /auto_examples/04_validation/images/sphx_glr_plot_04_benchmark_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.896 seconds) .. _sphx_glr_download_auto_examples_04_validation_plot_04_benchmark.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/04_validation/plot_04_benchmark.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_04_benchmark.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_04_benchmark.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_04_benchmark.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_