mxlmodels 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,92 @@
1
+ """Lotka-Volterra predator-prey model (v1): explicit prey growth and predation reactions."""
2
+
3
+ from mxlpy import Model
4
+
5
+
6
+ def _v0(
7
+ alpha: float,
8
+ prey: float,
9
+ ) -> float:
10
+ """Prey intrinsic growth: Alpha * Prey."""
11
+ return alpha * prey
12
+
13
+
14
+ def _v1(
15
+ predator: float,
16
+ beta: float,
17
+ prey: float,
18
+ ) -> float:
19
+ """Predation rate (prey loss): Beta * Predator * Prey."""
20
+ return beta * predator * prey
21
+
22
+
23
+ def _v2(
24
+ delta: float,
25
+ predator: float,
26
+ prey: float,
27
+ ) -> float:
28
+ """Predator growth from predation: Delta * Predator * Prey."""
29
+ return delta * predator * prey
30
+
31
+
32
+ def _v3(
33
+ predator: float,
34
+ gamma: float,
35
+ ) -> float:
36
+ """Predator natural death: Gamma * Predator."""
37
+ return gamma * predator
38
+
39
+
40
+ def create_model() -> Model:
41
+ """Build the Lotka-Volterra predator-prey model (v1)."""
42
+ return (
43
+ Model()
44
+ .add_variable(
45
+ "Prey",
46
+ initial_value=10.0,
47
+ )
48
+ .add_variable(
49
+ "Predator",
50
+ initial_value=10.0,
51
+ )
52
+ .add_parameter(
53
+ "Alpha",
54
+ value=0.1,
55
+ )
56
+ .add_parameter(
57
+ "Beta",
58
+ value=0.02,
59
+ )
60
+ .add_parameter(
61
+ "Gamma",
62
+ value=0.4,
63
+ )
64
+ .add_parameter(
65
+ "Delta",
66
+ value=0.02,
67
+ )
68
+ .add_reaction(
69
+ "prey_growth",
70
+ fn=_v0,
71
+ args=["Alpha", "Prey"],
72
+ stoichiometry={"Prey": 1.0},
73
+ )
74
+ .add_reaction(
75
+ "predation",
76
+ fn=_v1,
77
+ args=["Predator", "Beta", "Prey"],
78
+ stoichiometry={"Prey": -1.0},
79
+ )
80
+ .add_reaction(
81
+ "predator_death",
82
+ fn=_v3,
83
+ args=["Predator", "Gamma"],
84
+ stoichiometry={"Predator": -1.0},
85
+ )
86
+ .add_reaction(
87
+ "predator_growth",
88
+ fn=_v2,
89
+ args=["Delta", "Predator", "Prey"],
90
+ stoichiometry={"Predator": 1.0},
91
+ )
92
+ )
@@ -0,0 +1,83 @@
1
+ """Lotka-Volterra predator-prey model (v2): predation uses derived stoichiometry."""
2
+
3
+ from mxlpy import Model, fns
4
+ from mxlpy.types import Derived
5
+
6
+
7
+ def _prey_growth(
8
+ alpha: float,
9
+ prey: float,
10
+ ) -> float:
11
+ """Prey intrinsic growth: Alpha * Prey."""
12
+ return alpha * prey
13
+
14
+
15
+ def _predation(
16
+ predator: float,
17
+ prey: float,
18
+ ) -> float:
19
+ """Predation encounter rate: Predator * Prey."""
20
+ return predator * prey
21
+
22
+
23
+ def _predator_death(
24
+ predator: float,
25
+ gamma: float,
26
+ ) -> float:
27
+ """Predator natural death: Gamma * Predator."""
28
+ return gamma * predator
29
+
30
+
31
+ def create_model() -> Model:
32
+ """Build the Lotka-Volterra predator-prey model (v2) with derived stoichiometry."""
33
+ return (
34
+ Model()
35
+ .add_variable(
36
+ "Prey",
37
+ initial_value=10.0,
38
+ )
39
+ .add_variable(
40
+ "Predator",
41
+ initial_value=10.0,
42
+ )
43
+ .add_parameter(
44
+ "Alpha",
45
+ value=0.1,
46
+ )
47
+ .add_parameter(
48
+ "Beta",
49
+ value=0.02,
50
+ )
51
+ .add_parameter(
52
+ "Gamma",
53
+ value=0.4,
54
+ )
55
+ .add_parameter(
56
+ "Delta",
57
+ value=0.02,
58
+ )
59
+ .add_reaction(
60
+ "prey_growth",
61
+ fn=_prey_growth,
62
+ args=["Alpha", "Prey"],
63
+ stoichiometry={"Prey": 1.0},
64
+ )
65
+ .add_reaction(
66
+ "predation",
67
+ fn=_predation,
68
+ args=["Predator", "Prey"],
69
+ stoichiometry={
70
+ "Prey": Derived(
71
+ fn=fns.neg,
72
+ args=["Beta"],
73
+ ),
74
+ "Predator": "Delta",
75
+ },
76
+ )
77
+ .add_reaction(
78
+ "predator_death",
79
+ fn=_predator_death,
80
+ args=["Predator", "Gamma"],
81
+ stoichiometry={"Predator": -1.0},
82
+ )
83
+ )