.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/miscellaneous/evolutionary_game_theory.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 .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_miscellaneous_evolutionary_game_theory.py: ======================== Evolutionary game theory ======================== `replicator equation `__ .. warning:: The implementation of mathematics might be wrong due to my lack of knowledge. .. GENERATED FROM PYTHON SOURCE LINES 12-39 .. image-sg:: /gallery/miscellaneous/images/sphx_glr_evolutionary_game_theory_001.svg :alt: evolutionary game theory :srcset: /gallery/miscellaneous/images/sphx_glr_evolutionary_game_theory_001.svg :class: sphx-glr-single-img .. code-block:: Python import matplotlib.pyplot as plt import numpy as np from mpltern.datasets import get_triangular_grid x = np.array(get_triangular_grid(25)) payoff_matrix = [ [0.0, -1.0, 1.0], [1.0, 0.0, -1.0], [-1.0, 1.0, 0.0], ] fitness = payoff_matrix @ x d = (fitness - np.sum(fitness * x, axis=0)) * x norm = np.linalg.norm(d, axis=0) ax = plt.subplot(projection="ternary") ax.tripcolor(*x, norm, cmap="turbo", shading="gouraud", rasterized=True) ax.quiver(*x, *d, scale=5, clip_on=False) ax.set_tlabel("$x_0$") ax.set_llabel("$x_1$") ax.set_rlabel("$x_2$") plt.show() .. _sphx_glr_download_gallery_miscellaneous_evolutionary_game_theory.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: evolutionary_game_theory.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: evolutionary_game_theory.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_