# -*- coding: utf-8 -*-
"""
Created on Fri Jun 22 14:30:31 2018

@author: philipp.merz
"""

import birthdeathchain as bd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set(context='talk', style='whitegrid', color_codes=True)
# sns.set_palette("Blues")
G = bd.np.array([[1.1, 2], [2.1, 1]])
# dominated strat 3, 0.001 5, 1 becaus of rounding error
moran = bd.MarkovChain(54, s=1, game=G)

Tau_unif = []

for N in range(5, 200):
    moran = bd.MarkovChain(N, s=1, game=G)
    Tau_unif.append(np.mean(moran.expected_visits))
    del moran

fig, ax = plt.subplots()
ax.plot(range(5, 200), Tau_unif, label="average fixation time")
ax.set_xlabel(r"$N$-population size")
ax.legend(loc="best")
plt.show()
import birthdeathchain as bd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import sympy as sp
import pandas as pd

sns.set(context='talk', style='whitegrid')

G = bd.np.array([[3, 1], [1, 2]])

spread = []

for N_ in range(10, 800):
    moran = bd.MarkovChain(N_, s=1, game=G)
    moran.fixation_prob_calc()
    chaos_range = np.where(
        np.logical_and(moran.rho_i >= 0.001, moran.rho_i <= 0.999))[0]
    spread.append(chaos_range[-1] - chaos_range[0])

data = pd.DataFrame({"x": list(range(10, 800)), "spread": spread})

sns.lmplot(x="x",
           y="spread",
           data=data,
           order=2,
           ci=None,
           scatter_kws={"s": 80})

#for i in range(1, moran.N):
Esempio n. 3
0
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 11 21:35:22 2018

@author: philipp.merz
"""

import birthdeathchain as bd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np

sns.set(context='talk', style='whitegrid', color_codes=True)
qsd_s = []
mass_N = []
start = bd.np.zeros(49)
start[24] = 1

for eps in np.linspace(0.001, 2, num=100):
    G = bd.np.array([[1, 1 + eps], [1, 1]])
    moran = bd.MarkovChain(50, s=1, game=G)
    moran.fixation_prob_calc()
    mass_N.append(np.mean(moran.rho_i))
    moran.qsd_approx_script(start, precision=10)
    qsd_s.append(moran.qsd_q_power)

for qs in qsd_s:
    plt.plot(qs)
Esempio n. 4
0
@author: philipp.merz
"""

import birthdeathchain as bd
import matplotlib.pyplot as plt
import seaborn as sns
import numpy as np
import sympy as sp
from sympy.solvers.solveset import nonlinsolve

sp.init_printing()
sns.set(context='talk', style='whitegrid')

G = bd.np.array([[1, 3], [3, 1]])
moran = bd.MarkovChain(8, s=0, game=G)
# N gleich 17 ist schon nicht mehr abzuwarten
N = moran.N

q_string = ""

for i in range(1, moran.N):
    q_string += "q_" + str(i) + " "

q = sp.symbols(q_string)

b_i = moran.b_i[1:]
d_i = moran.d_i[:-1]
r_i = moran.r_i[1:-1]
c = 1 - q[0] * d_i[0] - q[-1] * b_i[-1]
"""
Created on Wed Mar 14 16:37:57 2018

@author: philipp.merz
"""

import birthdeathchain as bd
import matplotlib.pyplot as pl
import numpy as np

Game = bd.np.array([[1, 1.01], [1.01, 1]])
mass = {}
runs = {}

for i in range(520, 600, 16):
    moran = bd.MarkovChain(i, s=0, game=Game)
    moran.start_path(i // 2, str(i) + '_run', moran)
    moran.paths[str(i) + '_run'].completeRun(10)
    mass[str(i) + '_run_abs_mass'] = moran.paths[str(i) + '_run'].absorbed_mass
    print(i, moran.paths[str(i) + '_run'].absorbed_mass)
    del moran

# test for really high iterations of transition Matrix, inconclusive: looked
# like nothing changed even for absurd numbers when we renormalised
#
#for i in range(1, 9):
#    print(i)
#    mor_temp = bd.MarkovChain(i*50, game = Game)
#    mor_temp.start_path(i*25, 'dum', mor_temp)
#    mor_temp.paths['dum'].completeRun(50)
#    mass[str(i*50)+'abs_mass'] = mor_temp.paths['dum'].absorbed_mass
Esempio n. 6
0
fig, ax = plt.subplots()
starts = [0.01, 0.2, 0.5, 0.9, 0.99]
for i in starts:
    t, y = rep_moran(G, i)
    ax.plot(t, y, label="start at " + str(i))

ax.legend(loc='best')
plt.show()

x_result = []
x_moran = []
x_interior = []
x_axis = np.linspace(-1.0001, 0.9999, num=5000)
for l in x_axis:
    G_temp = np.array([[1, 1 + l], [1, 1]])
    x_result.append(x_star(G_temp))
    moran = bd.MarkovChain(100, s=1, game=G_temp)
    x_moran.append(
        np.argmin(abs(np.subtract(moran.b_i[1:], moran.d_i[:-1]))) + 1)
    x_interior.append(moran.x_interior)
    del moran

fig, ax = plt.subplots()
ax.plot(x_axis,
        np.divide(x_moran, 100),
        label=r"interior state $\frac{i}{100}$")
ax.plot(x_axis, x_result, label=r"$x^*$")
ax.legend(loc='best')
ax.set_xlabel(r"$\gamma$")
plt.show()