# Imports for the nbdev development environment
import nbdev
4 Annex: Heavy computations
import numpy as np
import matplotlib.pyplot as plt
= np.random.randn(2, 100)
data *data); plt.scatter(

#| default_exp HeavyComputations
#| export
import numpy as np
#| export
def noisy_predprey_model(prey_birth_rate,
prey_mortality,
predator_efficiency,
predator_death_rate,
initial_prey,
initial_predators,
time_length,
noiselevel):""" Discrete-time predator-prey model. """
= -1 * np.ones(time_length)
x = -1 * np.ones(time_length)
y 0] = initial_prey
x[0] = initial_predators
y[for t in range(1, time_length):
= x[t-1] + prey_birth_rate * x[t-1]\
x[t] - prey_mortality * y[t-1]*x[t-1]
= y[t-1] + predator_efficiency * y[t-1]*x[t-1]\
y[t] - predator_death_rate * y[t-1]\
+ noiselevel * (0.5 - np.random.rand())
return x, y
42)
np.random.seed(
= noisy_predprey_model(0.1, 0.1, 0.1, 0.01, 1.0, 1.0, 1000, 0.0)
preys, predators =3, ls='--', label="preys", color='blue', alpha=0.8)
plt.plot(preys, lw=3, ls='--', label="predators", color='orange', alpha=0.8)
plt.plot(predators, lw
for _ in range(35):
= noisy_predprey_model(0.1, 0.1, 0.1, 0.01, 1.0, 1.0, 1000,
preys, predators 0.025)
='blue', alpha=0.1)
plt.plot(preys, color='orange', alpha=0.1)
plt.plot(predators, color; plt.legend()
"HeavyComputations.ipynb", "_code") nbdev.export.nb_export(