.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/01_basics/plot_01_first_session.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_01_basics_plot_01_first_session.py: A first interactive session: evolving a Julia set ================================================= An interactive evolutionary algorithm shows a gallery of candidates, the evaluator picks the ones they like, and the algorithm breeds the next gallery from the picks. Here the evaluator is a *simulated user* who secretly prefers one particular Julia set; because its taste is known, we can measure how close each gallery came to it — the ground truth that a real person cannot give us. .. GENERATED FROM PYTHON SOURCE LINES 13-18 Problem, strategy and evaluator ------------------------------- A :class:`~easyiec.problems.JuliaSet` has ten genes: the complex constant in polar form, zoom, centre, four colour genes and the interior shade. The interactive GA shows nine images per generation and asks for the ones worth keeping (the *select* protocol). .. GENERATED FROM PYTHON SOURCE LINES 18-28 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import JuliaSet from easyiec.strategies import InteractiveGA problem = JuliaSet() user = ei.SimulatedUser(problem, target="random", noise=0.05, seed=3) result = ei.run(problem, InteractiveGA(pop_size=9), user, generations=12, seed=3) print(result) print(problem.describe(result.best.genome)) .. rst-class:: sphx-glr-script-out .. code-block:: none Result(problem=julia, strategy=InteractiveGA, evaluator=simulated-user, queries=12, items=108, human=0, usd=0.0, best_true=0.9190716458712059, stopped=max_generations, seed=3) Parameters: - radius = 0.7411 (range 0.62 .. 0.82) - angle = 2.828 (range 0 .. 6.283) - zoom = 1.293 (range 0.7 .. 2.5) - center_x = 0.5901 (range -0.6 .. 0.6) - center_y = 0.4171 (range -0.6 .. 0.6) - hue = 0.9559 (range 0 .. 1) - hue_cycles = 0.5047 (range 0.3 .. 3) - saturation = 0.9906 (range 0.3 .. 1) - gamma = 1.362 (range 0.3 .. 1.6) - interior = 0.5469 (range 0 .. 1) .. GENERATED FROM PYTHON SOURCE LINES 29-33 What the evaluator saw ---------------------- The film strip shows four galleries; the chosen images carry a frame. The population drifts towards the hidden target within a few generations. .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: Python ei.viz.plot_history(result.log, problem, steps=[0, 3, 7, 11], max_items=9, size=0.9) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_001.png :alt: plot 01 first session :srcset: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 36-39 The hidden target and the best image found ------------------------------------------ The simulated user's target is an ordinary genome, so it can be drawn. .. GENERATED FROM PYTHON SOURCE LINES 39-45 .. code-block:: Python fig, axes = plt.subplots(1, 2, figsize=(5.2, 2.7)) problem.render(user.target, ax=axes[0]) axes[0].set_title("hidden target", fontsize=9) problem.render(result.best.genome, ax=axes[1]) axes[1].set_title(f"best found (utility {problem.utility(result.best.genome, user.target):.2f})", fontsize=9) .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_002.png :alt: hidden target, best found (utility 0.83) :srcset: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(0.5, 1.0, 'best found (utility 0.83)') .. GENERATED FROM PYTHON SOURCE LINES 46-50 The anytime curve ----------------- The true utility of the best individual is plotted against the number of images shown — the classical measure of evaluator effort in IEC. .. GENERATED FROM PYTHON SOURCE LINES 50-53 .. code-block:: Python ax = ei.viz.plot_anytime(result, label="interactive GA") ax.set_title("best true utility vs. images shown") plt.show() .. image-sg:: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_003.png :alt: best true utility vs. images shown :srcset: /auto_examples/01_basics/images/sphx_glr_plot_01_first_session_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.756 seconds) .. _sphx_glr_download_auto_examples_01_basics_plot_01_first_session.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/01_basics/plot_01_first_session.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_01_first_session.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_01_first_session.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_01_first_session.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_