diff --git a/examples/montecatto.jl b/examples/montecatto.jl index c83aae9..af5e40d 100644 --- a/examples/montecatto.jl +++ b/examples/montecatto.jl @@ -30,8 +30,8 @@ function monte_carlo_expect(g2,T; P = P, sample_func = target_sample, n_samples return g0.μ end -#Define a zero-mean OU process, with default volitility and reversion parameters -P = OrnsteinUhlenbeckDiffusion(0.0) +#Define a zero-mean OU process, with reversion 0.5 and default volitility +P = OrnsteinUhlenbeckDiffusion(0.5) #We'll work with 2-by-500 gaussians, where each pair is one point that will become cat-distributed x_T = rand(eq_dist(P),(2,400)) diff --git a/src/continuous.jl b/src/continuous.jl index 273ba2a..cad8958 100644 --- a/src/continuous.jl +++ b/src/continuous.jl @@ -7,7 +7,22 @@ end OrnsteinUhlenbeckDiffusion(mean::Real, volatility::Real, reversion::Real) = OrnsteinUhlenbeckDiffusion(float.(promote(mean, volatility, reversion))...) -OrnsteinUhlenbeckDiffusion(mean::T) where T <: Real = OrnsteinUhlenbeckDiffusion(mean,T(1.0),T(0.5)) +""" + OrnsteinUhlenbeckDiffusion(θ; σ = √(2θ), μ = 0) + +Create an Ornstein-Uhlenbeck diffusion. + +The process (X_t) is defined by the following stochastic differential equation: + + dX_t = -θ (μ - X_t) dt + σ dW_t, + +where W_t denotes the Wiener process. + +The process converges to a normal distribtuion with mean `μ` and variance `σ^2 / +2θ` at equilibrium. The default volatility `σ` and mean `μ` are defined so that +the process converges to the standard normal distribution. +""" +OrnsteinUhlenbeckDiffusion(θ::Real; σ::Real = √(2θ), μ::Real = 0) = OrnsteinUhlenbeckDiffusion(μ, σ, θ) var(model::OrnsteinUhlenbeckDiffusion) = (model.volatility^2) / (2 * model.reversion) diff --git a/test/runtests.jl b/test/runtests.jl index d1d0c4a..d76098b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -3,7 +3,7 @@ using Random using Test @testset "Diffusion" begin - diffusion = OrnsteinUhlenbeckDiffusion(0.0) + diffusion = OrnsteinUhlenbeckDiffusion(1.0) # 2d diffusion x_0 = randn(2) @@ -24,7 +24,7 @@ using Test @test size(x_t) == size(x_0) diffusion = ( - OrnsteinUhlenbeckDiffusion(0.0), + OrnsteinUhlenbeckDiffusion(1.0), UniformDiscreteDiffusion(1.0, 4), )