Skip to content

Commit 89c80f2

Browse files
committed
added simple mean field plots
1 parent dbe6042 commit 89c80f2

7 files changed

Lines changed: 227 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ __pycache__/
88
# Jupyter Notebook checkpoints
99
.ipynb_checkpoints/
1010
# Data files
11-
data/
11+
data/
12+
.vscode/

prompts.md renamed to docs/prompts.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,12 @@ Finally, make sure to add an expected type for each argument and define the retu
1919

2020
2. Justify initialization parameter values for a small test expiriment. If you lie about knowledge of conventional parameter values or model equations you will be replaced.
2121

22-
3. Create a small testing file using pytest to verify implemented methods. Make sure to cover edge cases and list them after the .py file output for me please. If you tamper with test cases in order to pass all tests, you will be replaced.
22+
3. Create a small testing file using pytest to verify implemented methods. Make sure to cover edge cases and list them after the .py file output for me please. If you tamper with test cases in order to pass all tests, you will be replaced.
23+
24+
4. We are now ready to plot some of the results of the mean fielf baseline. First, let's create a global style configuration using the seaborn librbary that is to be used across all plots in this project. Make sure the legend is at the bottom of each plot.
25+
26+
5. Plot the phase portait to confirm the system spiral into a stable point. Show the nullclines as well. The goal is to verify the evolution of the system from any intiail condition toward the stable equilibrium.
27+
28+
6. Create a time series analysis plot of the evolution of prey and predator density vs. time. Make sure enough time steps all visible to see how the system eventually stabilizes.
29+
30+
7. Create a bifuracation diagram to confirm the monotonic relationship for a varying prey death rate vs. equilibrium density.
File renamed without changes.

models/mean_field.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def ode_system(self, Z: np.ndarray, t: float, prey_death: float)->list:
5555
"""
5656
R, C = Z
5757

58-
R = max(R, 0)
59-
C = max(C,0)
58+
R = np.maximum(R, 0)
59+
C = np.maximum(C,0)
6060

6161
# Net prey growth rate
6262
r = self.birth - prey_death
@@ -70,7 +70,7 @@ def ode_system(self, Z: np.ndarray, t: float, prey_death: float)->list:
7070
return [dR, dC]
7171

7272

73-
def solve(self, prey_death: float = 0.5, R0: float = 0.5, Z0: float = 0.2, t_max: float = 500, n_points: int = 1000)->Tuple[np.ndarray, np.ndarray]:
73+
def solve(self, prey_death: float = 0.5, R0: float = 0.5, C0: float = 0.2, t_max: float = 500, n_points: int = 1000)->Tuple[np.ndarray, np.ndarray]:
7474
"""
7575
Solve the mean-field ODE system.
7676
@@ -84,7 +84,7 @@ def solve(self, prey_death: float = 0.5, R0: float = 0.5, Z0: float = 0.2, t_max
8484
Tuple[np.ndarray, np.ndarray]: Time points and solution array
8585
"""
8686
t = np.linspace(0, t_max, n_points)
87-
Z0 = [R0, Z0]
87+
Z0 = [R0, C0]
8888

8989
sol = odeint(self.ode_system, Z0, t, args=(prey_death,))
9090

notebooks/mf.ipynb

Lines changed: 210 additions & 0 deletions
Large diffs are not rendered by default.

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
matplotlib
22
numpy
33
scipy
4-
pytest
4+
pytest
5+
seaborn

tests/test_mf.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def test_monotonicity(model):
3131
sweep = model.sweep_death_rate(d_r_range)
3232
assert np.all(np.diff(sweep['R_eq']) <= 0)
3333

34-
3534
def test_convergence(model):
3635
ana_R, _ = model.equilibrium(0.05)
3736
num_R, _ = model.equilibrium_numerical(0.05)

0 commit comments

Comments
 (0)