From 9a10de400c913b18401ef56d217d8f17c93fd802 Mon Sep 17 00:00:00 2001 From: costachris Date: Sun, 22 Oct 2023 12:51:02 -0700 Subject: [PATCH] Prevent DataMisfitController scheduler from modifying ekp.inv_sqrt_noise in place --- src/LearningRateSchedulers.jl | 1 + test/EnsembleKalmanProcess/runtests.jl | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/LearningRateSchedulers.jl b/src/LearningRateSchedulers.jl index 530501dcf..b5701acdb 100644 --- a/src/LearningRateSchedulers.jl +++ b/src/LearningRateSchedulers.jl @@ -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) diff --git a/test/EnsembleKalmanProcess/runtests.jl b/test/EnsembleKalmanProcess/runtests.jl index 914be0458..e60044d72 100644 --- a/test/EnsembleKalmanProcess/runtests.jl +++ b/test/EnsembleKalmanProcess/runtests.jl @@ -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) @@ -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