Skip to content

Commit

Permalink
JuliaFormatter.jl
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanaelbosch committed Feb 9, 2024
1 parent 9402f93 commit 4060652
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 15 deletions.
28 changes: 18 additions & 10 deletions src/algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,23 @@ abstract type AbstractEK <: OrdinaryDiffEq.OrdinaryDiffEqAdaptiveAlgorithm end

function ekargcheck(alg; diffusionmodel, pn_observation_noise, kwargs...)
if (isstatic(diffusionmodel) && diffusionmodel.calibrate) &&
(!isnothing(pn_observation_noise) && !iszero(pn_observation_noise))
throw(ArgumentError("Automatic calibration of global diffusion models is not possible when using observation noise. If you want to calibrate a global diffusion parameter, do so setting `calibrate=false` and optimizing `sol.pnstats.log_likelihood` manually."))
(!isnothing(pn_observation_noise) && !iszero(pn_observation_noise))
throw(
ArgumentError(
"Automatic calibration of global diffusion models is not possible when using observation noise. If you want to calibrate a global diffusion parameter, do so setting `calibrate=false` and optimizing `sol.pnstats.log_likelihood` manually.",
),
)
end
if (diffusionmodel isa FixedMVDiffusion || diffusionmodel isa DynamicMVDiffusion) && alg == EK1
throw(ArgumentError("The `EK1` algorithm does not support multivariate diffusion models. Use `EK0` instead, or use a scalar diffusion model."))
if (diffusionmodel isa FixedMVDiffusion || diffusionmodel isa DynamicMVDiffusion) &&
alg == EK1
throw(
ArgumentError(
"The `EK1` algorithm does not support multivariate diffusion models. Use `EK0` instead, or use a scalar diffusion model.",
),
)
end
end


"""
EK0(; order=3,
smooth=true,
Expand Down Expand Up @@ -56,11 +64,11 @@ struct EK0{PT,DT,IT,RT} <: AbstractEK
initialization::IT
pn_observation_noise::RT
EK0(; order=3,
prior::PT=IWP(order),
diffusionmodel::DT=DynamicDiffusion(),
smooth=true,
initialization::IT=TaylorModeInit(num_derivatives(prior)),
pn_observation_noise::RT=nothing,
prior::PT=IWP(order),
diffusionmodel::DT=DynamicDiffusion(),
smooth=true,
initialization::IT=TaylorModeInit(num_derivatives(prior)),
pn_observation_noise::RT=nothing,
) where {PT,DT,IT,RT} = begin
ekargcheck(EK0; diffusionmodel, pn_observation_noise)
new{PT,DT,IT,RT}(
Expand Down
3 changes: 2 additions & 1 deletion src/caches.jl
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ function OrdinaryDiffEq.alg_cache(
copy!(x0.Σ, apply_diffusion(x0.Σ, initdiff))

# Measurement model related things
R = isnothing(alg.pn_observation_noise) ? nothing :
R =
isnothing(alg.pn_observation_noise) ? nothing :
to_factorized_matrix(FAC, cov2psdmatrix(alg.pn_observation_noise; d))
H = factorized_similar(FAC, d, D)
v = similar(Array{uElType}, d)
Expand Down
9 changes: 5 additions & 4 deletions src/filtering/update.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,10 @@ end
function update!(
x_out::SRGaussian{T,<:IsometricKroneckerProduct},
x_pred::SRGaussian{T,<:IsometricKroneckerProduct},
measurement::Gaussian{<:AbstractVector,
<:Union{<:PSDMatrix{T,<:IsometricKroneckerProduct},
<:IsometricKroneckerProduct}},
measurement::Gaussian{
<:AbstractVector,
<:Union{<:PSDMatrix{T,<:IsometricKroneckerProduct},<:IsometricKroneckerProduct},
},
H::IsometricKroneckerProduct,
K1_cache::IsometricKroneckerProduct,
K2_cache::IsometricKroneckerProduct,
Expand All @@ -169,7 +170,7 @@ function update!(
_x_pred = Gaussian(reshape_no_alloc(x_pred.μ, Q, d), PSDMatrix(x_pred.Σ.R.B))
_measurement = Gaussian(
reshape_no_alloc(measurement.μ, 1, d),
measurement.Σ isa PSDMatrix ? PSDMatrix(measurement.Σ.R.B) : measurement.Σ.B
measurement.Σ isa PSDMatrix ? PSDMatrix(measurement.Σ.R.B) : measurement.Σ.B,
)
_H = H.B
_K1_cache = K1_cache.B
Expand Down

0 comments on commit 4060652

Please sign in to comment.