Skip to content

Commit

Permalink
Merge #270
Browse files Browse the repository at this point in the history
270: more robust empirical covariances r=odunbar a=odunbar

<!--- THESE LINES ARE COMMENTED -->
## Purpose 
<!--- One sentence to describe the purpose of this PR, refer to any linked issues:
#14 -- this will link to issue 14
Closes #2 -- this will automatically close issue 2 on PR merge
-->
Closes #269 

## To-do
<!---  list of proposed tasks in the PR, move to "Content" on completion 
- Proposed task
-->


## Content
<!---  specific tasks that are currently complete 
- Solution implemented
-->
- `cov(u,u) -> cov(u)`

<!---
Review checklist

I have:
- followed the codebase contribution guide: https://clima.github.io/ClimateMachine.jl/latest/Contributing/
- followed the style guide: https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/
- followed the documentation policy: https://github.com/CliMA/policies/wiki/Documentation-Policy
- checked that this PR does not duplicate an open PR.

In the Content, I have included 
- relevant unit tests, and integration tests, 
- appropriate docstrings on all functions, structs, and modules, and included relevant documentation.

-->

----
- [x] I have read and checked the items on the review checklist.


Co-authored-by: odunbar <[email protected]>
  • Loading branch information
bors[bot] and odunbar committed Mar 23, 2023
2 parents 3ba08bb + fe10056 commit dd4673d
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/EnsembleKalmanInversion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function eki_update(
obs_noise_cov::Union{AbstractMatrix{CT}, UniformScaling{CT}},
) where {FT <: Real, IT, CT <: Real}

cov_est = cov([u; g], [u; g], dims = 2, corrected = false) # [(N_par + N_obs)×(N_par + N_obs)]
cov_est = cov([u; g], dims = 2, corrected = false) # [(N_par + N_obs)×(N_par + N_obs)]

# Localization
cov_localized = ekp.localizer.localize(cov_est)
Expand Down
6 changes: 3 additions & 3 deletions src/EnsembleKalmanProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ Returns the unconstrained parameter sample covariance at the given iteration.
"""
function get_u_cov(ekp::EnsembleKalmanProcess, iteration::IT) where {IT <: Integer}
u = get_data(ekp.u[iteration])
return cov(u, u, dims = 2)
return cov(u, dims = 2)
end

"""
Expand All @@ -244,7 +244,7 @@ end
Returns the unconstrained parameter sample covariance for the initial ensemble.
"""
function get_u_cov_prior(ekp::EnsembleKalmanProcess)
return cov(get_u_prior(ekp), get_u_prior(ekp), dims = 2)
return cov(get_u_prior(ekp), dims = 2)
end

"""
Expand Down Expand Up @@ -421,7 +421,7 @@ function sample_empirical_gaussian(
n::IT;
inflation::Union{FT, Nothing} = nothing,
) where {FT <: Real, IT <: Int}
cov_u_new = Symmetric(cov(u, u, dims = 2))
cov_u_new = Symmetric(cov(u, dims = 2))
if !isposdef(cov_u_new)
@warn string("Sample covariance matrix over ensemble is singular.", "\n Appplying variance inflation.")
if isnothing(inflation)
Expand Down
2 changes: 1 addition & 1 deletion test/Localizers/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const EKP = EnsembleKalmanProcesses
# Test Schur product theorem
u_final = get_u_final(ekiobj)
g_final = get_g_final(ekiobj)
cov_est = cov([u_final; g_final], [u_final; g_final], dims = 2, corrected = false)
cov_est = cov([u_final; g_final], dims = 2, corrected = false)
cov_localized = ekiobj.localizer.localize(cov_est)
@test rank(cov_est) < rank(cov_localized)
# Test localization getter method
Expand Down

0 comments on commit dd4673d

Please sign in to comment.