Note
Go to the end to download the full example code or to run this example in your browser via Binder.
A factorial benchmark with simulated users#
Claims about IEC algorithms should rest on many runs, several problems and an
honest statistical comparison. 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.
Six strategies, three landscapes, eight seeds#
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)")

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
<Axes: title={'center': 'average ranks over 24 problem–seed blocks (135 images each)'}>
Curves per landscape#
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()

Total running time of the script: (0 minutes 1.896 seconds)