Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change constructor of OrnsteinUhlenbeckDiffusion #31

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/montecatto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
17 changes: 16 additions & 1 deletion src/continuous.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -24,7 +24,7 @@ using Test
@test size(x_t) == size(x_0)

diffusion = (
OrnsteinUhlenbeckDiffusion(0.0),
OrnsteinUhlenbeckDiffusion(1.0),
UniformDiscreteDiffusion(1.0, 4),
)

Expand Down