Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rveltz committed May 7, 2024
1 parent 007fa16 commit 724bc08
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 30 deletions.
8 changes: 7 additions & 1 deletion docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[deps]
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
LSODA = "7f56f5a3-f504-529b-bc02-0b1fe5e64312"
PiecewiseDeterministicMarkovProcesses = "86206cdf-4603-54e0-bd58-22a2dcbf57aa"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Sundials = "c3572dad-4567-51f8-b174-8c6c989267f4"

[compat]
Documenter = "0.24.3"
Documenter = "1"
LSODA = "0.7"
32 changes: 21 additions & 11 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,17 +1,27 @@
using Pkg
cd(@__DIR__)
pkg" activate ."
pkg" dev LSODA Sundials Plots"

using Documenter, PiecewiseDeterministicMarkovProcesses

makedocs(doctest = false,
sitename = "PiecewiseDeterministicMarkovProcesses.jl",
pages = Any[
"Home" => "index.md",
"Tutorials" => "tutorials.md",
"Problem Type" => "problem.md",
"Solver Algorithms" => "solver.md",
"FAQ" => "addFeatures.md",
"Library" => "library.md"
]
makedocs(modules = [PiecewiseDeterministicMarkovProcesses],
authors = "Romain Veltz",
doctest = false,
pagesonly = true, # this is on Documenter#master, do not compile what is not in pages =
# draft = true,
warnonly = true,
sitename = "PiecewiseDeterministicMarkovProcesses.jl",
pages = Any[
"Home" => "index.md",
"Tutorials" => "tutorials.md",
"Problem Type" => "problem.md",
"Solver Algorithms" => "solver.md",
"FAQ" => "addFeatures.md",
"Library" => "library.md"
]
)

deploydocs(
repo = "github.com/rveltz/PiecewiseDeterministicMarkovProcesses.jl.git",
)
push_preview=true, target="build", devbranch="main")
29 changes: 11 additions & 18 deletions docs/src/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@ In between jumps, $x_c$ evolves according to

We first need to load the library.

```julia
```@example TUT1
using Revise, Sundials, Random
using PiecewiseDeterministicMarkovProcesses
const PDMP = PiecewiseDeterministicMarkovProcesses
```
We then define a function that encodes the dynamics in between jumps. We need to provide the vector field of the ODE. Hence, we define a function that, given the continuous state $x_c$ and the discrete state $x_d$ at time $t$, returns the vector field. In addition some parameters can be passed with the variable `parms`.

```julia
```@example TUT1
function F!(ẋ, xc, xd, parms, t)
if mod(xd[1],2)==0
ẋ[1] = 10xc[1]
Expand All @@ -47,7 +48,7 @@ We implement these jumps using a 2x1 matrix `nu` of Integers, such that the jump
The rates of these reactions are encoded in the following function.


```julia
```@example TUT1
k(x) = 1 + x
function R!(rate, xc, xd, parms, t, issum::Bool)
Expand Down Expand Up @@ -76,31 +77,27 @@ parms = [50.]

We define a problem type by giving the characteristics of the process `F, R, Delta, nu`, the initial conditions, and the timespan to solve over:

```julia
```@example TUT1
Random.seed!(8) # to get the same result as this simulation!
problem = PDMP.PDMPProblem(F!, R!, nu, xc0, xd0, parms, (0.0, 10.0))
```

After defining the problem, you solve it using `solve`.

```julia
```@example TUT1
sol = PDMP.solve(problem, CHV(CVODE_BDF()))
```

In this case, we chose to sample `pb` with the [CHV algorithm](https://arxiv.org/abs/1504.06873) where the flow in between jumps is integrated with the solver `CVODE_BDF()` from [DifferentialEquations.jl](https://github.com/JuliaDiffEq/DifferentialEquations.jl).

We can then plot the solution as follows:

```
```@example TUT1
# plotting
using Plots
Plots.plot(sol.time,sol.xc[1,:],label="xc")
```

This produces the graph:

![TCP](example1.png)


## Basic example with the rejection method
The previous method is useful when the total rate function varies a lot. In the case where the total rate is mostly constant in between jumps, the **rejection method** is more appropriate.
Expand All @@ -110,7 +107,7 @@ The **rejection method** assumes some a priori knowledge of the process one want

`sum(rate)(t) <= bound_rejection `

```julia
```@example TUT1
function R2!(rate, xc, xd, parms, t, issum::Bool)
# rate function
bound_rejection = 1. + parms[1] + 15 # bound on the total rate
Expand All @@ -128,7 +125,7 @@ end

We can now simulate this process as follows

```julia
```@example TUT1
Random.seed!(8) # to get the same result as this simulation!
problem = PDMP.PDMPProblem(F!, R2!, nu, xc0, xd0, parms, (0.0, 1.0))
sol = PDMP.solve(problem, Rejection(CVODE_BDF()))
Expand All @@ -138,12 +135,8 @@ In this case, we chose to sample `pb` with the Rejection algorithm where the flo

We can then plot the solution as follows:

```
```@example TUT1
# plotting
using Plots
Plots.plot(sol.time,sol.xc[1,:],label="xc")
```

This produces the graph:

![TCP](example2.png)
```

0 comments on commit 724bc08

Please sign in to comment.