egttools.plotting.indicators.draw_invasion_diagram

draw_invasion_diagram(strategies, drift, fixation_probabilities, stationary_distribution, atol=0.0001, max_displayed_label_letters=4, min_strategy_frequency=-1, node_size=4000, font_size_node_labels=18, font_size_edge_labels=14, font_size_sd_labels=12, display_node_labels=True, display_edge_labels=True, display_sd_labels=True, node_labels_top_separation=0.15, node_labels_bottom_separation=-0.2, edge_width=2, node_linewidth=0, node_edgecolors=None, figsize=(10, 10), dpi=150, colors=None, ax=None)[source]

Draws the markov chain for a given stationary distribution of monomorphic states.

Parameters
  • strategies (List[str]) – Strategies and array of string labels for each strategy present in the population.

  • drift (float) – drift = 1/pop_size

  • fixation_probabilities (numpy.ndarray[float, 2]) – A matrix specifying the fixation probabilities.

  • stationary_distribution (numpy.ndarray[float, 1]) – An array containing the stationary distribution (probability of each state in the system).

  • atol (float) – The tolerance for considering a value equal to 1 (to detect wheter there is random drift). Default is 1e-4.

  • max_displayed_label_letters (int) – Maximum number of letters of the strategy labels contained in the strategies List to be displayed.

  • min_strategy_frequency (Optional[float]) – Minimum frequency of a strategy (its probability given by the stationary distribution) to be shown in the Graph.

  • font_size_node_labels (Optional[int]) – Font size of the labels displayed inside each node.

  • font_size_edge_labels (Optional[int]) – Font size of the labels displayed in each edge (which contain the fixation probabilities).

  • font_size_sd_labels (Optional[int]) – Font size of the labels displayed beside each node containing the value of the stationary distribution.

  • display_node_labels (Optional[bool]) – Indicates wether the node labels should be displayed.

  • display_edge_labels (Optional[bool]) – Indicates wether the edge labels should be displayed.

  • display_sd_labels (Optional[bool]) – Indicates whether the stationary distribution labels should be displayed.

  • node_labels_top_separation (Optional[float]) – Gives the separation of node label for nodes with positive y (y > 0)

  • node_labels_bottom_separation (Optional[float]) – Gives the separation of node label for nodes with negative y (y <= 0)

  • edge_width (Optional[int]) – Width of the edge line.

  • node_linewidth (Optional[float]) – Line width of node border

  • node_edgecolors (Optional[str]) – Colors of node borders

  • figsize (Optional[Tuple[int, int]]) – Size of the default figure (Only used if ax is not specified).

  • dpi (Optional[int]) – Pixel density of the default plot

  • node_size (Optional[int]) – Size of the nodes of the Graph to be plotted

  • colors (Optional[List[str]]) – A list with the colors used to plot the nodes of the graph.

  • ax (Optional[plt.axis]) – Axis on which to draw the graph.

Returns

The graph depicting the Markov chain which represents the invasion dynamics.

Return type

networkx.Graph

Notes

If there are too many strategies, this function may not only take a lot of time to generate the Graph, but it will also not be easy to visualize. Also, you should only use this function when ploting the invasion diagram assuming the small mutation limit of the replication dynamics (SML).

See also

plot_gradient

Examples

>>> import egttools as egt
>>> import matplotlib.pyplot as plt
>>> strategies = [egt.behaviors.NormalForm.TwoActions.Cooperator(), egt.behaviors.NormalForm.TwoActions.Defector(),
...               egt.behaviors.NormalForm.TwoActions.TFT(), egt.behaviors.NormalForm.TwoActions.Pavlov(),
...               egt.behaviors.NormalForm.TwoActions.Random(), egt.behaviors.NormalForm.TwoActions.GRIM()]
>>> strategy_labels = [strategy.type().replace("NFGStrategies::", '') for strategy in strategies]
>>> T=4; R=2; P=1; S=0; Z= 100; beta=1
>>> A = np.array([
...     [P, T],
...     [S, R]
... ])
>>> game = egt.games.NormalFormGame(100, A, strategies)
>>> evolver = egt.analytical.StochDynamics(len(strategies), game.expected_payoffs(), Z)
>>> sd = evolver.calculate_stationary_distribution(beta)
>>> transitions, fixation_probabilities = evolver.transition_and_fixation_matrix(beta)
>>> fig, ax = plt.subplots(figsize=(5, 5), dpi=150)
>>> G = egt.plotting.draw_invasion_diagram(strategy_labels, 1/Z, fixation_probabilities, sd,
...     node_size=2000, min_strategy_frequency=0.00001, ax=ax)
>>> plt.axis('off')
>>> plt.show() # display