Skip to content

Commit d286f0d

Browse files
author
SciML Bot
committed
Apply JuliaFormatter to fix code formatting
- Applied JuliaFormatter with SciML style guide - Formatted 136 files 🤖 Generated by OrgMaintenanceScripts.jl
1 parent 8f3c86e commit d286f0d

File tree

136 files changed

+38981
-28154
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

136 files changed

+38981
-28154
lines changed

.JuliaFormatter.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
style = "sciml"
2+
format_markdown = true
3+
format_docstrings = true

LICENSE.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,3 @@ The StochasticDiffEq.jl package is licensed under the MIT "Expat" License:
1919
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2121
> SOFTWARE.
22-
>

README.md

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,77 +18,77 @@ using StochasticDiffEq
1818
α=1
1919
β=1
2020
u₀=1/2
21-
f(u,p,t) = α*u
22-
g(u,p,t) = β*u
21+
f(u, p, t) = α*u
22+
g(u, p, t) = β*u
2323
dt = 1//2^(4)
24-
tspan = (0.0,1.0)
25-
prob = SDEProblem(f,g,u₀,(0.0,1.0))
26-
sol =solve(prob,SRIW1())
24+
tspan = (0.0, 1.0)
25+
prob = SDEProblem(f, g, u₀, (0.0, 1.0))
26+
sol = solve(prob, SRIW1())
2727
```
2828

2929
The options for `solve` are defined in the [common solver options page](https://diffeq.sciml.ai/stable/basics/common_solver_opts/) and are thoroughly explained in [the ODE tutorial](https://diffeq.sciml.ai/stable/tutorials/ode_example/).
3030

3131
That example uses the out-of-place syntax `f(u,p,t)`, while the inplace syntax (more efficient for systems of equations) is shown in the Lorenz example:
3232

3333
```julia
34-
function lorenz(du,u,p,t)
35-
du[1] = 10.0(u[2]-u[1])
36-
du[2] = u[1]*(28.0-u[3]) - u[2]
37-
du[3] = u[1]*u[2] - (8/3)*u[3]
34+
function lorenz(du, u, p, t)
35+
du[1] = 10.0(u[2]-u[1])
36+
du[2] = u[1]*(28.0-u[3]) - u[2]
37+
du[3] = u[1]*u[2] - (8/3)*u[3]
3838
end
3939

40-
function σ_lorenz(du,u,p,t)
41-
du[1] = 3.0
42-
du[2] = 3.0
43-
du[3] = 3.0
40+
function σ_lorenz(du, u, p, t)
41+
du[1] = 3.0
42+
du[2] = 3.0
43+
du[3] = 3.0
4444
end
4545

