Skip to content

Commit 6a34814

Browse files
committed
change names, delete path convergence test
1 parent 9dd8a96 commit 6a34814

File tree

5 files changed

+111
-136
lines changed

5 files changed

+111
-136
lines changed

src/algorithms.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ RKMilCommute: Nonstiff Method
9191
An explicit Runge-Kutta discretization of the strong order 1.0 Milstein method for commutative noise problems.
9292
Defaults to solving the Ito problem, but RKMilCommute(interpretation=:Stratonovich) makes it solve the Stratonovich problem.
9393
Uses a 1.5/2.0 error estimate for adaptive time stepping.
94+
Default: ii_approx=IICommutative() does not approximate the Levy area.
9495
"""
9596
struct RKMilCommute{T} <: StochasticDiffEqAdaptiveAlgorithm
9697
interpretation::Symbol
@@ -107,6 +108,9 @@ RKMilGeneral(;interpretation=:Ito, ii_approx=IILevyArea()
107108
An explicit Runge-Kutta discretization of the strong order 1.0 Milstein method for general non-commutative noise problems.
108109
Allows for a choice of interpretation between :Ito and :Stratonovich.
109110
Allows for a choice of iterated integral approximation.
111+
Default: ii_approx=IILevyArea() uses LevyArea.jl to choose optimal algorithm. See
112+
Kastner, F. and Rößler, A., arXiv: 2201.08424
113+
Kastner, F. and Rößler, A., LevyArea.jl, 10.5281/ZENODO.5883748, https://github.com/stochastics-uni-luebeck/LevyArea.jl
110114
"""
111115
struct RKMilGeneral{T, TruncationType} <: StochasticDiffEqAdaptiveAlgorithm
112116
interpretation::Symbol

src/caches/basic_method_caches.jl

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -115,44 +115,44 @@ function alg_cache(alg::RKMil,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototy
115115
RKMilCache(u,uprev,du1,du2,K,tmp,L)
116116
end
117117

118-
struct RKMilCommuteConstantCache{WikType} <: StochasticDiffEqConstantCache
119-
WikJ::WikType
118+
struct RKMilCommuteConstantCache{JalgType} <: StochasticDiffEqConstantCache
119+
Jalg::JalgType
120120
end
121-
@cache struct RKMilCommuteCache{uType,rateType,rateNoiseType,WikType} <: StochasticDiffEqMutableCache
121+
@cache struct RKMilCommuteCache{uType,rateType,rateNoiseType,JalgType} <: StochasticDiffEqMutableCache
122122
u::uType
123123
uprev::uType
124124
du1::rateType
125125
du2::rateType
126126
K::rateType
127127
gtmp::rateNoiseType
128128
L::rateNoiseType
129-
WikJ::WikType
129+
Jalg::JalgType
130130
mil_correction::rateType
131131
Kj::uType
132132
Dgj::rateNoiseType
133133
tmp::uType
134134
end
135135

136136
function alg_cache(alg::RKMilCommute,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
137-
WikJ = get_WikJ(ΔW,dt,prob,alg)
138-
RKMilCommuteConstantCache{typeof(WikJ)}(WikJ)
137+
Jalg = get_Jalg(ΔW,dt,prob,alg)
138+
RKMilCommuteConstantCache{typeof(Jalg)}(Jalg)
139139
end
140140

141141
function alg_cache(alg::RKMilCommute,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{true}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
142142
du1 = zero(rate_prototype); du2 = zero(rate_prototype)
143143
K = zero(rate_prototype); gtmp = zero(noise_rate_prototype);
144144
L = zero(noise_rate_prototype); tmp = zero(rate_prototype)
145-
WikJ = get_WikJ(ΔW,dt,prob,alg)
145+
Jalg = get_Jalg(ΔW,dt,prob,alg)
146146
mil_correction = zero(rate_prototype)
147147
Kj = zero(u); Dgj = zero(noise_rate_prototype)
148-
RKMilCommuteCache(u,uprev,du1,du2,K,gtmp,L,WikJ,mil_correction,Kj,Dgj,tmp)
148+
RKMilCommuteCache(u,uprev,du1,du2,K,gtmp,L,Jalg,mil_correction,Kj,Dgj,tmp)
149149
end
150150

151-
struct RKMilGeneralConstantCache{WikType} <: StochasticDiffEqConstantCache
152-
WikJ::WikType
151+
struct RKMilGeneralConstantCache{JalgType} <: StochasticDiffEqConstantCache
152+
Jalg::JalgType
153153
end
154154

155-
@cache struct RKMilGeneralCache{uType, rateType, rateNoiseType, WikType} <: StochasticDiffEqMutableCache
155+
@cache struct RKMilGeneralCache{uType, rateType, rateNoiseType, JalgType} <: StochasticDiffEqMutableCache
156156
u::uType
157157
uprev::uType
158158
tmp::uType
@@ -162,12 +162,12 @@ end
162162
L::rateNoiseType
163163
mil_correction::uType
164164
ggprime::rateNoiseType
165-
WikJ::WikType
165+
Jalg::JalgType
166166
end
167167

168-
function alg_cache(alg::RKMilGeneral,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
169-
WikJ = get_WikJ(ΔW,dt,prob,alg)
170-
RKMilGeneralConstantCache{typeof(WikJ)}(WikJ)
168+
function alg_cache(alg::RKMilGeneral, prob, u, ΔW, ΔZ, p, rate_prototype, noise_rate_prototype, jump_rate_prototype, ::Type{uEltypeNoUnits}, ::Type{uBottomEltypeNoUnits}, ::Type{tTypeNoUnits}, uprev, f, t, dt, ::Type{Val{false}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
169+
Jalg = get_Jalg(ΔW, dt, prob, alg)
170+
RKMilGeneralConstantCache{typeof(Jalg)}(Jalg)
171171
end
172172

173173
function alg_cache(alg::RKMilGeneral,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_prototype,jump_rate_prototype,::Type{uEltypeNoUnits},::Type{uBottomEltypeNoUnits},::Type{tTypeNoUnits},uprev,f,t,dt,::Type{Val{true}}) where {uEltypeNoUnits,uBottomEltypeNoUnits,tTypeNoUnits}
@@ -178,6 +178,6 @@ function alg_cache(alg::RKMilGeneral,prob,u,ΔW,ΔZ,p,rate_prototype,noise_rate_
178178
L = zero(noise_rate_prototype)
179179
mil_correction = zero(u)
180180
ggprime = zero(noise_rate_prototype)
181-
WikJ = get_WikJ(ΔW,dt,prob,alg)
182-
RKMilGeneralCache{typeof(u), typeof(rate_prototype), typeof(noise_rate_prototype), typeof(WikJ)}(u, uprev, tmp, du₁, du₂, K, L, mil_correction, ggprime, WikJ)
181+
Jalg = get_Jalg(ΔW,dt,prob,alg)
182+
RKMilGeneralCache{typeof(u), typeof(rate_prototype), typeof(noise_rate_prototype), typeof(Jalg)}(u, uprev, tmp, du₁, du₂, K, L, mil_correction, ggprime, Jalg)
183183
end

src/iterated_integrals.jl

Lines changed: 46 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,50 @@ by the J.
55

66
abstract type AbstractJ end
77

8-
# Wiktorssson Approximation (for diagonal and commutative noise processes where the Levy area approximation is not required.)
8+
# Iterated stochastic integral (for diagonal and commutative noise processes where the Levy area approximation is not required.)
9+
abstract type AbstractJDiagonal <: AbstractJ end
10+
abstract type AbstractJCommute <: AbstractJ end
911

10-
abstract type AbstractWikJ <: AbstractJ end
11-
abstract type AbstractWikJDiagonal <: AbstractWikJ end
12-
abstract type AbstractWikJCommute <: AbstractWikJ end
12+
struct JDiagonal_oop <: AbstractJDiagonal end
1313

14-
struct WikJDiagonal_oop <: AbstractWikJDiagonal end
15-
16-
mutable struct WikJDiagonal_iip{WikJType} <: AbstractWikJDiagonal
17-
WikJ::WikJType
18-
WikJDiagonal_iip(ΔW) = new{typeof(ΔW)}(false .* ΔW .* ΔW)
14+
mutable struct JDiagonal_iip{JType} <: AbstractJDiagonal
15+
J::JType
16+
JDiagonal_iip(ΔW) = new{typeof(ΔW)}(false .* ΔW .* ΔW)
1917
end
2018

21-
struct WikJCommute_oop <: AbstractWikJCommute end
19+
struct JCommute_oop <: AbstractJCommute end
2220

23-
mutable struct WikJCommute_iip{WikJType} <: AbstractWikJCommute
24-
WikJ::WikJType
25-
function WikJCommute_iip(ΔW)
26-
WikJ = false .* vec(ΔW) .* vec(ΔW)'
27-
new{typeof(WikJ)}(WikJ)
21+
mutable struct JCommute_iip{JType} <: AbstractJCommute
22+
J::JType
23+
function JCommute_iip(ΔW)
24+
J = false .* vec(ΔW) .* vec(ΔW)'
25+
new{typeof(J)}(J)
2826
end
2927
end
3028

31-
function get_iterated_I(dt, dW, dZ, Wik::WikJDiagonal_oop, p=nothing, C=1, γ=1//1)
32-
WikJ = 1//2 .* dW .* dW
33-
WikJ
29+
function get_iterated_I(dt, dW, dZ, alg::JDiagonal_oop, p=nothing, c=1, γ=1//1)
30+
1//2 .* dW .* dW
3431
end
3532

36-
function get_iterated_I!(dt, dW, dZ, Wik::WikJDiagonal_iip, p=nothing, C=1, γ=1//1)
37-
@unpack WikJ = Wik
33+
function get_iterated_I!(dt, dW, dZ, alg::JDiagonal_iip, p=nothing, c=1, γ=1//1)
34+
@unpack J = alg
3835
if typeof(dW) <: Number
39-
Wik.WikJ = 1//2 .* dW .^ 2
36+
alg.J = 1//2 .* dW .^ 2
4037
else
41-
@.. WikJ = 1//2 * dW^2
38+
@.. J = 1//2 * dW^2
4239
end
4340
return nothing
4441
end
4542

46-
function get_iterated_I(dt, dW, dZ, Wik::WikJCommute_oop, p=nothing, C=1, γ=1//1)
47-
WikJ = 1//2 .* vec(dW) .* vec(dW)'
48-
WikJ
43+
function get_iterated_I(dt, dW, dZ, alg::JCommute_oop, p=nothing, c=1, γ=1//1)
44+
J = 1//2 .* vec(dW) .* vec(dW)'
45+
J
4946
end
5047

51-
function get_iterated_I!(dt, dW, dZ, Wik::WikJCommute_iip, p=nothing, C=1, γ=1//1)
52-
@unpack WikJ = Wik
53-
mul!(WikJ, vec(dW), vec(dW)')
54-
@.. WikJ *= 1//2
48+
function get_iterated_I!(dt, dW, dZ, alg::JCommute_iip, p=nothing, c=1, γ=1//1)
49+
@unpack J = alg
50+
mul!(J, vec(dW), vec(dW)')
51+
@.. J *= 1//2
5552
return nothing
5653
end
5754

@@ -62,59 +59,59 @@ function get_iterated_I(dt, dW, dZ, alg::LevyArea.AbstractIteratedIntegralAlgori
6259
ε = c * dt^+ 1//2)
6360
p = terms_needed(length(dW), dt, ε, alg, MaxL2())
6461
end
65-
I = LevyArea.levyarea(dW/dt, p, alg)
62+
I = LevyArea.levyarea(dW / dt, p, alg)
6663
I .= 1//2 * dW .* dW' .+ dt .* I
6764
end
6865

69-
mutable struct IteratedIntegralAlgorithm_iip{WikJType,algType} <: LevyArea.AbstractIteratedIntegralAlgorithm
70-
WikJ::WikJType
71-
alg::algType
72-
function IteratedIntegralAlgorithm_iip(ΔW, alg)
73-
WikJ = false .* vec(ΔW) .* vec(ΔW)'
74-
new{typeof(WikJ),typeof(alg)}(WikJ, alg)
66+
mutable struct IteratedIntegralAlgorithm_iip{JType,levyalgType} <: LevyArea.AbstractIteratedIntegralAlgorithm
67+
J::JType
68+
levyalg::levyalgType
69+
function IteratedIntegralAlgorithm_iip(ΔW, levyalg)
70+
J = false .* vec(ΔW) .* vec(ΔW)'
71+
new{typeof(J),typeof(levyalg)}(J, levyalg)
7572
end
7673
end
7774

78-
function get_iterated_I!(dt, dW, dZ, Wik::IteratedIntegralAlgorithm_iip, p=nothing, c=1, γ=1//1)
79-
@unpack WikJ, alg = Wik
75+
function get_iterated_I!(dt, dW, dZ, alg::IteratedIntegralAlgorithm_iip, p=nothing, c=1, γ=1//1)
76+
@unpack J, levyalg = alg
8077
if isnothing(p)
8178
ε = c * dt^+ 1//2)
82-
p = terms_needed(length(dW), dt, ε, alg, MaxL2())
79+
p = terms_needed(length(dW), dt, ε, levyalg, MaxL2())
8380
end
84-
WikJ .= LevyArea.levyarea(dW/dt, p, alg)
85-
WikJ .= 1//2 * dW .* dW' .+ dt .* WikJ
81+
J .= LevyArea.levyarea(dW / dt, p, levyalg)
82+
J .= 1//2 * dW .* dW' .+ dt .* J
8683
return nothing
8784
end
8885

8986
# Default algorithms, keep KPWJ_oop() to have a non-mutating version
90-
function get_WikJ(ΔW, dt, prob, alg)
87+
function get_Jalg(ΔW, dt, prob, alg)
9188
if alg.ii_approx isa IILevyArea
9289
if isinplace(prob)
9390
if typeof(ΔW) <: Number || is_diagonal_noise(prob)
94-
return WikJDiagonal_iip(ΔW)
91+
return JDiagonal_iip(ΔW)
9592
else
9693
# optimal_algorithm(dim, stepsize, eps=stepsize^(3/2), norm=MaxL2())
9794
return IteratedIntegralAlgorithm_iip(ΔW, LevyArea.optimal_algorithm(length(ΔW), dt))
9895
end
9996
else
10097
if typeof(ΔW) <: Number || is_diagonal_noise(prob)
101-
return WikJDiagonal_oop()
98+
return JDiagonal_oop()
10299
else
103100
return LevyArea.optimal_algorithm(length(ΔW), dt)
104101
end
105102
end
106103
elseif alg.ii_approx isa IICommutative
107104
if isinplace(prob)
108105
if typeof(ΔW) <: Number || is_diagonal_noise(prob)
109-
return WikJDiagonal_iip(ΔW)
106+
return JDiagonal_iip(ΔW)
110107
else
111-
return WikJCommute_iip(ΔW)
108+
return JCommute_iip(ΔW)
112109
end
113110
else
114111
if typeof(ΔW) <: Number || is_diagonal_noise(prob)
115-
return WikJDiagonal_oop()
112+
return JDiagonal_oop()
116113
else
117-
return WikJCommute_oop()
114+
return JCommute_oop()
118115
end
119116
end
120117
else
@@ -123,6 +120,6 @@ function get_WikJ(ΔW, dt, prob, alg)
123120
end
124121

125122
# Specific Levy area alg for an SDE solver
126-
# function StochasticDiffEq.get_WikJ(ΔW,prob,alg::SOLVER)
123+
# function StochasticDiffEq.get_Jalg(ΔW,prob,alg::SOLVER)
127124
# return MronRoe()
128125
# end

0 commit comments

Comments
 (0)