Skip to content

Commit

Permalink
Merge 70f9cd5 into 3fd02b0
Browse files Browse the repository at this point in the history
  • Loading branch information
gzagatti committed Nov 21, 2023
2 parents 3fd02b0 + 70f9cd5 commit db55c72
Show file tree
Hide file tree
Showing 12 changed files with 1,062 additions and 109 deletions.
5 changes: 5 additions & 0 deletions docs/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[deps]
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GR_jll = "d2c73de3-f751-5644-a686-071e5b155ba9"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PointProcesses = "af0b7596-9bb0-472a-a012-63904f2b4c55"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"

[compat]
Expand Down
9 changes: 6 additions & 3 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
# Put in a separate page so it can be used by SciMLDocs.jl

pages = ["index.md",
"getting_started.md",
"Tutorials" => Any["tutorials/simple_poisson_process.md",
"tutorials/discrete_stochastic_example.md",
"tutorials/jump_diffusion.md",
"tutorials/spatial.md"],
"FAQ" => "faq.md",
"Type Documentation" => Any["Jump types and JumpProblem" => "jump_types.md",
"tutorials/point_process.md",
"tutorials/spatial.md",
],
"Type Documentation" => Any["Jumps, JumpProblem, and Aggregators" => "jump_types.md",
"Jump solvers" => "jump_solve.md"],
"FAQ" => "faq.md",
"API" => "api.md",
]
4 changes: 2 additions & 2 deletions docs/src/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SSAStepper
reset_aggregated_jumps!
```

## Types of Jumps
## Jump Types

```@docs
ConstantRateJump
Expand All @@ -22,7 +22,7 @@ RegularJump
JumpSet
```

## Aggregators
## Aggregator Types

Aggregators are the underlying algorithms used for sampling
[`ConstantRateJump`](@ref)s, [`MassActionJump`](@ref)s, and
Expand Down
5 changes: 5 additions & 0 deletions docs/src/assets/Project.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
[deps]
Catalyst = "479239e8-5488-4da2-87a7-35f2df7eef83"
DensityInterface = "b429d917-457f-4dbc-8f4c-0cc954292b1d"
DifferentialEquations = "0c46a032-eb83-5123-abaf-570d42b7fbaa"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
GR_jll = "d2c73de3-f751-5644-a686-071e5b155ba9"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
JumpProcesses = "ccbc3e58-028d-4f4c-8cd5-9ae44345cda5"
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
PointProcesses = "af0b7596-9bb0-472a-a012-63904f2b4c55"
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0"

[compat]
Expand Down
176 changes: 176 additions & 0 deletions docs/src/getting_started.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
# Getting Started with JumpProcesses in Julia

Jumps (or point) processes are stochastic processes with discrete state changes
driven by a `rate` function. Historically, jump processes have been developed in
the context of dynamical systems to describe dynamics with sudden changes —
the jumps — in a system's value at random times. In contrast, the development
of point processes has been more focused on describing the occurrence of random
events — the points — over a support. In reality, jump and point processes
share many things in common which make JumpProcesses ideal for both.

Processes involving multiple jumps are known as compound jump (or point)
processes.
```math
du = \sum_{j} h_j(u,p,t) dN_j(t)
```
where ``N_j`` is a jump process with rate ``\lambda_i(u,p,t)``.

The homogeneous Poisson process is the canonical point process with a constant
rate of change. A compound Poisson process is a continuous-time Markov Chain
where the time to the next jump is exponentially distributed as determined by
the aggregate rate. In the statistics literature, the composition of Poisson
processes is described by the superposition theorem. Simulation algorithms for
these types of processes are known in biology and chemistry as Gillespie methods
or Stochastic Simulation Algorithms (SSA), with the time evolution that the
probability these processes are in a given state at a given time satisfying the
Chemical Master Equation (CME).

Any differential equation can be extended by jumps. For example, we have an ODE
with jumps, denoted by
```math
du = f(u,p,t)dt + \sum_{j} h_j(u,p,t) dN_j(t)
```
Extending a stochastic differential equation (SDE) to have jumps is commonly known as a jump-
diffusion, and is denoted by
```math
du = f(u,p,t)dt + \sum_{i}g_i(u,t)dW_i(t) + \sum_{j}h_i(u,p,t)dN_i(t)
```

The general workflow with any of the jump processes above is to define the base
and jump problem, solve the jump problem and then analyze the solution. The full
code for a jump process with no other dynamics apart from jumps is:
```@example ex0
using JumpProcesses
u0 = [0]
tspan = (0.0, 10.0)
dprob = DiscreteProblem(u0, tspan)
rate(u, p, t) = 2.0
affect!(integrator) = (integrator.u[1] += 1)
jump = ConstantRateJump(rate, affect!)
jprob = JumpProblem(dprob, Direct(), jump)
sol = solve(jprob, SSAStepper())
using Plots
plot(sol, title="Sample path from a jump process with constant rate",
label = "N(t)", xlabel = "t", legend = :bottomright)
```

## Step 1: Defining a problem

The first thing you want to do is to define your base problem from the many
options available. For dynamics that involve only jumps we employ
a `DiscreteProblem` as our base problem.
```@example ex0
using JumpProcesses
u0 = [0]
tspan = (0.0, 10.0)
dprob = DiscreteProblem(u0, tspan)
```

For our example, notice that `u0` is a `Int[]` which is an appropriate choice in
this case because we will only be working with jumps. Since we will be modifying
`u0` only when a jump occurs via its `affect!`, we initialize `DiscreteProblem`
without any function mapping which means `DiscreteProblem` use the default
identity mapping.

JumpProcesses exports
[`DiscreteProblem`](https://docs.sciml.ai/DiffEqDocs/stable/types/discrete_types/)
from OrdinaryDiffEq. In case you want
to model the base dynamics as an
[`ODEProblem`](https://docs.sciml.ai/DiffEqDocs/stable/types/ode_types/) or as
an [`SDEProblem`](https://docs.sciml.ai/DiffEqDocs/stable/types/sde_types/)
you will need to import
OrdinaryDiffEq.

## Step 2: Defining a jump

Jumps are implemented as [callbacks
functions](https://docs.sciml.ai/DiffEqDocs/stable/features/callback_functions/)
from DifferentialEquations. Our library takes care of adding the appropriate
callbacks to the base problem to ensure that jumps are properly initialized and
executed.

Here we add a `ConstantRateJump` to the base problem. As such the user must
define the `rate` and `affect!` which determines the frequency and the effect of
the jumps on the base problem.
```@example ex0
rate(u, p, t) = 2.0
affect!(integrator) = (integrator.u[1] += 1)
jump = ConstantRateJump(rate, affect!)
```

There are many types of jumps. Some of them allow for variable rates. You can
read about [different jump types in this page](@ref jump_types).

Once the jump is defined, we initialize the `JumpProblem`. _Aggegators_ are
algorithms that determines jump times. We call them _aggregators_ because they
aggregate all jump callbacks into a single callback. Alternatively, we can think
of aggregators as the jump simulation algorithms. In this case we use the
`Direct` _aggregator_.
```@example ex0
jprob = JumpProblem(dprob, Direct(), jump)
```

JumpProblem can be initialized with different combination of jumps and
aggregators. If you want to understand more about the options available read
about [JumpProblem initialization in here](@ref defining_jump_problem).

In addition to that, aggregators come with different trade-offs. Not all
aggregators accept all jump types. To learn [more about _aggregators_ check this
section](@ref Jump-Aggregators-for-Exact-Simulation).

## Step 3: Solving a problem

After defining a problem, we solve it using `solve` with an appropriate stepper.
```@example ex0
sol = solve(jprob, SSAStepper())
```

Steppers tell how we evolve time in our base problem and required for any
numerical simulator. JumpProcesses offers the `SSAStepper` which steps through
time one jump candidate at a time.

If you are modelling other types of base problems like `ODEProblem` or
`SDEProblem`, you will not be able to use `SSAStepper` since these problems
require more fine-grained time evolution.

Apart from time-stepping, you might also be interested in controlling the saving
frequency of the state variable `u`. This control can be thought as orthogonal
to how the stepper evolves time. To avoid saving at every jump, we can
initialize jumps as following.
```@example ex0
jprob = JumpProblem(dprob, Direct(), jump; save_positions = (false, false))
```

Finally, to solve the problem at regular intervals we can use `saveat`.
```@example ex0
sol = solve(jprob, SSAStepper(); saveat = 1.0)
```
When you do not save the jump events, be careful when analysing interpolated
values as they will not be an accurate representation of the sampled path. This
can be particularly problematic plotting the data.

## Going Beyond the Poisson process: How to Use the Documentation

This tutorial covered only the basics of the Poisson process with constant rate.
We mostly focused on the basic pattern to define and solve a JumpProblem.

In case you want to go further, JumpProcesses is a component package in the
[SciML](https://sciml.ai/) ecosystem, and one of the core solver libraries
included in
[DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/).

The documentation includes tutorials and examples:

- [Simulating basic Poisson processes](@ref poisson_proc_tutorial)
- [Simulating jump processes via SSAs (i.e., Gillespie methods)](@ref ssa_tutorial)
- [Simulating jump-diffusion processes](@ref jump_diffusion_tutorial)
- [Temporal point processes (TPP)](@ref tpp_tutorial)
- [Spatial SSAs](@ref Spatial-SSAs-with-JumpProcesses.jl)

In addition to that the document contains references to guide you through:

- [References on the types of jumps and available simulation methods](@ref jump_problem_type)
- [References on jump time stepping methods](@ref jump_solve)
- [FAQ with information on changing parameters between simulations and using callbacks](@ref FAQ)
- [API documentation](@ref JumpProcesses.jl-API)
31 changes: 22 additions & 9 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,32 @@ methods, or Kinetic Monte Carlo methods. It also enables the incorporation of
jump processes into hybrid jump-ODE and jump-SDE models, including jump
diffusions.

Historically, jump processes have been developed in the context of dynamical
systems to describe dynamics with sudden changes — the jumps — in a
system's value at random times. In contrast, the development of point processes
has been more focused on describing the occurrence of random events — the
points — over a support. In reality, jump and point processes share many
things in common which make JumpProcesses ideal for both.

JumpProcesses is a component package in the [SciML](https://sciml.ai/) ecosystem,
and one of the core solver libraries included in
[DifferentialEquations.jl](https://docs.sciml.ai/DiffEqDocs/stable/).

The documentation includes
The documentation includes tutorials and examples:

- [Getting Started with JumpProcesses in Julia](@ref)
- [Simulating basic Poisson processes](@ref poisson_proc_tutorial)
- [Simulating jump processes via SSAs (i.e., Gillespie methods)](@ref ssa_tutorial)
- [Simulating jump-diffusion processes](@ref jump_diffusion_tutorial)
- [Temporal point processes (TPP)](@ref tpp_tutorial)
- [Spatial SSAs](@ref Spatial-SSAs-with-JumpProcesses.jl)

In addition to that the document contains references to guide you through:

- [a tutorial on simulating basic Poisson processes](@ref poisson_proc_tutorial)
- [a tutorial and details on using JumpProcesses to simulate jump processes via SSAs (i.e., Gillespie methods)](@ref ssa_tutorial),
- [a tutorial on simulating jump-diffusion processes](@ref jump_diffusion_tutorial),
- [a reference on the types of jumps and available simulation methods](@ref jump_problem_type),
- [a reference on jump time stepping methods](@ref jump_solve)
- a [FAQ](@ref) with information on changing parameters between simulations and using callbacks.
- the [JumpProcesses.jl API](@ref) documentation.
- [References on the types of jumps and available simulation methods](@ref jump_problem_type)
- [References on jump time stepping methods](@ref jump_solve)
- [FAQ with information on changing parameters between simulations and using callbacks](@ref FAQ)
- [API documentation](@ref JumpProcesses.jl-API)

## Installation

Expand Down Expand Up @@ -110,7 +123,7 @@ link_manifest = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * ver
"/assets/Manifest.toml"
link_project = "https://github.com/SciML/" * name * ".jl/tree/gh-pages/v" * version *
"/assets/Project.toml"
Markdown.parse("""You can also download the
Markdown.parse("""\nYou can also download the
[manifest]($link_manifest)
file and the
[project]($link_project)
Expand Down
36 changes: 3 additions & 33 deletions docs/src/jump_types.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,6 @@
# [Jump Problems](@id jump_problem_type)
# [Jumps, JumpProblem, and Aggregators](@id jump_problem_type)

## Mathematical Specification of a problem with jumps

Jumps (or point) processes are stochastic processes with discrete state changes
driven by a `rate` function. The homogeneous Poisson process is the canonical
point process with a constant rate of change. Processes involving multiple jumps
are known as compound jump (or point) processes.

A compound Poisson process is a continuous-time Markov Chain where the time to
the next jump is exponentially distributed as determined by the rate. Simulation
algorithms for these types of processes are known in biology and chemistry as
Gillespie methods or Stochastic Simulation Algorithms (SSA), with the time
evolution that the probability these processes are in a given state at a given
time satisfying the Chemical Master Equation (CME). In the statistics literature,
the composition of Poisson processes is described by the superposition theorem.

Any differential equation can be extended by jumps. For example, we have an ODE
with jumps, denoted by

```math
\frac{du}{dt} = f(u,p,t) + \sum_{i}c_i(u,p,t)p_i(t)
```

where ``p_i`` is a Poisson counter of rate ``\lambda_i(u,p,t)``. Extending
a stochastic differential equation to have jumps is commonly known as a Jump
Diffusion, and is denoted by

```math
du(t) = f(u,p,t)dt + \sum_{j}g_j(u,t)dW_j(t) + \sum_{i}c_i(u,p,t)dp_i(t)
```

## Types of Jumps: Constant Rate, Mass Action, Variable Rate and Regular
## [Jump Types: Constant Rate, Mass Action, Variable Rate and Regular](@id jump_types)

Exact jump process simulation algorithms tend to describe the realization of
each jump event chronologically. Individual jumps are usually associated with
Expand Down Expand Up @@ -266,7 +236,7 @@ RegularJump(rate, c, numjumps; mark_dist = nothing)
equations and the number of `counts`.
- `mark_dist` is the distribution for a mark.

## Defining a Jump Problem
## [JumpProblem](@id defining_jump_problem)

To define a `JumpProblem`, one must first define the basic problem. This can be
a `DiscreteProblem` if there is no differential equation, or an ODE/SDE/DDE/DAE
Expand Down
Loading

0 comments on commit db55c72

Please sign in to comment.