46-
prob_sde_lorenz = SDEProblem(lorenz,σ_lorenz,[1.0,0.0,0.0],(0.0,10.0))
46+
prob_sde_lorenz = SDEProblem(lorenz, σ_lorenz, [1.0, 0.0, 0.0], (0.0, 10.0))
4747
sol = solve(prob_sde_lorenz)
48-
plot(sol,vars=(1,2,3))
48+
plot(sol, vars = (1, 2, 3))
4949
```
5050

5151
The problems default to diagonal noise. Non-diagonal noise can be added by setting
5252
the `noise_prototype`:
5353

5454
```julia
55-
f = (du,u,p,t) -> du.=1.01u
56-
g = function (du,u,p,t)
57-
du[1,1] = 0.3u[1]
58-
du[1,2] = 0.6u[1]
59-
du[1,3] = 0.9u[1]
60-
du[1,4] = 0.12u[2]
61-
du[2,1] = 1.2u[1]
62-
du[2,2] = 0.2u[2]
63-
du[2,3] = 0.3u[2]
64-
du[2,4] = 1.8u[2]
55+
f = (du, u, p, t) -> du.=1.01u
56+
g = function (du, u, p, t)
57+
du[1, 1] = 0.3u[1]
58+
du[1, 2] = 0.6u[1]
59+
du[1, 3] = 0.9u[1]
60+
du[1, 4] = 0.12u[2]
61+
du[2, 1] = 1.2u[1]
62+
du[2, 2] = 0.2u[2]
63+
du[2, 3] = 0.3u[2]
64+
du[2, 4] = 1.8u[2]
6565
end
66-
prob = SDEProblem(f,g,ones(2),(0.0,1.0),noise_rate_prototype=zeros(2,4))
66+
prob = SDEProblem(f, g, ones(2), (0.0, 1.0), noise_rate_prototype = zeros(2, 4))
6767
```
6868

6969
Colored noise can be set using [an `AbstractNoiseProcess`](https://diffeq.sciml.ai/stable/features/noise_process/). For example, we can set the underlying noise process to a `GeometricBrownianMotionProcess` via:
7070

7171
```julia
7272
μ = 1.0
7373
σ = 2.0
74-
W = GeometricBrownianMotionProcess(μ,σ,0.0,1.0,1.0)
74+
W = GeometricBrownianMotionProcess(μ, σ, 0.0, 1.0, 1.0)
7575
# ...
7676
# Define f,g,u0,tspan for a SDEProblem
7777
# ...
78-
prob = SDEProblem(f,g,u0,tspan,noise=W)
78+
prob = SDEProblem(f, g, u0, tspan, noise = W)
7979
```
8080

8181
StochasticDiffEq.jl also handles solving random ordinary differential equations. This is shown [in the RODE tutorial](https://diffeq.sciml.ai/stable/tutorials/rode_example/).
8282

8383
```julia
8484
using StochasticDiffEq
85-
function f(u,p,t,W)
86-
2u*sin(W)
85+
function f(u, p, t, W)
86+
2u*sin(W)
8787
end
8888
u0 = 1.00
89-
tspan = (0.0,5.0)
90-
prob = RODEProblem(f,u0,tspan)
91-
sol = solve(prob,RandomEM(),dt=1/100)
89+
tspan = (0.0, 5.0)
90+
prob = RODEProblem(f, u0, tspan)
91+
sol = solve(prob, RandomEM(), dt = 1/100)
9292
```
9393

9494
## Available Solvers

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ makedocs(sitename = "StochasticDiffEq.jl",
1919
pages = pages)
2020

2121
deploydocs(repo = "github.com/SciML/StochasticDiffEq.jl";
22-
push_preview = true)
22+
push_preview = true)

docs/pages.jl

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
pages = [
2-
"StochasticDiffEq.jl: SDE solvers and utilities" => "index.md",
3-
"Usage" => "usage.md",
4-
"Nonstiff Solvers" => [
5-
"nonstiff/basic_methods.md",
6-
"nonstiff/sra_sri_methods.md",
7-
"nonstiff/high_weak_order.md",
8-
"nonstiff/commutative_noise.md"
9-
],
10-
"Stiff Solvers" => [
11-
"stiff/implicit_methods.md",
12-
"stiff/split_step_methods.md",
13-
"stiff/stabilized_methods.md"
14-
],
15-
"Jump Diffusion" => [
16-
"jumpdiffusion/tau_leaping.md"
17-
],
18-
"Misc Solvers" => [
19-
"misc.md"
20-
]
21-
]
2+
"StochasticDiffEq.jl: SDE solvers and utilities" => "index.md",
3+
"Usage" => "usage.md",
4+
"Nonstiff Solvers" => [
5+
"nonstiff/basic_methods.md",
6+
"nonstiff/sra_sri_methods.md",
7+
"nonstiff/high_weak_order.md",
8+
"nonstiff/commutative_noise.md"
9+
],
10+
"Stiff Solvers" => [
11+
"stiff/implicit_methods.md",
12+
"stiff/split_step_methods.md",
13+
"stiff/stabilized_methods.md"
14+
],
15+
"Jump Diffusion" => [
16+
"jumpdiffusion/tau_leaping.md"
17+
],
18+
"Misc Solvers" => [
19+
"misc.md"
20+
]
21+
]

docs/src/index.md

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,36 +43,39 @@ sol = solve(prob)
4343
StochasticDiffEq.jl provides several categories of solvers optimized for different types of problems:
4444

4545
### Nonstiff Solvers
46-
- **Basic Methods**: Euler-Maruyama, Heun methods
47-
- **SRA/SRI Methods**: High-order adaptive methods (SOSRI, SOSRA)
48-
- **High Weak Order**: Methods optimized for weak convergence (DRI1)
49-
- **Commutative Noise**: Specialized methods for commuting noise terms
5046

51-
### Stiff Solvers
52-
- **Implicit Methods**: Drift-implicit methods for stiff problems
53-
- **Split-Step Methods**: Methods handling stiffness in diffusion
54-
- **Stabilized Methods**: SROCK-type methods for parabolic PDEs
47+
- **Basic Methods**: Euler-Maruyama, Heun methods
48+
- **SRA/SRI Methods**: High-order adaptive methods (SOSRI, SOSRA)
49+
- **High Weak Order**: Methods optimized for weak convergence (DRI1)
50+
- **Commutative Noise**: Specialized methods for commuting noise terms
51+
52+
### Stiff Solvers
53+
54+
- **Implicit Methods**: Drift-implicit methods for stiff problems
55+
- **Split-Step Methods**: Methods handling stiffness in diffusion
56+
- **Stabilized Methods**: SROCK-type methods for parabolic PDEs
5557

5658
### Jump-Diffusion
57-
- **Tau-Leaping**: Methods for jump-diffusion processes
59+
60+
- **Tau-Leaping**: Methods for jump-diffusion processes
5861

5962
## Recommended Methods
6063

6164
For most users, we recommend starting with these methods:
6265

63-
- **General Purpose**: `SOSRI()` - Excellent for diagonal/scalar Itô SDEs
64-
- **Additive Noise**: `SOSRA()` - Optimal for problems with additive noise
65-
- **Stiff Problems**: `SKenCarp()` - Best for stiff problems with additive noise
66-
- **Commutative Noise**: `RKMilCommute()` - For multi-dimensional commutative noise
67-
- **High Efficiency**: `EM()` - When computational speed is most important
66+
- **General Purpose**: `SOSRI()` - Excellent for diagonal/scalar Itô SDEs
67+
- **Additive Noise**: `SOSRA()` - Optimal for problems with additive noise
68+
- **Stiff Problems**: `SKenCarp()` - Best for stiff problems with additive noise
69+
- **Commutative Noise**: `RKMilCommute()` - For multi-dimensional commutative noise
70+
- **High Efficiency**: `EM()` - When computational speed is most important
6871

6972
## Advanced Features
7073

71-
- Adaptive time stepping with sophisticated error control
72-
- Support for all noise types (diagonal, non-diagonal, additive, scalar)
73-
- Both Itô and Stratonovich interpretations
74-
- Integration with the broader DifferentialEquations.jl ecosystem
75-
- GPU compatibility for high-performance computing
76-
- Extensive callback and event handling capabilities
74+
- Adaptive time stepping with sophisticated error control
75+
- Support for all noise types (diagonal, non-diagonal, additive, scalar)
76+
- Both Itô and Stratonovich interpretations
77+
- Integration with the broader DifferentialEquations.jl ecosystem
78+
- GPU compatibility for high-performance computing
79+
- Extensive callback and event handling capabilities
7780

78-
See the individual solver pages for detailed information about each method's properties, when to use them, and their theoretical foundations.
81+
See the individual solver pages for detailed information about each method's properties, when to use them, and their theoretical foundations.

docs/src/jumpdiffusion/tau_leaping.md

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,97 +5,109 @@ Tau-leaping methods approximate jump processes by "leaping" over multiple potent
55
## Tau-Leaping Methods
66

77
### TauLeaping - Basic Tau-Leaping
8+
89
```@docs
910
TauLeaping
1011
```
1112

12-
### CaoTauLeaping - Cao's Tau-Leaping
13+
### CaoTauLeaping - Cao's Tau-Leaping
14+
1315
```@docs
1416
CaoTauLeaping
1517
```
1618

1719
## Understanding Jump-Diffusion Processes
1820

1921
Jump-diffusion processes combine:
20-
1. **Continuous diffusion**: Standard Brownian motion terms
21-
2. **Jump processes**: Discontinuous jumps at random times
22+
23+
1. **Continuous diffusion**: Standard Brownian motion terms
24+
2. **Jump processes**: Discontinuous jumps at random times
2225

2326
General form:
27+
2428
```
2529
dX = μ(X,t)dt + σ(X,t)dW + ∫ h(X-,z)Ñ(dt,dz)
2630
```
2731

2832
Where:
29-
- μ(X,t)dt: Drift term
30-
- σ(X,t)dW: Diffusion term
31-
- Ñ(dt,dz): Compensated random measure (jumps)
33+
34+
- μ(X,t)dt: Drift term
35+
- σ(X,t)dW: Diffusion term
36+
- Ñ(dt,dz): Compensated random measure (jumps)
3237

3338
## When to Use Tau-Leaping
3439

3540
**Appropriate for:**
36-
- Systems with many small jumps
37-
- When exact jump simulation is computationally prohibitive
38-
- Chemical reaction networks
39-
- Population models with birth-death processes
40-
- Financial models with rare events
41+
42+
- Systems with many small jumps
43+
- When exact jump simulation is computationally prohibitive
44+
- Chemical reaction networks
45+
- Population models with birth-death processes
46+
- Financial models with rare events
4147

4248
**Not appropriate for:**
43-
- Systems dominated by large, infrequent jumps
44-
- When exact jump timing is critical
45-
- Small systems where exact methods are feasible
49+
50+
- Systems dominated by large, infrequent jumps
51+
- When exact jump timing is critical
52+
- Small systems where exact methods are feasible
4653

4754
## Method Characteristics
4855

4956
### TauLeaping:
50-
- Basic tau-leaping approximation
51-
- Fixed tau approach
52-
- Good for initial exploration
57+
58+
- Basic tau-leaping approximation
59+
- Fixed tau approach
60+
- Good for initial exploration
5361

5462
### CaoTauLeaping:
55-
- Adaptive tau selection
56-
- More sophisticated error control
57-
- Better for production simulations
63+
64+
- Adaptive tau selection
65+
- More sophisticated error control
66+
- Better for production simulations
5867

5968
## Configuration
6069

6170
Tau-leaping methods require:
62-
1. **Jump rate functions**: λ(X,t) for each reaction/jump type
63-
2. **Jump effects**: How state changes with each jump
64-
3. **Tau selection**: Time step size strategy
71+
72+
1. **Jump rate functions**: λ(X,t) for each reaction/jump type
73+
2. **Jump effects**: How state changes with each jump
74+
3. **Tau selection**: Time step size strategy
6575

6676
```julia
6777
# Basic setup
6878
prob = JumpProblem(base_problem, aggregator, jumps...)
6979
sol = solve(prob, TauLeaping())
7080

