%pylab inline
This notebook assumes that ews.py and visualization.py are in the same folder of this notebook.
We need to specify some parameters to call the estimation procedure.
!python ews.py
Let us call the estimation procedure with SEED=1234, 3 strategies, 50 samples and uniformly distributed games. Fifty samples will not give a quality estimate, but it is fine for demonstration purposes. This will take a couple of minutes...
!python ews.py 1234 3 50 0
We can list the newly created files
!ls -l *.pickle
We can inspect the results by unpickling the new files.
import pickle
filename_ranking_counts = 'n_3_dist_0_seed_1234_count.pickle'
filename_most_abundant_counts = 'ma_n_3_dist_0_seed_1234_count.pickle'
ranking_changes = pickle.load(open(filename_ranking_counts))
most_abundant_changes = pickle.load(open(filename_most_abundant_counts))
ranking_changes
In this paticular estimate, out of 50 samples, 34 have no ranking changes, 13 have one ranking change and 3 have two ranking changes.
most_abundant_changes
In 8 out of 50 cases, the most abundant strategy changes once.
We first import ews.py to load all the function definitions.
from ews import *
The first step in the estimation is to generate a random game. For this example, we use 3 strategies and uniformly distributed payoffs.
number_of_strategies = 3
distribution_type = 0 # for uniform
a_random_game = random_game(number_of_strategies, distribution_type)
print a_random_game
Let us create a vector of selection intensities, in order to compute the abundance curves. Inside this process, for every intensity of selection we will compute the transition matrix of the markov chain that describes the imitation process, and then compute the stationary distribution.
We use the default limits in variables LEFT_LIMIT and RIGHT_LIMIT:
'Intensity of selection interval = {}'.format((10**LEFT_LIMIT, 10**RIGHT_LIMIT))
intensity_vector = np.logspace(LEFT_LIMIT, RIGHT_LIMIT, num=100,
endpoint=True)
We create an auxliary matrix that contains the abundances vector across the values of our intensity vector.
Therefore, this matrix has as many columns as strategies in our game, and as many rows as values in intensity_vector
population_size = 30
matrix = get_curves_truncating(intensity_vector, a_random_game,
population_size,
truncate=True)
What are the dimensions of matrix?
matrix.shape
Note that if matrix has lesss than 100 values, the graph has been truncated to avoid overflow. This happens when selection is strong enough and the stationary distribution becomes a singleton.
We can now count how many intersections are there for this case:
count_intersections(matrix)
And how many changes in the most abundant strategy
count_most_abundant_changes(matrix)
Now we use the function in visualization.py to build a graph.
from visualization import plot_abundance
plot_abundance(matrix, intensity_vector)
You can re-run the cells up to here to generate another example.
We can use the functions in ews.py, for instance, to replicate Figure 3A.
figure_3a_game = np.array([[0.18,0.91,0.85],[0.11,0.59,0.78],[0.75,0.11,0.54]])
intensity_vector = np.logspace(LEFT_LIMIT, RIGHT_LIMIT, num=100,
endpoint=True)
auxiliary_matrix = get_curves_truncating(intensity_vector, figure_3a_game, population_size=30, truncate=True)
plot_abundance(auxiliary_matrix, intensity_vector)
We can also run the unit tests.
!python tests.py