diff --git a/README.md b/README.md index 8e9f954..24830c0 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Analysis of a dynamical system with three species in a competitive loop: a rock The notebook [`long_range_simulations.ipynb`](./long_range_simulations.ipynb) analyzes simulations of the long-range dispersal model. -The model is examined under both discrete and continuous time frameworks. For the continuous time approach, the differential equation system defining the model is solved using the [`scipy.integrate`](https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate) package. Additionally, the model is reframed in terms of chemical reactions for stochastic simulations, which are conducted using the [`StochPy`](https://stochpy.sourceforge.net) package. It is further examined as a continuous-time Markov chain with the [`PRISM`](https://www.prismmodelchecker.org) stochastic model checker. +The model is examined under both discrete and continuous time frameworks. For the continuous time approach, the differential equation system defining the model is solved using the [`scipy.integrate`](https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate) package. Additionally, the model is reframed in terms of chemical reactions for stochastic simulations, which are conducted using the [`StochPy`](https://stochpy.sourceforge.net) package. It is further examined as a continuous-time Markov chain with the [`PRISM`](https://www.prismmodelchecker.org) stochastic model checker and as a Petri net with the tool [`Charlie`](https://www-dssz.informatik.tu-cottbus.de/DSSZ/Software/Charlie). ## Lattice model diff --git a/index.md b/index.md index 644e216..74ae879 100644 --- a/index.md +++ b/index.md @@ -4,7 +4,7 @@ Analysis of a dynamical system with three species in a competitive loop: a rock ## Long range dispersal model -Click [here](./long_range_simulations.html) to view the notebook `long_range_simulations.ipynb`, which analyzes simulations of the long-range dispersal model. The model is examined under both discrete and continuous time frameworks. For the continuous time approach, the differential equation system defining the model is solved using the [`scipy.integrate`](https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate) package. Additionally, the model is reframed in terms of chemical reactions for stochastic simulations, which are conducted using the [`StochPy`](https://stochpy.sourceforge.net) package. It is further examined as a continuous-time Markov chain with the [`PRISM`](https://www.prismmodelchecker.org) stochastic model checker. +Click [here](./long_range_simulations.html) to view the notebook `long_range_simulations.ipynb`, which analyzes simulations of the long-range dispersal model. The model is examined under both discrete and continuous time frameworks. For the continuous time approach, the differential equation system defining the model is solved using the [`scipy.integrate`](https://docs.scipy.org/doc/scipy/reference/integrate.html#module-scipy.integrate) package. Additionally, the model is reframed in terms of chemical reactions for stochastic simulations, which are conducted using the [`StochPy`](https://stochpy.sourceforge.net) package. It is further examined as a continuous-time Markov chain with the [`PRISM`](https://www.prismmodelchecker.org) stochastic model checker and as a Petri net with the tool [`Charlie`](https://www-dssz.informatik.tu-cottbus.de/DSSZ/Software/Charlie). ## Lattice model diff --git a/lattice_simulations.html b/lattice_simulations.html index 3d98668..8bc4226 100644 --- a/lattice_simulations.html +++ b/lattice_simulations.html @@ -7517,6 +7517,25 @@

Lattice model

This notebook simulates the evolution of the system with local dispersal, featuring three variants of the rock-paper-scissors game. All lattice-based model were developed using the Mesa framework. With Mesa's visualization tools, we can observe the spatial structures that emerge from the interactions between the agents.

+

Outline

+

Importing the necessary libraries:

@@ -7574,9 +7593,9 @@

Lattice model
@@ -7831,7 +7850,7 @@

Implementation detailsAt each step, a neighbor is randomly chosen and the agent in the patch interacts with it. According to the invasion rates, the neighboring agent may be defeated and may become the same species as the agent in the patch.
  • If the parameter increase_rate is set to True, after 100 steps the invasion rate of species 0 is increased whenever it replicates onto a new site. The increment is a random number uniformly distributed between 0 and 1e-4 and the new invasion rate is accepted if it is in the range $0<P_r<1$).
  • -

    Simulations

    Defining functions to run simulations and visualize the evolution of the system:

    +

    1.2. Simulations

    Defining functions to run simulations and visualize the evolution of the system:

    @@ -9116,8 +9135,8 @@

    Simulations

    An increase in the invasion rate of species R results in a decrease of its population.

    -

    Model with simultaneous activation of agents

    This is a variant of the model where the N sites are again taken to be sites in a periodic, square lattice, but at each time step, all agents are activated simultaneously. During activation, each agent competes with all its neighboring agents. If an agent is surrounded by at least three neighbors of the species that defeat it, it is transformed into an individual of that species. Note that invasion rates are not considered in this model.

    -

    Implementation details

    The model is defined by the class RSPSimAct in the file ./lattice_models/model_sim_act.py:

    +

    2. Model with simultaneous activation of agents

    This is a variant of the model where the N sites are again taken to be sites in a periodic, square lattice, but at each time step, all agents are activated simultaneously. During activation, each agent competes with all its neighboring agents. If an agent is surrounded by at least three neighbors of the species that defeat it, it is transformed into an individual of that species. Note that invasion rates are not considered in this model.

    +

    2.1. Implementation details

    The model is defined by the class RSPSimAct in the file ./lattice_models/model_sim_act.py:

    @@ -9330,7 +9349,7 @@

    Implementation detailsEach patch has a Moore neighborhood, i.e. the eight cells surrounding it.
  • At each step, an agent interacts with all its neighbors. If an agent is surrounded by at least three neighbors of the species that defeat it, it is transformed into an individual of that species. In case of a tie (possible with 5 species), the new species is chosen randomly among the species that defeated the agent.
  • -

    Simulations

    Let's define the parameters to perform a simulation of a system with 3 species, on a square lattice with $N=200\cdot 200$ sites, initialized with the sites being randomly assigned to each of the three species in equal proportions (init0=0.33, init1=0.33, init2=0.33).

    +

    2.2. Simulations

    Let's define the parameters to perform a simulation of a system with 3 species, on a square lattice with $N=200\cdot 200$ sites, initialized with the sites being randomly assigned to each of the three species in equal proportions (init0=0.33, init1=0.33, init2=0.33).

    @@ -10190,17 +10209,18 @@

    Simulations

    With 5 species, initially distributed in equal proportions, the system oscillates and again spiral patterns emerge.

    -

    Reichenbach, Mobilia, and Frey model

    In this model the N sites are taken to be sites in a periodic, square lattice. Each patch can be occupied by one of the species or can be blank. Each tick, the following types of events happen at defined average rates:

    +

    3. Reichenbach, Mobilia and Frey model

    In this model the N sites are taken to be sites in a periodic, square lattice. Each patch can be occupied by one of the species or can be blank. Each tick, the following types of events happen at defined average rates:

    Therefore, this model combines the local competition and reproduction from the Frean and Abraham model with spatial migration, a ubiquitous feature of real ecosystems.

    +

    For more details, see the original paper [2].

    The exact number of, for instance, swap events that occur each tick is drawn from a Poisson distribution with mean equal to $(number\_ of\_ patches) * 10 ^{swap-exponent}$. A Poisson distribution defines how many times a particular event occurs given an average rate for that event assuming that the occurrences of that event are independent. Here, the occurrences of the events are approximately independent since they're being performed by different organisms.

    The events occur in a random order involving random pairs of neighbors.

    See the original paper for more details: Reichenbach, Tobias, Mauro Mobilia, and Erwin Frey. "Mobility promotes and jeopardizes biodiversity in rock–paper–scissors games." Nature 448.7157 (2007): 1046-1049.

    -

    Implementation details

    The model is defined by the class RSPMobility in the file ./lattice_models/model_mobility.py:

    +

    3.1. Implementation details

    The model is defined by the class RSPMobility in the file ./lattice_models/model_mobility.py:

    @@ -10459,7 +10479,7 @@

    Implementation details
    @@ -11279,6 +11299,10 @@

    Simulations

    Also with 5 species, entangled rotating spiral waves emerge.

    +

    4. References

    diff --git a/lattice_simulations.ipynb b/lattice_simulations.ipynb index 8f23124..d1d7732 100644 --- a/lattice_simulations.ipynb +++ b/lattice_simulations.ipynb @@ -8,6 +8,19 @@ "\n", "This notebook simulates the evolution of the system with local dispersal, featuring three variants of the rock-paper-scissors game. All lattice-based model were developed using the [Mesa](https://mesa.readthedocs.io/en/stable/) framework. With Mesa's visualization tools, we can observe the spatial structures that emerge from the interactions between the agents.\n", "\n", + "**Outline**\n", + "\n", + "- [1. Frean and Abraham model](#1.-frean-and-abraham-model)\n", + " - [1.1. Implementation details](#1.1.-implementation-details)\n", + " - [1.2. Simulations](#1.2.-simulations)\n", + "- [2. Model with simultaneous activation of agents](#2.-model-with-simultaneous-activation-of-agents)\n", + " - [2.1. Implementation details](#2.1.-implementation-details)\n", + " - [2.2. Simulations](#2.2.-simulations)\n", + "- [3. Reichenbach, Mobilia and Frey model](#3.-reichenbach,-mobilia-and-frey-model)\n", + " - [3.1. Implementation details](#3.1.-implementation-details)\n", + " - [3.2. Simulations](#3.2.-simulations)\n", + "- [4. References](#4.-references)\n", + "\n", "Importing the necessary libraries:" ] }, @@ -51,13 +64,13 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "## Frean and Abraham model\n", + "## 1. Frean and Abraham model\n", "\n", "In this model the N sites are taken to be sites in a periodic, square lattice and each agent is activated once per time-step, in random order. During each activation, an agent competes with a randomly chosen neighboring agent. If the neighboring agent can be defeated, the agent wins the competition with a probability determined by the invasion rate. If the agent wins the competition, the neighboring agent is transformed into an individual of the same species of the winning agent.\n", "\n", - "See the original paper for more details: Frean, Marcus, and Edward R. Abraham. \"Rock–scissors–paper and the survival of the weakest.\" Proceedings of the Royal Society of London. Series B: Biological Sciences 268.1474 (2001): 1323-1327.\n", + "For more details, see the original paper [1].\n", "\n", - "### Implementation details\n", + "### 1.1. Implementation details\n", "\n", "The model is defined by the class `RSPRandAct` in the file `./lattice_models/model_rand_act.py`:" ] @@ -284,7 +297,7 @@ "- At each step, a neighbor is randomly chosen and the agent in the patch interacts with it. According to the invasion rates, the neighboring agent may be defeated and may become the same species as the agent in the patch.\n", "- If the parameter `increase_rate` is set to `True`, after 100 steps the invasion rate of species 0 is increased whenever it replicates onto a new site. The increment is a random number uniformly distributed between 0 and 1e-4 and the new invasion rate is accepted if it is in the range $0 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/long_range_simulations.html b/long_range_simulations.html index f696d3b..c7fc051 100644 --- a/long_range_simulations.html +++ b/long_range_simulations.html @@ -7517,6 +7517,19 @@ @@ -7537,6 +7550,7 @@

    Long range dispersal modelimport plotly.graph_objects as go from matplotlib import colormaps from scipy.integrate import odeint +from sympy import symbols, Matrix, Eq, solve np.random.seed(0) @@ -7550,7 +7564,7 @@

    Long range dispersal model @@ -8125,7 +8139,7 @@

    Discrete-time model @@ -8940,7 +8954,7 @@

    Continuous-time model @@ -10791,6 +10732,904 @@

    Stochastic Model Checking

    After a time step, the probability mass of species $s$ and $p$ is concentrated at lower values, while species $r$ has a more uniform distribution.

    +

    5. Petri net analysis

    A graphical representation of a system of chemical reaction can also be given in terms of Petri nets. Several variants of Petri nets exist, here we consider stochastic Petri nets, a variant that allows the modeling of stochastic systems.

    +

    For the rock-scissors-paper model, analyzing the net through property verification is relatively straightforward and doesn't provide substantial insights. However, we will carry out this verification as a tutorial to illustrate the step-by-step approach to modeling and analyzing more complex biochemical networks.

    +

    The Petri net representing the system was created using the Snoopy tool, saved as ./long_range_models/rsp.spn, and subsequently imported into the Charlie tool for analysis.

    +

    Let's introduce some definitions, necessary for the analysis of the Petri net.

    +

    A Stochastic Petri net consists of places, transitions with corresponding kinetic functions, arcs and tokens. Places represent the species, transitions represent the reactions, arcs represent the flow of species between reactions and tokens represent the number of molecules of each species.

    +

    More formally, a stochastic Petri net is a quintuple $N = (P, T, f, \nu, m_0)$, where

    +
      +
    • $P$ and $T$ are finite, non empty, and disjoint sets. $P$ is the set of places (in the figures represented by circles). $T$ is the set of transitions (in the figures represented by rectangles);
    • +
    • $f : ((P \times T)\cup (T \times P)) \rightarrow \mathbb{N}_0$ defines the set of directed arcs, weighted by nonnegative integer values;
    • +
    • $\nu:T \rightarrow \Psi$, with $\Psi=M\rightarrow R\geq 0$, is a function that assigns to each transition a function corresponding to the computation of a kinetic formula to every possible marking $m \in M$;
    • +
    • $m_0 \in M: P \rightarrow \mathbb{N}_0$ gives the initial marking.
    • +
    +

    The stochastic Petri net for the rock-paper-scissor system is shown below, where we set the initial marking $P=20, R=50, S=30$ and made the kinetic functions correspond to the law of mass action with constants equal to the invasion rates $P_r=0.2$, $P_s=0.5$ and $P_p=0.3$:

    +No description has been provided for this image +

    The preset of a node $x\in P \cup T$ is defined as $•x:=\{y\in P\cup T |f(y,x) \neq 0\}$, and its post set as $x• :=\{y\in P \cup T| f(x,y) \neq 0\}$. Altogether we get four types of sets:

    +
      +
    • $•t$, the preplaces of a transition $t$, consisting of the reaction’s precursors
    • +
    • $t•$, the postplaces of a transition $t$, consisting of the reaction’s products
    • +
    • $•p$, the pretransitions of a place $p$, consisting of all reactions producing this species
    • +
    • $p•$, the posttransitions of a place $p$, consisting of all reactions consuming this species
    • +
    +

    Given a set of places $S=p_1, p_2, \ldots$, the pre-transition of a set of places $S$ is defined as $•S=•p_1 \cup •p_2 \cup \ldots$, while the post-transition of a set of places $S$ is defined as $S•=p_1• \cup p_2• \cup \ldots$.

    +

    In this particular net, the pretransition and posttransition of the sites are as follows:

    +
      +
    • $•P=\{Pp\}$
    • +
    • $•R=\{Pr\}$
    • +
    • $•S=\{Ps\}$
    • +
    • $P•=\{Pp,Ps\}$
    • +
    • $R•=\{Pr,Pp\}$
    • +
    • $S•=\{Ps,Pr\}$
    • +
    +

    The incidence matrix of $\mathcal{N}$ is a matrix $C:P\times T \rightarrow \mathbb{Z}$, indexed by $P$ and $T$, such that $C(p,t)=f(t,p)−f(p,t)$.

    +

    Loading the file containing the incidence matrix produced by Charlie:

    + + + + + + + + + + + + + + +