Skip to content

Moran processes are always stochastic #796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 1 addition & 10 deletions axelrod/moran.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# -*- coding: utf-8 -*-
from collections import Counter
import random

import numpy as np

from .deterministic_cache import DeterministicCache
from .match import Match, is_stochastic
from .match import Match
from .random_ import randrange


Expand Down Expand Up @@ -94,14 +93,6 @@ def set_players(self):
self.populations = [self.population_distribution()]
self.num_players = len(self.players)

@property
def _stochastic(self):
"""
A boolean to show whether a match between two players would be
stochastic
"""
return is_stochastic(self.players, self.noise) or (self.mutation_rate > 0)

def mutate(self, index):
# If mutate, choose another strategy at random from the initial population
r = random.random()
Expand Down
19 changes: 2 additions & 17 deletions axelrod/tests/unit/test_moran.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
# -*- coding: utf-8 -*-
from collections import Counter
import itertools
import random
import unittest

from hypothesis import given, example, settings

import axelrod
from axelrod import MoranProcess
from axelrod.moran import fitness_proportionate_selection

from hypothesis import given, example, settings

from axelrod.tests.property import strategy_lists


Expand All @@ -21,17 +19,6 @@ def test_fps(self):
self.assertEqual(fitness_proportionate_selection([1, 1, 1]), 0)
self.assertEqual(fitness_proportionate_selection([1, 1, 1]), 2)

def test_stochastic(self):
p1, p2 = axelrod.Cooperator(), axelrod.Cooperator()
mp = MoranProcess((p1, p2))
self.assertFalse(mp._stochastic)
p1, p2 = axelrod.Cooperator(), axelrod.Cooperator()
mp = MoranProcess((p1, p2), noise=0.05)
self.assertTrue(mp._stochastic)
p1, p2 = axelrod.Cooperator(), axelrod.Random()
mp = MoranProcess((p1, p2))
self.assertTrue(mp._stochastic)

def test_exit_condition(self):
p1, p2 = axelrod.Cooperator(), axelrod.Cooperator()
mp = MoranProcess((p1, p2))
Expand Down Expand Up @@ -62,7 +49,6 @@ def test_two_players_with_mutation(self):
p1, p2 = axelrod.Cooperator(), axelrod.Defector()
random.seed(5)
mp = MoranProcess((p1, p2), mutation_rate=0.2)
self.assertEqual(mp._stochastic, True)
self.assertDictEqual(mp.mutation_targets, {str(p1): [p2], str(p2): [p1]})
# Test that mutation causes the population to alternate between fixations
counters = [
Expand Down Expand Up @@ -99,7 +85,6 @@ def test_three_players_with_mutation(self):
p3 = axelrod.Defector()
players = [p1, p2, p3]
mp = MoranProcess(players, mutation_rate=0.2)
self.assertEqual(mp._stochastic, True)
self.assertDictEqual(mp.mutation_targets, {str(p1): [p3, p2], str(p2): [p1, p3], str(p3): [p1, p2]})
# Test that mutation causes the population to alternate between fixations
counters = [
Expand Down