7181
# With adaptive tau
72-
sol = solve(prob, CaoTauLeaping(), tau_tol=0.01)
82+
sol = solve(prob, CaoTauLeaping(), tau_tol = 0.01)
7383
```
7484

7585
## Accuracy Considerations
7686

7787
**Tau-leaping approximation quality depends on:**
78-
- Jump frequency vs. tau size
79-
- State change magnitude per jump
80-
- System stiffness
81-
- Error tolerance requirements
88+
89+
- Jump frequency vs. tau size
90+
- State change magnitude per jump
91+
- System stiffness
92+
- Error tolerance requirements
8293

8394
**Rule of thumb:** Tau should be small enough that jump rates don't change significantly over [t, t+tau].
8495

8596
## Alternative Approaches
8697

8798
**If tau-leaping is inadequate:**
88-
1. **Exact methods**: Gillespie algorithm for small systems
89-
2. **Hybrid methods**: Combine exact and approximate regions
90-
3. **Moment closure**: For statistical properties only
91-
4. **Piecewise deterministic**: For systems with rare jumps
99+
100+
1. **Exact methods**: Gillespie algorithm for small systems
101+
2. **Hybrid methods**: Combine exact and approximate regions
102+
3. **Moment closure**: For statistical properties only
103+
4. **Piecewise deterministic**: For systems with rare jumps
92104

93105
## Performance Tips
94106

95-
1. **Vectorize jump computations** when possible
96-
2. **Use sparse representations** for large systems
97-
3. **Tune tau carefully** - too large gives poor accuracy, too small is inefficient
98-
4. **Monitor jump frequencies** to validate approximation
107+
1. **Vectorize jump computations** when possible
108+
2. **Use sparse representations** for large systems
109+
3. **Tune tau carefully** - too large gives poor accuracy, too small is inefficient
110+
4. **Monitor jump frequencies** to validate approximation
99111

100112
## Integration with DifferentialEquations.jl
101113

@@ -107,7 +119,7 @@ function drift!(du, u, p, t)
107119
# Continuous drift
108120
end
109121

110-
function diffusion!(du, u, p, t)
122+
function diffusion!(du, u, p, t)
111123
# Continuous diffusion
112124
end
113125

@@ -124,5 +136,6 @@ sol = solve(jump_prob, TauLeaping())
124136
```
125137

126138
## References
127-
- Gillespie, D.T., "Approximate accelerated stochastic simulation of chemically reacting systems"
128-
- Cao, Y., Gillespie, D.T., Petzold, L.R., "Efficient step size selection for the tau-leaping method"
139+
140+
- Gillespie, D.T., "Approximate accelerated stochastic simulation of chemically reacting systems"
141+
- Cao, Y., Gillespie, D.T., Petzold, L.R., "Efficient step size selection for the tau-leaping method"

0 commit comments

Comments
 (0)