-
Documenter.jl authoredDocumenter.jl authored
starting.html 10.82 KiB
<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Getting Started · MarkovProcesses.jl</title><script data-outdated-warner src="assets/warner.js"></script><link href="https://cdnjs.cloudflare.com/ajax/libs/lato-font/3.0.0/css/lato-font.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/juliamono/0.045/juliamono.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.13.24/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL="."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="assets/documenter.js"></script><script src="siteinfo.js"></script><script src="../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-dark.css" data-theme-name="documenter-dark" data-theme-primary-dark/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><a class="docs-logo" href="index.html"><img src="assets/logo.png" alt="MarkovProcesses.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit"><a href="index.html">MarkovProcesses.jl</a></span></div><form class="docs-search" action="search.html"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="index.html">Home</a></li><li class="is-active"><a class="tocitem" href="starting.html">Getting Started</a><ul class="internal"><li><a class="tocitem" href="#Installation"><span>Installation</span></a></li><li><a class="tocitem" href="#Context-Mathematical-framework"><span>Context - Mathematical framework</span></a></li><li><a class="tocitem" href="#Models"><span>Models</span></a></li><li><a class="tocitem" href="#Trajectories"><span>Trajectories</span></a></li></ul></li><li><a class="tocitem" href="create_model.html">Create a model</a></li><li><span class="tocitem">API</span><ul><li><a class="tocitem" href="api/model.html">Model</a></li><li><a class="tocitem" href="api/trajectory.html">Trajectory</a></li><li><a class="tocitem" href="api/abc.html">Approximate Bayesian Computation</a></li><li><a class="tocitem" href="api/plots.html">Plots</a></li></ul></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href="starting.html">Getting Started</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href="starting.html">Getting Started</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com//blob/master/docs/src/starting.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="Getting-Started"><a class="docs-heading-anchor" href="#Getting-Started">Getting Started</a><a id="Getting-Started-1"></a><a class="docs-heading-anchor-permalink" href="#Getting-Started" title="Permalink"></a></h1><h2 id="Installation"><a class="docs-heading-anchor" href="#Installation">Installation</a><a id="Installation-1"></a><a class="docs-heading-anchor-permalink" href="#Installation" title="Permalink"></a></h2><ol><li>Launch Julia's REPL (for example by entering julia in your shell)</li><li>Enter Pkg's REPL by typing <code>]</code></li><li>Enter<pre><code class="language-julia hljs">pkg> add https://gitlab-research.centralesupelec.fr/2017bentrioum/markovprocesses.jl/</code></pre></li></ol><h2 id="Context-Mathematical-framework"><a class="docs-heading-anchor" href="#Context-Mathematical-framework">Context - Mathematical framework</a><a id="Context-Mathematical-framework-1"></a><a class="docs-heading-anchor-permalink" href="#Context-Mathematical-framework" title="Permalink"></a></h2><p>In this package, we are focused on Continuous-Time Markov Chains (CTMC, also called Markov jump processes), that can be described by Chemical Reaction Networks. The future state only depends on the current state. It is defined by two properties:</p><ul><li><span>$\forall t, s \in \mathbb{R}_{\geq 0}, \mathbb{P}(S_t | S_v, v \in [0,s]) = \mathbb{P}(S_t| S_s)$</span> (Memoryless/Markov property)</li><li><span>$\forall t,v \in \mathbb{R}_{\geq 0}, t > v, \mathbb{P}(S_t | S_v) = \mathbb{P}(S_{t-v} | S_0)$</span> (Time-homogeneity).</li></ul><p>A Chemical Reaction Network (CRN) is a formalism that describes biological phenomena. An example is the Susceptible-Infected-Removed model (SIR):</p><p><span>$R_1: S + I \xrightarrow{k_i} 2I$</span> <span>$R_2: I \xrightarrow{k_r} R$</span></p><p>This CRN has two reactions that models two phenomena: infection (<span>$R_1$</span>) or immunisation (<span>$R_2$</span>). Each reaction is parametrized by a kinetic rate (<span>$k_i$</span> or <span>$k_r$</span>). The stochastic dynamics of a CRN are described by CTMCs.</p><h2 id="Models"><a class="docs-heading-anchor" href="#Models">Models</a><a id="Models-1"></a><a class="docs-heading-anchor-permalink" href="#Models" title="Permalink"></a></h2><p>In the package, models are objects and their types all derived from the abstract type <code>Model</code>. Let's load the SIR model, which is pre-written within the package.</p><pre><code class="language-julia hljs">julia> load_model("SIR")
create_SIR (generic function with 1 method)
julia> println(SIR)
SIRModel <: ContinuousTimeModel model
- variables :
* I (index = 2 in state space)
* R (index = 3 in state space)
* S (index = 1 in state space)
- parameters :
* ki (index = 1 in parameter space)
* kr (index = 2 in parameter space)
- transitions : R1,R2
- observed variables :
* I (index = 1 in observed state space, index = 2 in state space)
p = [0.0012, 0.05]
x0 = [95, 5, 0]
t0 = 0.0
time bound = Inf</code></pre><p><code>load_model</code> has created a variable called SIR, which contains all the information for simulating the SIR model described above. It also contains a parameter vector and an initial point.</p><pre><code class="language-julia hljs">julia> @show SIR.p
@show SIR.x0
SIR.p = [0.0012, 0.05]
SIR.x0 = [95, 5, 0]</code></pre><p>You can change the parameters or the initial state with the functions <code>set_param!</code> and <code>set_x0!</code>.</p><pre><code class="language-julia hljs">julia> set_param!(SIR, :ki, 0.015)
julia> @show SIR.p
SIR.p = [0.015, 0.05]
julia> set_param!(SIR, [0.02, 0.07])
julia> @show SIR.p
SIR.p = [0.02, 0.07]
julia> set_x0!(SIR, :S, 93)
julia> @show SIR.x0
SIR.x0 = [93, 5, 0]</code></pre><h2 id="Trajectories"><a class="docs-heading-anchor" href="#Trajectories">Trajectories</a><a id="Trajectories-1"></a><a class="docs-heading-anchor-permalink" href="#Trajectories" title="Permalink"></a></h2><p>The simulation of the model is done by the function simulate.</p><pre><code class="language-julia hljs">julia> σ = simulate(SIR)</code></pre><p><code>simulate</code> returns a trajectory, which type is derived from <code>AbstractTrajectory</code>. It can be either an object of type <code>Trajectory</code> for models <code>::ContinuousTimeModel</code> or <code>SynchronizedTrajectory</code> for models that includes an automaton (but this is the subject of another section). It is easy to access the values of a trajectory.</p><pre><code class="language-julia hljs">julia> @show σ[3] # the third state of the trajectory
@show length_states(σ) # number of states
@show σ[:I, 4] # Fourth value of the variable I
@show σ.I[4] # Fourth value of the variable I
@show get_state_from_time(σ, 2.3)
σ[3] = [7]
length_states(σ) = 196
σ[:I, 4] = 8
σ.I[4] = 8
get_state_from_time(σ, 2.3) = [79]</code></pre><p>The SIR object includes an observation model symbolized by the vector <code>SIR.g</code>. Even if the variables of the model are <code>[:S, :I, :R]</code>, only I will be observed.</p><pre><code class="language-julia hljs">julia> @show SIR.map_var_idx
@show SIR.g
@show size(σ.values), length(σ[:I]) # Only one column which corresponds to the I variable
SIR.map_var_idx = Dict(:I => 2,:R => 3,:S => 1)
SIR.g = [:I]
(size(σ.values), length(σ[:I])) = ((1,), 196)</code></pre><p>The SIR model is by default unbounded, i.e. each trajectory is simulated until it reaches an absorbing state.</p><pre><code class="language-julia hljs">julia> @show isbounded(SIR)
@show isbounded(σ)
isbounded(SIR) = false
isbounded(σ) = false</code></pre><p>We can bound the SIR's trajectories until time 120 by running <code>set_time_bound!(SIR, 120.0)</code>.</p></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="index.html">« Home</a><a class="docs-footer-nextpage" href="create_model.html">Create a model »</a><div class="flexbox-break"></div><p class="footer-message">Powered by <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> and the <a href="https://julialang.org/">Julia Programming Language</a>.</p></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> version 0.27.24 on <span class="colophon-date" title="Monday 22 May 2023 14:03">Monday 22 May 2023</span>. Using Julia version 1.7.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>