Beispiel #1
0
    'ea': 1.0 - eps,
    'PiaA': 6.0,
    'PiAA': 5.0,
    'Piaa': 4.0,
    'PiAa': 3.0
}

# create an array of initial guesses for root finder
N = 100
prng = np.random.RandomState(42)
initial_males = prng.dirichlet(np.ones(4), size=N)
initial_females = initial_males
initial_guesses = np.hstack((initial_males, initial_females))

# create an instance of the model
example = model.Model(params=params, solver_kwargs={'tol': 1e-12})

# initialize a storage container
steady_states = np.empty((N, 8))

# compute the steady state of the model for different initial guesses
fig, ax = plt.subplots()
ind = np.arange(-0.5, 7.5)

for i in range(N):

    # extract initial guess
    example.initial_guess = initial_guesses[i]

    # solve the nonlinear system
    tmp_result = example.steady_state
from package import model

# fix the model parameters
params = {'dA': 0.25, 'da': 0.25, 'eA': 0.0, 'ea': 0.0, 'PiaA': 6.0,
          'PiAA': 5.0, 'Piaa': 4.0, 'PiAa': 3.0}

# define an array of initial conditions
N = 500
prng = np.random.RandomState(42)
initial_males = prng.dirichlet(np.ones(4), size=N)
initial_females = initial_males
initial_conditions = np.hstack((initial_males, initial_females))

# create an instance of the model
example = model.Model(params=params)

# storage container
results = np.empty((N, 8))

for i, initial_condition in enumerate(initial_conditions):

    # simulate the model to find the equilibrium
    tmp_traj = example.simulate(initial_condition, rtol=1e-4)

    # store the results
    results[i, :] = tmp_traj[:, -1]

### make the contour plot for
fig, ax = plt.subplots(1, 1, figsize=(8, 6))
fGA = initial_conditions[:, 4]
import sys
sys.path.append('../../')

import numpy as np

from package import model

# define a model object
mod = model.Model()

# define an array of initial conditions S_A = mGA = fGA
N_initial = 5
eps = 1e-3
mGA0 = np.linspace(eps, 1 - eps, N_initial)
mga0 = 1 - mGA0

tup = (mGA0[:, np.newaxis], np.zeros((mGA0.size, 2)), mga0[:, np.newaxis])
initial_males = np.hstack(tup)
initial_females = initial_males

initial_conditions = np.hstack((initial_males, initial_females))

# define some signaling and screening params
N_probs = 7
signaling_probs = np.linspace(eps, 1 - eps, N_probs)
screening_probs = signaling_probs

# storage container for results
tmp_shape = 4 * (N_probs, ) + (N_initial, 8)
results = np.empty(tmp_shape)
import matplotlib.pyplot as plt

from package import model

# fix the initial condition
prng = np.random.RandomState(56789)
initial_males = prng.dirichlet(np.ones(4), size=1)
initial_females = initial_males
initial_condition = np.hstack((initial_males, initial_females))

# define an array of screening probabilities
N = 21
screening_probs = np.linspace(0, 1, N)

# create an instance of the model
example = model.Model()

# storage container
results = np.empty((N, N, 8))

for i, eA in enumerate(screening_probs):
    for j, ea in enumerate(screening_probs):

        # females send random signals, but males screen imperfectly
        tmp_params = {'dA': 0.5, 'da': 0.5, 'eA': eA, 'ea': ea,
                      'PiaA': 6.0, 'PiAA': 5.0, 'Piaa': 4.0, 'PiAa': 3.0}

        # simulate the model to find the equilibrium
        example.params = tmp_params
        tmp_traj = example.simulate(initial_condition, rtol=1e-4)
Beispiel #5
0
    for j, initial_condition in enumerate(initial_conditions):

        # fix the model parameters
        tmp_params = {
            'dA': dA,
            'da': dA,
            'eA': 0.0,
            'ea': 0.0,
            'PiaA': 6.0,
            'PiAA': 5.0,
            'Piaa': 4.0,
            'PiAa': 3.0
        }

        # create an instance of the model
        tmp_example = model.Model(params=tmp_params)

        # simulate the model to find the equilibrium
        tmp_traj = tmp_example.simulate(initial_condition, rtol=1e-4)

        # store the results
        results[i, j, :] = tmp_traj[:, -1]

### make the contour plot for
fig, ax = plt.subplots(1, 1, figsize=(8, 6))

for i, dA in enumerate(signaling_probs[::4]):

    # equilibrium share of female altruists
    equilibrium_female_altruists = results[i, :, 4:7:2].sum(axis=1)