Skip to content

Commit

Permalink
Reword tutorial to use Random player.
Browse files Browse the repository at this point in the history
  • Loading branch information
drvinceknight committed Apr 3, 2017
1 parent 47b6be9 commit fe11a66
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
28 changes: 19 additions & 9 deletions docs/tutorials/further_topics/approximate_moran_processes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,32 @@ 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::
following code snippet will generate a Moran process in which the outcomes of
the matches played by a :code:`Random: 0.5` are sampled from one possible
outcome against each opponent (:code:`Defector` and :code:`Random: 0.5`). 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)]))
>>> cached_outcomes[("Random: 0.5", "Defector")] = axl.Pdf(Counter([(1, 1)]))
>>> cached_outcomes[("Random: 0.5", "Random: 0.5")] = axl.Pdf(Counter([(3, 3)]))
>>> cached_outcomes[("Defector", "Defector")] = axl.Pdf(Counter([(1, 1)]))

Now let us create an Approximate Moran Process::

>>> axl.seed(0)
>>> players = [axl.Cooperator(), axl.Defector(), axl.Defector(), axl.Defector()]
>>> axl.seed(2)
>>> players = [axl.Defector(), axl.Random(), axl.Random()]
>>> amp = axl.ApproximateMoranProcess(players, cached_outcomes)
>>> results = amp.play()
>>> amp.population_distribution()
Counter({'Defector': 4})
Counter({'Random: 0.5': 3})

We see that the :code:`Random: 0.5` won this Moran process. This is not what happens in a
standard Moran process where the `Random: 0.5` player will not win::

>>> axl.seed(2)
>>> amp = axl.MoranProcess(players)
>>> results = amp.play()
>>> amp.population_distribution()
Counter({'Defector': 3})
2 changes: 1 addition & 1 deletion docs/tutorials/getting_started/moran.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ the library, proceed as follows::
>>> import axelrod as axl
>>> axl.seed(0)
>>> players = [axl.Cooperator(), axl.Defector(),
... axl.TitForTat(), axl.Grudger()]
... axl.TitForTat(), axl.Grudger()]
>>> mp = axl.MoranProcess(players)
>>> populations = mp.play()
>>> mp.winning_strategy_name
Expand Down

0 comments on commit fe11a66

Please sign in to comment.