In [1]:

```
%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.

In [2]:

```
!python ews.py
```

**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...

In [3]:

```
!python ews.py 1234 3 50 0
```

We can list the newly created files

In [4]:

```
!ls -l *.pickle
```

We can inspect the results by unpickling the new files.

In [5]:

```
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'
```

In [6]:

```
ranking_changes = pickle.load(open(filename_ranking_counts))
most_abundant_changes = pickle.load(open(filename_most_abundant_counts))
```

In [7]:

```
ranking_changes
```

Out[7]:

In [8]:

```
most_abundant_changes
```

Out[8]:

In 8 out of 50 cases, the most abundant strategy changes once.

We first import *ews.py* to load all the function definitions.

In [9]:

```
from ews import *
```

In [10]:

```
number_of_strategies = 3
distribution_type = 0 # for uniform
a_random_game = random_game(number_of_strategies, distribution_type)
print a_random_game
```

We use the default limits in variables LEFT_LIMIT and RIGHT_LIMIT:

In [11]:

```
'Intensity of selection interval = {}'.format((10**LEFT_LIMIT, 10**RIGHT_LIMIT))
```

Out[11]:

In [12]:

```
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*

In [13]:

```
population_size = 30
matrix = get_curves_truncating(intensity_vector, a_random_game,
population_size,
truncate=True)
```

What are the dimensions of matrix?

In [14]:

```
matrix.shape
```

Out[14]:

*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:

In [15]:

```
count_intersections(matrix)
```

Out[15]:

And how many changes in the most abundant strategy

In [16]:

```
count_most_abundant_changes(matrix)
```

Out[16]:

Now we use the function in visualization.py to build a graph.

In [17]:

```
from visualization import plot_abundance
```

In [18]:

```
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**.

In [19]:

```
figure_3a_game = np.array([[0.18,0.91,0.85],[0.11,0.59,0.78],[0.75,0.11,0.54]])
```

In [20]:

```
intensity_vector = np.logspace(LEFT_LIMIT, RIGHT_LIMIT, num=100,
endpoint=True)
```

In [21]:

```
auxiliary_matrix = get_curves_truncating(intensity_vector, figure_3a_game, population_size=30, truncate=True)
```

In [22]:

```
plot_abundance(auxiliary_matrix, intensity_vector)
```

We can also run the unit tests.

In [23]:

```
!python tests.py
```