Skip to content

Commit

Permalink
let diffusion_matrix(::CoupledSDEs) export a matrix (#221)
Browse files Browse the repository at this point in the history
* let diffusion_matrix export a matrix

* increase path number
  • Loading branch information
oameye authored Oct 4, 2024
1 parent 8cc1b54 commit 581255a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DynamicalSystemsBase"
uuid = "6e36e845-645a-534a-86f2-f5d4aa5a06b4"
repo = "https://github.com/JuliaDynamics/DynamicalSystemsBase.jl.git"
version = "3.11.0"
version = "3.11.1"

[deps]
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
Expand Down
11 changes: 6 additions & 5 deletions ext/src/CoupledSDEs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,11 @@ If this is not the case, returns `nothing`.
Note: The diffusion matrix ``Σ`` is the square root of the noise covariance matrix ``Q`` (see
[`covariance_matrix`](@ref)), defined via the Cholesky decomposition ``Q = Σ Σ^\\top``.
"""
function diffusion_matrix(ds::CoupledSDEs{IIP,D}) where {IIP,D}
function diffusion_matrix(ds::CoupledSDEs{IIP,D})::AbstractMatrix where {IIP,D}
if ds.noise_type[:invertible]
diffusion = diffusion_function(ds)
A = diffusion(zeros(D), current_parameters(ds), 0.0)
A = A isa AbstractMatrix ? A : Diagonal(A)
else
@warn """
The diffusion function of the `CoupledSDEs` cannot be expressed as a constant
Expand All @@ -218,7 +219,7 @@ If this is not the case, returns `nothing`.
See also [`diffusion_matrix`](@ref).
"""
function covariance_matrix(ds::CoupledSDEs)
function covariance_matrix(ds::CoupledSDEs)::AbstractMatrix
A = diffusion_matrix(ds)
(A == nothing) ? nothing : A * A'
end
Expand All @@ -241,10 +242,10 @@ Returns `g, noise_prototype`.
"""
function construct_diffusion_function(
g, covariance, noise_prototype, noise_strength, D, IIP
)
)
if isnothing(g) # diagonal additive noise
cov = isnothing(covariance) ? LinearAlgebra.I(D) : covariance
size(cov) != (D,D) &&
size(cov) != (D, D) &&
throw(ArgumentError("Covariance matrix must be of size $((D, D))"))
A = sqrt(cov)
if IIP
Expand All @@ -269,4 +270,4 @@ function construct_diffusion_function(
end
end
return g, noise_prototype
end
end
3 changes: 2 additions & 1 deletion test/stochastic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ end
A = sqrt(Γ)
lorenz_oop = CoupledSDEs(lorenz_rule, u0, p0, covariance = Γ, diffeq=diffeq_cov)
@test A diffusion_matrix(lorenz_oop)
@test A isa AbstractMatrix
@test Γ A * A'
end

Expand All @@ -153,4 +154,4 @@ end
@test approx Γ atol=1e-1 broken = true
# I think I understand something wromg here
end
end
end

0 comments on commit 581255a

Please sign in to comment.