Skip to content

Commit

Permalink
finalized Petri nets analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
iretes committed Aug 19, 2024
1 parent 01fb8fe commit b46732d
Show file tree
Hide file tree
Showing 12 changed files with 2,028 additions and 426 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 34 additions & 10 deletions lattice_simulations.html
Original file line number Diff line number Diff line change
Expand Up @@ -7517,6 +7517,25 @@
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h1 id="Lattice-model">Lattice model<a class="anchor-link" href="#Lattice-model">¶</a></h1><p>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 <a href="https://mesa.readthedocs.io/en/stable/">Mesa</a> framework. With Mesa's visualization tools, we can observe the spatial structures that emerge from the interactions between the agents.</p>
<p><strong>Outline</strong></p>
<ul>
<li><a href="#1.-frean-and-abraham-model">1. Frean and Abraham model</a><ul>
<li><a href="#1.1.-implementation-details">1.1. Implementation details</a></li>
<li><a href="#1.2.-simulations">1.2. Simulations</a></li>
</ul>
</li>
<li><a href="#2.-model-with-simultaneous-activation-of-agents">2. Model with simultaneous activation of agents</a><ul>
<li><a href="#2.1.-implementation-details">2.1. Implementation details</a></li>
<li><a href="#2.2.-simulations">2.2. Simulations</a></li>
</ul>
</li>
<li><a href="#3.-reichenbach,-mobilia-and-frey-model">3. Reichenbach, Mobilia and Frey model</a><ul>
<li><a href="#3.1.-implementation-details">3.1. Implementation details</a></li>
<li><a href="#3.2.-simulations">3.2. Simulations</a></li>
</ul>
</li>
<li><a href="#4.-references">4. References</a></li>
</ul>
<p>Importing the necessary libraries:</p>
</div>
</div>
Expand Down Expand Up @@ -7574,9 +7593,9 @@ <h1 id="Lattice-model">Lattice model<a class="anchor-link" href="#Lattice-model"
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h2 id="Frean-and-Abraham-model">Frean and Abraham model<a class="anchor-link" href="#Frean-and-Abraham-model">¶</a></h2><p>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.</p>
<p>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.</p>
<h3 id="Implementation-details">Implementation details<a class="anchor-link" href="#Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPRandAct</code> in the file <code>./lattice_models/model_rand_act.py</code>:</p>
<h2 id="1.-Frean-and-Abraham-model">1. Frean and Abraham model<a class="anchor-link" href="#1.-Frean-and-Abraham-model">¶</a></h2><p>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.</p>
<p>For more details, see the original paper [1].</p>
<h3 id="1.1.-Implementation-details">1.1. Implementation details<a class="anchor-link" href="#1.1.-Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPRandAct</code> in the file <code>./lattice_models/model_rand_act.py</code>:</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -7831,7 +7850,7 @@ <h3 id="Implementation-details">Implementation details<a class="anchor-link" hre
<li>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.</li>
<li>If the parameter <code>increase_rate</code> is set to <code>True</code>, 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&lt;P_r&lt;1$).</li>
</ul>
<h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a></h3><p>Defining functions to run simulations and visualize the evolution of the system:</p>
<h3 id="1.2.-Simulations">1.2. Simulations<a class="anchor-link" href="#1.2.-Simulations">¶</a></h3><p>Defining functions to run simulations and visualize the evolution of the system:</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -9116,8 +9135,8 @@ <h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<p>An increase in the invasion rate of species R results in a decrease of its population.</p>
<h2 id="Model-with-simultaneous-activation-of-agents">Model with simultaneous activation of agents<a class="anchor-link" href="#Model-with-simultaneous-activation-of-agents">¶</a></h2><p>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.</p>
<h3 id="Implementation-details">Implementation details<a class="anchor-link" href="#Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPSimAct</code> in the file <code>./lattice_models/model_sim_act.py</code>:</p>
<h2 id="2.-Model-with-simultaneous-activation-of-agents">2. Model with simultaneous activation of agents<a class="anchor-link" href="#2.-Model-with-simultaneous-activation-of-agents">¶</a></h2><p>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.</p>
<h3 id="2.1.-Implementation-details">2.1. Implementation details<a class="anchor-link" href="#2.1.-Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPSimAct</code> in the file <code>./lattice_models/model_sim_act.py</code>:</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -9330,7 +9349,7 @@ <h3 id="Implementation-details">Implementation details<a class="anchor-link" hre
<li>Each patch has a Moore neighborhood, i.e. the eight cells surrounding it.</li>
<li>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.</li>
</ul>
<h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a></h3><p>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 (<code>init0</code>=0.33, <code>init1</code>=0.33, <code>init2</code>=0.33).</p>
<h3 id="2.2.-Simulations">2.2. Simulations<a class="anchor-link" href="#2.2.-Simulations">¶</a></h3><p>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 (<code>init0</code>=0.33, <code>init1</code>=0.33, <code>init2</code>=0.33).</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -10190,17 +10209,18 @@ <h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<p>With 5 species, initially distributed in equal proportions, the system oscillates and again spiral patterns emerge.</p>
<h2 id="Reichenbach,-Mobilia,-and-Frey-model">Reichenbach, Mobilia, and Frey model<a class="anchor-link" href="#Reichenbach,-Mobilia,-and-Frey-model">¶</a></h2><p>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:</p>
<h2 id="3.-Reichenbach,-Mobilia-and-Frey-model">3. Reichenbach, Mobilia and Frey model<a class="anchor-link" href="#3.-Reichenbach,-Mobilia-and-Frey-model">¶</a></h2><p>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:</p>
<ul>
<li><strong>Select event</strong>: Two random neighbors compete with each other. The losing patch becomes blanks.</li>
<li><strong>Reproduce event</strong>: Two random neighbors attempt to reproduce. If one of the neighbors is blank, it acquires the color of the other. Nothing happens if neither neighbor is blank.</li>
<li><strong>Swap event</strong>: Two random neighbors swap color. This represents the organisms moving.</li>
</ul>
<p>Therefore, this model combines the local competition and reproduction from the Frean and Abraham model with spatial migration, a ubiquitous feature of real ecosystems.</p>
<p>For more details, see the original paper [2].</p>
<p>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.</p>
<p>The events occur in a random order involving random pairs of neighbors.</p>
<p>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.</p>
<h3 id="Implementation-details">Implementation details<a class="anchor-link" href="#Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPMobility</code> in the file <code>./lattice_models/model_mobility.py</code>:</p>
<h3 id="3.1.-Implementation-details">3.1. Implementation details<a class="anchor-link" href="#3.1.-Implementation-details">¶</a></h3><p>The model is defined by the class <code>RSPMobility</code> in the file <code>./lattice_models/model_mobility.py</code>:</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -10459,7 +10479,7 @@ <h3 id="Implementation-details">Implementation details<a class="anchor-link" hre
</div>
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a></h3><p>Let's define the parameters to perform a simulation of a system with 3 species, on a square lattice with $N=150\cdot 150$ sites, initialized with the sites being randomly assigned to each of the three species and empty sites in equal proportions (<code>init0</code>=0.25, <code>init1</code>=0.25, <code>init2</code>=0.25, <code>init3</code>=0.25). Black patches represent empty sites.</p>
<h3 id="3.2.-Simulations">3.2. Simulations<a class="anchor-link" href="#3.2.-Simulations">¶</a></h3><p>Let's define the parameters to perform a simulation of a system with 3 species, on a square lattice with $N=150\cdot 150$ sites, initialized with the sites being randomly assigned to each of the three species and empty sites in equal proportions (<code>init0</code>=0.25, <code>init1</code>=0.25, <code>init2</code>=0.25, <code>init3</code>=0.25). Black patches represent empty sites.</p>
</div>
</div>
</div>
Expand Down Expand Up @@ -11279,6 +11299,10 @@ <h3 id="Simulations">Simulations<a class="anchor-link" href="#Simulations">¶</a
<div class="jp-InputArea jp-Cell-inputArea"><div class="jp-InputPrompt jp-InputArea-prompt">
</div><div class="jp-RenderedHTMLCommon jp-RenderedMarkdown jp-MarkdownOutput" data-mime-type="text/markdown">
<p>Also with 5 species, entangled rotating spiral waves emerge.</p>
<h2 id="4.-References">4. References<a class="anchor-link" href="#4.-References">¶</a></h2><ul>
<li>[1] 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.</li>
<li>[2] Reichenbach, Tobias, Mauro Mobilia, and Erwin Frey. "Mobility promotes and jeopardizes biodiversity in rock–paper–scissors games." Nature 448.7157 (2007): 1046-1049.</li>
</ul>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit b46732d

Please sign in to comment.