Skip to content

Commit 7f0fed1

Browse files
committed
Fix scaling bug in AiryProcess
Also provide next!(::AiryProcess, S) to update the state S without computing the value.
1 parent b1e3e03 commit 7f0fed1

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/StochasticProcess.jl

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#Matrices related to stochastic processes
22

33
import Base: start, next, done
4-
export AiryProcess, BrownianProcess, WhiteNoiseProcess
4+
export AiryProcess, BrownianProcess, WhiteNoiseProcess, next!
55

66
abstract StochasticProcess{T<:Real}
77

@@ -13,7 +13,7 @@ immutable BrownianProcess{T<:Real} <: StochasticProcess{T}
1313
dt::T
1414
end
1515

16-
type AiryProcess{S<:Real, T<:Real} <: StochasticProcess{T}
16+
immutable AiryProcess{S<:Real, T<:Real} <: StochasticProcess{T}
1717
dt::T
1818
beta::S
1919
end
@@ -41,14 +41,31 @@ end
4141
# Airy process #
4242
################
4343
start{T}(p::AiryProcess{T}) = SymTridiagonal(T[-(2/p.dt^2)], T[])
44+
45+
"""
46+
Like next, but update only the state of the AiryProcess
47+
48+
Skip the eigenvalue computation, which gets expensive
49+
"""
50+
function next!{T}(p::AiryProcess{T}, S::SymTridiagonal{T})
51+
t = (size(S, 1)-1)*p.dt
52+
53+
#Discretized Airy operator plus diagonal noise
54+
x = inv(p.dt^2)
55+
push!(S.dv, -2x - t + 2/sqrt(p.dt*p.beta)*randn())
56+
push!(S.ev, x)
57+
58+
S
59+
end
4460
function next{T}(p::AiryProcess{T}, S::SymTridiagonal{T})
4561
t = (size(S, 1)-1)*p.dt
4662

4763
#Discretized Airy operator plus diagonal noise
4864
x = inv(p.dt^2)
49-
push!(S.dv, -2x - t + 2/sqrt(p.beta/p.dt)*randn())
65+
push!(S.dv, -2x - t + 2/sqrt(p.dt*p.beta)*randn())
5066
push!(S.ev, x)
5167

52-
(eigmax(S)*p.dt^2, S)
68+
(eigmax(S), S)
5369
end
5470

71+

0 commit comments

Comments
 (0)