From bf730652e52fc48cf569ec59f67c003ca01db93f Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Wed, 8 Mar 2023 01:00:13 +0100 Subject: [PATCH 1/2] change constructor of OrnsteinUhlenbeckDiffusion --- examples/montecatto.jl | 4 ++-- src/continuous.jl | 17 ++++++++++++++++- test/runtests.jl | 4 ++-- 3 files changed, 20 insertions(+), 5 deletions(-) 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..b0faa32 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 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), ) From 5f65c9ca9f9d5d4d9a202d38676454b7d02d5f8a Mon Sep 17 00:00:00 2001 From: Kenta Sato Date: Wed, 8 Mar 2023 10:31:57 +0100 Subject: [PATCH 2/2] fix docstring --- src/continuous.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/continuous.jl b/src/continuous.jl index b0faa32..cad8958 100644 --- a/src/continuous.jl +++ b/src/continuous.jl @@ -12,9 +12,9 @@ OrnsteinUhlenbeckDiffusion(mean::Real, volatility::Real, reversion::Real) = Orns Create an Ornstein-Uhlenbeck diffusion. -The process is defined by the following stochastic differential equation: +The process (X_t) is defined by the following stochastic differential equation: - dx_t = -θ (μ - x_t) dt + σ dW_t, + dX_t = -θ (μ - X_t) dt + σ dW_t, where W_t denotes the Wiener process.