.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/06_visual/plot_06_music_and_text.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_06_visual_plot_06_music_and_text.py: Beyond images: melodies and slogans =================================== The evaluator of a melody listens; the evaluator of a slogan reads. :class:`~easyiec.problems.Melody` evolves 16-step melodies in a chosen scale (GenJam of Biles, 1994, evolved jazz solos interactively); a gallery shows them as piano rolls and :meth:`~easyiec.problems.Melody.wav_bytes` renders them as sound for a notebook player. :class:`~easyiec.problems.TextDesign` evolves slogans from templates or, with a language model connected, lets the model propose variations of the chosen ones — an LLM acting as the *variation operator* while the person (or another model) judges. .. GENERATED FROM PYTHON SOURCE LINES 17-19 Melodies -------- .. GENERATED FROM PYTHON SOURCE LINES 19-32 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import Melody, TextDesign from easyiec.strategies import InteractiveGA problem = Melody() user = ei.SimulatedUser(problem, target="random", noise=0.03, seed=3) res = ei.run(problem, InteractiveGA(pop_size=6), user, generations=10, seed=3) ei.viz.plot_history(res.log, problem, steps=[0, 9], max_items=6, size=1.3) audio = problem.wav_bytes(res.best.genome) # IPython.display.Audio(audio) plays it in a notebook print(f"{len(audio)} bytes of WAV;", problem.describe(res.best.genome)) .. image-sg:: /auto_examples/06_visual/images/sphx_glr_plot_06_music_and_text_001.png :alt: plot 06 music and text :srcset: /auto_examples/06_visual/images/sphx_glr_plot_06_music_and_text_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 236304 bytes of WAV; D# dorian, 93 bpm, 16 steps; notes with lengths in steps: D#5(1) C#5(1) A#4(1) F#5(1) F#4(1) F5(1) F#5(1) C#6(1) G#4(1) C#6(1) A#4(1) F4(1) G#5(1) F5(2) .. GENERATED FROM PYTHON SOURCE LINES 33-37 Slogans from templates ---------------------- Without a language model the variation operator recombines template phrases; the simulated reader prefers short, positive slogans that use the keywords. .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: Python text = TextDesign(topic="the open day of a university of technology", keywords=("future", "together", "discover")) reader = ei.SimulatedUser(text, target="default", noise=0.03, seed=1) res_t = ei.run(text, InteractiveGA(pop_size=6), reader, generations=8, seed=1) for r in (res_t.log.records[0], res_t.log.records[-1]): print([text.describe(it.genome) for it in r.query.items][:3]) ax = ei.viz.plot_anytime(res_t, label="slogans") ax.set_title("slogan design with a simulated reader", fontsize=9) plt.show() .. image-sg:: /auto_examples/06_visual/images/sphx_glr_plot_06_music_and_text_002.png :alt: slogan design with a simulated reader :srcset: /auto_examples/06_visual/images/sphx_glr_plot_06_music_and_text_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ['Knowledge. discovery. Pannonia.', 'Shape the careers for real', 'Where engineering meets Veszprém'] ['Discover the minds today', 'Discover minds minds for together', 'Discover the minds boldly'] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.650 seconds) .. _sphx_glr_download_auto_examples_06_visual_plot_06_music_and_text.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/06_visual/plot_06_music_and_text.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_06_music_and_text.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_06_music_and_text.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_06_music_and_text.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_