.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/05_engineering/plot_03_beer_fermentation.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_05_engineering_plot_03_beer_fermentation.py: Designing a beer fermentation temperature profile ================================================= The temperature profile of a lager fermentation trades batch time against flavour: warm fermentation is fast but produces diacetyl and esters, cold fermentation is clean but slow (de Andrés-Toro et al., 1998). The model of the Simulink library used in the EASY-IEC paper describes sugar, ethanol, biomass, diacetyl and ethyl acetate. The profile is a piecewise-linear curve through six knots between 9 and 16 °C; the evaluator sees the profile and the predicted concentrations and can *drag the knots* directly (the Lamarckian edit protocol of EASY-IEC). .. GENERATED FROM PYTHON SOURCE LINES 16-18 Presets and their outcomes -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 18-30 .. code-block:: Python import matplotlib.pyplot as plt import easyiec as ei from easyiec.problems import BeerFermentation from easyiec.strategies import InteractiveGA problem = BeerFermentation() for name, x in problem.presets().items(): o = problem.objectives(x) print(f"{name:18s} ethanol {o['ethanol']:.1f} g/L, batch time {o['batch_time']:.0f} h, " f"diacetyl {o['diacetyl']:.2f} ppm, ethyl acetate {o['ethyl_acetate']:.2f} ppm") .. rst-class:: sphx-glr-script-out .. code-block:: none isothermal 13 °C ethanol 55.9 g/L, batch time 98 h, diacetyl 0.35 ppm, ethyl acetate 0.57 ppm warm start ethanol 58.0 g/L, batch time 75 h, diacetyl 0.62 ppm, ethyl acetate 1.51 ppm free rise ethanol 53.5 g/L, batch time 180 h, diacetyl 0.07 ppm, ethyl acetate 0.25 ppm industrial-like ethanol 55.8 g/L, batch time 97 h, diacetyl 0.35 ppm, ethyl acetate 0.57 ppm .. GENERATED FROM PYTHON SOURCE LINES 31-36 Selections plus direct manipulation ----------------------------------- The simulated brewer occasionally drags a knot of the chosen profile towards its own ideal (``edit_prob``); edited profiles enter the population as new individuals (origin ``"edit"``). .. GENERATED FROM PYTHON SOURCE LINES 36-42 .. code-block:: Python user = ei.SimulatedUser(problem, target="industrial-like", noise=0.04, edit_prob=0.3, edit_step=0.4, seed=5) result = ei.run(problem, InteractiveGA(pop_size=8), user, generations=12, seed=5) edits = [i for i in result.log.individuals.values() if i.origin == "edit"] print(len(edits), "edited profiles;", problem.describe(result.best.genome)) ei.viz.plot_history(result.log, problem, steps=[0, 5, 11], max_items=8, size=1.3) .. image-sg:: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_001.png :alt: plot 03 beer fermentation :srcset: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none 3 edited profiles; Temperature knots every 30 h: [13.4, 12.8, 12.6, 11.6, 11.3, 11.8] °C. Batch time 90 h, final ethanol 54.4 g/L, diacetyl 0.46 (limit 0.5), ethyl acetate 0.47 (band 0.5–1.5), profile variation 2.4 °C.
.. GENERATED FROM PYTHON SOURCE LINES 43-45 The best profile ---------------- .. GENERATED FROM PYTHON SOURCE LINES 45-48 .. code-block:: Python fig, ax = plt.subplots(figsize=(6, 5)) problem.render(result.best.genome, ax=ax) .. image-sg:: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_002.png :alt: plot 03 beer fermentation :srcset: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 49-51 The genealogy shows where the edits entered ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 51-53 .. code-block:: Python ei.viz.plot_genealogy(result.log) plt.show() .. image-sg:: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_003.png :alt: plot 03 beer fermentation :srcset: /auto_examples/05_engineering/images/sphx_glr_plot_03_beer_fermentation_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 4.485 seconds) .. _sphx_glr_download_auto_examples_05_engineering_plot_03_beer_fermentation.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/05_engineering/plot_03_beer_fermentation.ipynb :alt: Launch binder :width: 150 px .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_03_beer_fermentation.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_03_beer_fermentation.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_03_beer_fermentation.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_