.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/03_evaluators/plot_01_simulated_users.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_03_evaluators_plot_01_simulated_users.py: Simulated users: benchmarking with a known ground truth ======================================================= A person cannot tell us how far a gallery is from what they "really" want, so IEC algorithms have been compared with simulated users since the early days (Takagi, 2001; Breukelaar et al., 2006). The :class:`~easyiec.SimulatedUser` holds a hidden target and answers every protocol through a Thurstonian (or Bradley–Terry–Luce) choice model, with optional fatigue, lapses, position bias, limited attention, drift of taste and satisficing. .. GENERATED FROM PYTHON SOURCE LINES 14-19 The choice model ---------------- Probability that the user prefers A to B as a function of the true utility difference, estimated from 400 random pairs per noise level. Thurstone's law of comparative judgment gives :math:`\Phi(\Delta u / \sqrt{2}\sigma)`. .. GENERATED FROM PYTHON SOURCE LINES 19-50 .. 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 InteractiveGA from easyiec.validation import make_individuals, run_benchmark problem = SyntheticPreference(dim=4, kind="sphere", seed=0) rng = np.random.default_rng(1) fig, ax = plt.subplots(figsize=(6.4, 3.6)) for k, noise in enumerate([0.02, 0.05, 0.1, 0.2]): user = ei.SimulatedUser(problem, target="random", noise=noise, seed=2) d, win = [], [] for _ in range(400): a, b = make_individuals(problem.random(rng, 2)) fb = user.evaluate(ei.Query("pairs", [a, b])) d.append(user.true_utility(a.genome) - user.true_utility(b.genome)) win.append(fb.pair_results[0][2]) d, win = np.array(d), np.array(win) edges = np.linspace(-0.6, 0.6, 13) mid = (edges[1:] + edges[:-1]) / 2 p = [win[(d >= lo) & (d < hi)].mean() if ((d >= lo) & (d < hi)).sum() > 5 else np.nan for lo, hi in zip(edges[:-1], edges[1:])] ax.plot(mid, p, "o-", ms=4, lw=1.5, label=f"σ = {noise}", color=ei.viz._style.color_for(k)) ax.axhline(0.5, color="0.8", lw=0.8) ax.set_xlabel("true utility difference u(A) − u(B)", fontsize=8) ax.set_ylabel("P(A preferred)", fontsize=8) ax.legend(frameon=False, fontsize=8) ax.set_title("Thurstonian choice probabilities of the simulated user", fontsize=9) .. image-sg:: /auto_examples/03_evaluators/images/sphx_glr_plot_01_simulated_users_001.png :alt: Thurstonian choice probabilities of the simulated user :srcset: /auto_examples/03_evaluators/images/sphx_glr_plot_01_simulated_users_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'Thurstonian choice probabilities of the simulated user') .. GENERATED FROM PYTHON SOURCE LINES 51-56 The same algorithm under six user models ---------------------------------------- Fatigue increases the noise with the number of items seen; lapses replace answers by random ones; position bias favours the first images; limited attention means only the first few images are really looked at. .. GENERATED FROM PYTHON SOURCE LINES 56-72 .. code-block:: Python users = { "careful": dict(noise=0.03), "noisy": dict(noise=0.15), "tiring": dict(noise=0.03, fatigue=1.0, fatigue_scale=60), "lapsing 20 %": dict(noise=0.03, lapse=0.2), "position-biased": dict(noise=0.03, position_bias=0.15), "inattentive (4)": dict(noise=0.03, attention=4), } bench = run_benchmark( problems={"sphere-5": lambda: SyntheticPreference(dim=5, kind="sphere", seed=1)}, strategies={"GA": lambda: InteractiveGA(pop_size=9)}, users={n: (lambda p, s, kw=kw: ei.SimulatedUser(p, target="random", seed=s, **kw)) for n, kw in users.items()}, seeds=range(10), generations=20) print(bench.summary.groupby("evaluator")["best_true"].agg(["mean", "std"]).round(3)) ei.viz.plot_convergence(bench.curves, by="user", title="interactive GA, six simulated users, 10 seeds") plt.show() .. image-sg:: /auto_examples/03_evaluators/images/sphx_glr_plot_01_simulated_users_002.png :alt: interactive GA, six simulated users, 10 seeds :srcset: /auto_examples/03_evaluators/images/sphx_glr_plot_01_simulated_users_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none mean std evaluator careful 0.988 0.008 inattentive (4) 0.985 0.005 lapsing 20 % 0.964 0.021 noisy 0.866 0.270 position-biased 0.902 0.230 tiring 0.986 0.010 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.298 seconds) .. _sphx_glr_download_auto_examples_03_evaluators_plot_01_simulated_users.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/03_evaluators/plot_01_simulated_users.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_simulated_users.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_simulated_users.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_simulated_users.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_