-
Notifications
You must be signed in to change notification settings - Fork 264
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fragment the documentation for Moran processes.
Closes #961
- Loading branch information
1 parent
095baf0
commit e70555f
Showing
4 changed files
with
74 additions
and
65 deletions.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
docs/tutorials/further_topics/approximate_moran_processes.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
.. _approximate-moran-process: | ||
|
||
Approximate Moran Process | ||
========================= | ||
|
||
Due to the high computational cost of a single Moran process, an approximate | ||
Moran process is implemented that can make use of cached outcomes of games. The | ||
following code snippet will generate a Moran process in which a `Defector` | ||
cooperates (gets a high score) against another `Defector`. First the cache is | ||
built by passing counter objects of outcomes:: | ||
|
||
>>> import axelrod as axl | ||
>>> from collections import Counter | ||
>>> cached_outcomes = {} | ||
>>> cached_outcomes[("Cooperator", "Defector")] = axl.Pdf(Counter([(0, 5)])) | ||
>>> cached_outcomes[("Cooperator", "Cooperator")] = axl.Pdf(Counter([(3, 3)])) | ||
>>> cached_outcomes[("Defector", "Defector")] = axl.Pdf(Counter([(10, 10), (9, 9)])) | ||
|
||
Now let us create an Approximate Moran Process:: | ||
|
||
>>> axl.seed(0) | ||
>>> players = [axl.Cooperator(), axl.Defector(), axl.Defector(), axl.Defector()] | ||
>>> amp = axl.ApproximateMoranProcess(players, cached_outcomes) | ||
>>> results = amp.play() | ||
>>> amp.population_distribution() | ||
Counter({'Defector': 4}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
docs/tutorials/further_topics/moran_processes_on_graphs.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
.. _moran-process-on-graphs: | ||
|
||
Moran Process on Graphs | ||
======================= | ||
|
||
The library also provides a graph-based Moran process [Shakarian2013]_ with | ||
:code:`MoranProcessGraph`. To use this class you must supply at least one | ||
:code:`Axelrod.graph.Graph` object, which can be initialized with just a list of | ||
edges:: | ||
|
||
edges = [(source_1, target1), (source2, target2), ...] | ||
|
||
The nodes can be any hashable object (integers, strings, etc.). For example:: | ||
|
||
>>> import axelrod as axl | ||
>>> from axelrod.graph import Graph | ||
>>> edges = [(0, 1), (1, 2), (2, 3), (3, 1)] | ||
>>> graph = Graph(edges) | ||
|
||
Graphs are undirected by default. Various intermediates such as the list of | ||
neighbors are cached for efficiency by the graph object. | ||
|
||
A Moran process can be invoked with one or two graphs. The first graph, the | ||
*interaction graph*, dictates how players are matched up in the scoring phase. | ||
Each player plays a match with each neighbor. The second graph dictates how | ||
players replace another during reproduction. When an individual is selected to | ||
reproduce, it replaces one of its neighbors in the *reproduction graph*. If only | ||
one graph is supplied to the process, the two graphs are assumed to be the same. | ||
|
||
To create a graph-based Moran process, use a graph as follows:: | ||
|
||
>>> from axelrod.graph import Graph | ||
>>> axl.seed(40) | ||
>>> edges = [(0, 1), (1, 2), (2, 3), (3, 1)] | ||
>>> graph = Graph(edges) | ||
>>> players = [axl.Cooperator(), axl.Cooperator(), axl.Cooperator(), axl.Defector()] | ||
>>> mp = axl.MoranProcessGraph(players, interaction_graph=graph) | ||
>>> results = mp.play() | ||
>>> mp.population_distribution() | ||
Counter({'Cooperator': 4}) | ||
|
||
You can supply the `reproduction_graph` as a keyword argument. The standard Moran | ||
process is equivalent to using a complete graph for both graphs. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters