|
| 1 | +abstract type StochasticDynamicalEqConstantCache <: StochasticDiffEqConstantCache end # Pourquoi faire ça, Si c'est pour avoir une seul function de check dans initialize! |
| 2 | +abstract type StochasticDynamicalEqMutableCache <: StochasticDiffEqMutableCache end |
1 | 3 |
|
2 |
| -mutable struct BAOABConstantCache{uType,uEltypeNoUnits} <: StochasticDiffEqConstantCache |
| 4 | + |
| 5 | +mutable struct BAOABConstantCache{uType,uEltypeNoUnits,uCoeffType} <: StochasticDynamicalEqConstantCache |
3 | 6 | k::uType
|
4 | 7 | half::uEltypeNoUnits
|
5 |
| - c1::uEltypeNoUnits |
6 |
| - c2::uEltypeNoUnits |
| 8 | + c1::uCoeffType |
| 9 | + c2::uCoeffType |
7 | 10 | end
|
8 |
| -@cache struct BAOABCache{uType,uEltypeNoUnits,rateNoiseType,uTypeCombined} <: StochasticDiffEqMutableCache |
| 11 | +@cache struct BAOABCache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType,uTypeCombined} <: StochasticDynamicalEqMutableCache |
9 | 12 | utmp::uType
|
10 | 13 | dutmp::uType
|
11 | 14 | k::uType
|
12 |
| - gtmp::uType |
13 |
| - noise::rateNoiseType |
| 15 | + gtmp::rateNoiseType |
| 16 | + noise::uType |
14 | 17 | half::uEltypeNoUnits
|
15 |
| - c1::uEltypeNoUnits |
16 |
| - c2::uEltypeNoUnits |
| 18 | + c1::uCoeffType |
| 19 | + c2::uCoeffType |
17 | 20 | tmp::uTypeCombined
|
18 | 21 | end
|
19 | 22 |
|
20 | 23 | function alg_cache(alg::BAOAB,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}
|
21 | 24 | k = zero(rate_prototype.x[1])
|
22 |
| - c1 = exp(-alg.gamma*dt) |
23 |
| - c2 = sqrt(1 - alg.scale_noise*c1^2) # if scale_noise == false, c2 = 1 |
24 |
| - BAOABConstantCache(k, uEltypeNoUnits(1//2), uEltypeNoUnits(c1), uEltypeNoUnits(c2)) |
| 25 | + if typeof(alg.gamma) <: Number |
| 26 | + c1 = exp.(-alg.gamma*dt) |
| 27 | + c2 = sqrt.(1 .- alg.scale_noise*c1.^2)# if scale_noise == false, c2 = 1 |
| 28 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 29 | + c1 = exp(-alg.gamma*dt) |
| 30 | + c2 = cholesky(I - alg.scale_noise*c1*transpose(c1)).U# if scale_noise == false, c2 = 1 |
| 31 | + else |
| 32 | + c1 = exp.(-alg.gamma*dt) |
| 33 | + c2 = sqrt.(1 .- alg.scale_noise*c1.^2)# if scale_noise == false, c2 = 1 |
| 34 | + end |
| 35 | + BAOABConstantCache(k, uEltypeNoUnits(1//2),c1, c2) |
25 | 36 | end
|
26 | 37 |
|
27 | 38 | function alg_cache(alg::BAOAB,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}
|
28 | 39 | dutmp = zero(u.x[1])
|
29 | 40 | utmp = zero(u.x[2])
|
30 | 41 | k = zero(rate_prototype.x[1])
|
31 | 42 |
|
32 |
| - gtmp = zero(rate_prototype.x[1]) |
| 43 | + gtmp = zero(noise_rate_prototype) |
| 44 | + noise = zero(rate_prototype.x[1]) |
| 45 | + |
| 46 | + half = uEltypeNoUnits(1//2) |
| 47 | + if typeof(alg.gamma) <: Number |
| 48 | + c1 = exp.(-alg.gamma*dt) |
| 49 | + c2 = sqrt.(1 .- alg.scale_noise*c1.^2)# if scale_noise == false, c2 = 1 |
| 50 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 51 | + c1 = exp(-alg.gamma*dt) |
| 52 | + c2 = cholesky(I - alg.scale_noise*c1*transpose(c1)).U# if scale_noise == false, c2 = 1 |
| 53 | + else |
| 54 | + c1 = exp.(-alg.gamma*dt) |
| 55 | + c2 = sqrt.(1 .- alg.scale_noise*c1.^2)# if scale_noise == false, c2 = 1 |
| 56 | + end |
| 57 | + |
| 58 | + tmp = zero(u) |
| 59 | + |
| 60 | + BAOABCache(utmp, dutmp, k, gtmp, noise, half, c1, c2, tmp) |
| 61 | +end |
| 62 | + |
| 63 | + |
| 64 | + |
| 65 | +mutable struct ABOBAConstantCache{uType,uEltypeNoUnits, uCoeffType} <: StochasticDynamicalEqConstantCache |
| 66 | + k::uType |
| 67 | + half::uEltypeNoUnits |
| 68 | + c₂::uCoeffType |
| 69 | + σ::uCoeffType |
| 70 | +end |
| 71 | +@cache struct ABOBACache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType,uTypeCombined} <: StochasticDynamicalEqMutableCache |
| 72 | + utmp::uType |
| 73 | + dutmp::uType |
| 74 | + k::uType |
| 75 | + gtmp::rateNoiseType |
| 76 | + noise::uType |
| 77 | + half::uEltypeNoUnits |
| 78 | + c₂::uCoeffType |
| 79 | + σ::uCoeffType |
| 80 | + tmp::uTypeCombined |
| 81 | +end |
| 82 | + |
| 83 | +function alg_cache(alg::ABOBA,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} |
| 84 | + k = zero(rate_prototype.x[1]) |
| 85 | + |
| 86 | + if typeof(alg.gamma) <: Number |
| 87 | + c₂ = exp.(-alg.gamma*dt) |
| 88 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 89 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 90 | + c₂ = exp(-alg.gamma*dt) |
| 91 | + σ = cholesky(I - alg.scale_noise*c₂*transpose(c₂)).U |
| 92 | + else |
| 93 | + c₂ = exp.(-alg.gamma*dt) |
| 94 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 95 | + end |
| 96 | + # if scale_noise == false, c2 = 1 |
| 97 | + ABOBAConstantCache(k, uEltypeNoUnits(1//2), c₂, σ) |
| 98 | +end |
| 99 | + |
| 100 | +function alg_cache(alg::ABOBA,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} |
| 101 | + dutmp = zero(u.x[1]) |
| 102 | + utmp = zero(u.x[2]) |
| 103 | + k = zero(rate_prototype.x[1]) |
| 104 | + |
| 105 | + gtmp = zero(noise_rate_prototype) |
| 106 | + noise = zero(rate_prototype.x[1]) |
| 107 | + |
| 108 | + half = uEltypeNoUnits(1//2) |
| 109 | + |
| 110 | + if typeof(alg.gamma) <: Number |
| 111 | + c₂ = exp.(-alg.gamma*dt) |
| 112 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 113 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 114 | + c₂ = exp(-alg.gamma*dt) |
| 115 | + σ = cholesky(I - alg.scale_noise*c₂*transpose(c₂)).U |
| 116 | + else |
| 117 | + c₂ = exp.(-alg.gamma*dt) |
| 118 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 119 | + end |
| 120 | + |
| 121 | + tmp = zero(u) |
| 122 | + |
| 123 | + ABOBACache(utmp, dutmp, k, gtmp, noise, half, c₂, σ, tmp) |
| 124 | +end |
| 125 | + |
| 126 | + |
| 127 | + |
| 128 | + |
| 129 | +mutable struct OBABOConstantCache{uType,uEltypeNoUnits, uCoeffType} <: StochasticDynamicalEqConstantCache |
| 130 | + k::uType |
| 131 | + half::uEltypeNoUnits |
| 132 | + c₂::uCoeffType |
| 133 | + σ::uCoeffType |
| 134 | +end |
| 135 | +@cache struct OBABOCache{uType,uEltypeNoUnits,rateNoiseType,uCoeffType,uTypeCombined} <: StochasticDynamicalEqMutableCache |
| 136 | + utmp::uType |
| 137 | + dutmp::uType |
| 138 | + k::uType |
| 139 | + gtmp::rateNoiseType |
| 140 | + noise::uType |
| 141 | + noisetmp::uType |
| 142 | + half::uEltypeNoUnits |
| 143 | + c₂::uCoeffType |
| 144 | + σ::uCoeffType |
| 145 | + tmp::uTypeCombined |
| 146 | +end |
| 147 | + |
| 148 | +function alg_cache(alg::OBABO,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} |
| 149 | + k = zero(rate_prototype.x[1]) |
| 150 | + half=uEltypeNoUnits(1//2) |
| 151 | + if typeof(alg.gamma) <: Number |
| 152 | + c₂ = exp.(-alg.gamma*half*dt) |
| 153 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 154 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 155 | + c₂ = exp(-alg.gamma*half*dt) |
| 156 | + σ = cholesky(I - alg.scale_noise*c₂*transpose(c₂)).U |
| 157 | + else |
| 158 | + c₂ = exp.(-alg.gamma*half*dt) |
| 159 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 160 | + end |
| 161 | + # if scale_noise == false, c2 = 1 |
| 162 | + OBABOConstantCache(k, half, c₂, σ) |
| 163 | +end |
| 164 | + |
| 165 | +function alg_cache(alg::OBABO,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} |
| 166 | + dutmp = zero(u.x[1]) |
| 167 | + utmp = zero(u.x[2]) |
| 168 | + k = zero(rate_prototype.x[1]) |
33 | 169 | noise = zero(rate_prototype.x[1])
|
34 | 170 |
|
| 171 | + gtmp = zero(noise_rate_prototype) |
| 172 | + noisetmp = zero(rate_prototype.x[1]) |
| 173 | + |
| 174 | + |
35 | 175 | half = uEltypeNoUnits(1//2)
|
36 |
| - c1 = exp(-alg.gamma*dt) |
37 |
| - c2 = sqrt(1 - alg.scale_noise*c1^2) # if scale_noise == false, c2 = 1 |
| 176 | + |
| 177 | + if typeof(alg.gamma) <: Number |
| 178 | + c₂ = exp.(-alg.gamma*half*dt) |
| 179 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 180 | + elseif typeof(alg.gamma) <: AbstractMatrix |
| 181 | + c₂ = exp(-alg.gamma*half*dt) |
| 182 | + σ = cholesky(I - alg.scale_noise*c₂*transpose(c₂)).U |
| 183 | + else |
| 184 | + c₂ = exp.(-alg.gamma*half*dt) |
| 185 | + σ = sqrt.(1 .- alg.scale_noise*c₂.^2) |
| 186 | + end |
38 | 187 |
|
39 | 188 | tmp = zero(u)
|
40 | 189 |
|
41 |
| - BAOABCache(utmp, dutmp, k, gtmp, noise, half, uEltypeNoUnits(c1), uEltypeNoUnits(c2), tmp) |
| 190 | + OBABOCache(utmp, dutmp, k, noise, gtmp, noisetmp, half, c₂, σ, tmp) |
42 | 191 | end
|
0 commit comments