Skip to content

Commit

Permalink
Prevent DataMisfitController scheduler from modifying ekp.inv_sqrt_no…
Browse files Browse the repository at this point in the history
…ise in place
  • Loading branch information
costachris committed Oct 22, 2023
1 parent ad23cac commit 04b7a42
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/LearningRateSchedulers.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# included in EnsembleKalmanProcess.jl

export DefaultScheduler, MutableScheduler, EKSStableScheduler, DataMisfitController
export calculate_timestep!
export calculate_timestep!, posdef_correct

# default unless user overrides

Expand Down Expand Up @@ -222,6 +222,7 @@ $(DocStringExtensions.TYPEDSIGNATURES)
Makes square matrix `mat` positive definite, by symmetrizing and bounding the minimum eigenvalue below by `tol`
"""
function posdef_correct(mat::AbstractMatrix; tol::Real = 1e8 * eps())
mat = deepcopy(mat)
if !issymmetric(mat)
out = 0.5 * (mat + permutedims(mat, (2, 1))) #symmetrize
if isposdef(out)
Expand Down
5 changes: 5 additions & 0 deletions test/EnsembleKalmanProcess/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,7 @@ end
else #no initial ensemble for UKI
ekpobj = EKP.EnsembleKalmanProcess(y_obs, Γy, process, rng = copy(rng), scheduler = scheduler)
end
initial_obs_noise_cov = deepcopy(ekpobj.obs_noise_cov)
for i in 1:N_iter
params_i = get_ϕ_final(prior, ekpobj)
g_ens = G(params_i)
Expand All @@ -290,9 +291,13 @@ end
if !isnothing(terminated)
break
end
# ensure Δt is updated
@test length(ekpobj.Δt) == i
end
push!(init_means, vec(mean(get_u_prior(ekpobj), dims = 2)))
push!(final_means, vec(mean(get_u_final(ekpobj), dims = 2)))
# ensure obs_noise_cov matrix remains unchanged
@test initial_obs_noise_cov == ekpobj.obs_noise_cov

# this test is fine so long as N_iter is large enough to hit the termination time
if nameof(typeof(scheduler)) == DataMisfitController
Expand Down

0 comments on commit 04b7a42

Please sign in to comment.