Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrected EKS implementation #83

Merged
merged 7 commits into from
Nov 18, 2020
Merged

Corrected EKS implementation #83

merged 7 commits into from
Nov 18, 2020

Conversation

agarbuno
Copy link
Collaborator

@agarbuno agarbuno commented Nov 3, 2020

This kills a bug in the EKS method and add a linear example as a test.

@agarbuno agarbuno requested review from bielim and ilopezgp November 3, 2020 03:29
Project.toml Outdated
@@ -9,6 +9,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
GaussianProcesses = "891a1506-143c-57d2-908e-e1f8e92e6de9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep this dependency on Plots or do something else? @jakebolewski @bielim @odunbar

Copy link
Collaborator

@odunbar odunbar Nov 6, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a good thing to do with plots (for this PR) is described here https://discourse.julialang.org/t/add-package-to-project-toml-when-needed-only-for-testing/20552/3
In our setting I think it amounts to the following

  1. Add Test to the Project.toml
  2. Add (manually) new sections [extras] and [targets] into Project.toml,
  3. Copy the Test line and the Plots lines into [extras]
  4. in the [targets] section put test = ["Test","Plots"]

Then when you call Pkg.test("MyPackage"), (not run runtest.jl directly) it will also load the Plots package.

NB I haven't done this before but hopefully it will work

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try this, yes (this is what worked for @glwagner in Oceananigans, right?)

@codecov
Copy link

codecov bot commented Nov 3, 2020

Codecov Report

Merging #83 (660f597) into master (229522c) will increase coverage by 0.51%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #83      +/-   ##
==========================================
+ Coverage   77.32%   77.84%   +0.51%     
==========================================
  Files           7        7              
  Lines         494      492       -2     
==========================================
+ Hits          382      383       +1     
+ Misses        112      109       -3     
Impacted Files Coverage Δ
src/EKP.jl 81.81% <100.00%> (+2.92%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 229522c...660f597. Read the comment docs.

src/EKP.jl Outdated Show resolved Hide resolved
src/EKP.jl Outdated Show resolved Hide resolved
src/EKP.jl Outdated Show resolved Hide resolved
u_mean = mean(u', dims=2)
# g_mean: N_params x 1
u_mean = mean(u', dims=2)
# g_mean: N_params x 1
g_mean = mean(g', dims=2)
# g_cov: N_params x N_params
g_cov = cov(g, corrected=false)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

corrected=false is a default and can be removed

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the docs, the default is actually corrected=true, so we need to explicitly set the flag to false here.

# EKI provides a solution closer to the ordinary Least Squares estimate
@test norm(ols_mean - eki_final_result) < norm(ols_mean - eks_final_result)
# EKS provides a solution closer to the posterior mean
@test norm(posterior_mean - eks_final_result) < norm(posterior_mean - eki_final_result)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these tests always going to be true? Or just in this test case, e.g this depends on realizations of the data you provide etc?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we will improve the tests in a future PR, this one is mainly about implementing the EKS.

# In words: the ensemble covariance is still a bit ill-dispersed since the
# algorithm employed still does not include the correction term for finite-sized
# ensembles.
@test abs(sum(diag(posterior_cov_inv\cov(eksobj.u[end]))) - n_par) > 1e-5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is maybe more of a feature of the current algorithm as opposed to a test. e.g are we actually implying we fail this test if the covariance is not ill-dispersed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed, we will improve the tests in a future PR, this one is mainly about implementing the EKS.

Copy link
Contributor

@bielim bielim left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that we make runtests-linear-model.jl the new runtests.jl and delete the old one, since runtests-linear-model.jl is basically an improved version of the example in runtests.jl. But it needs some more @test statements - in general it would be good if all functions, objects and object attributes in EKP.jl were "touched" at least once in these tests.

Project.toml Outdated
@@ -9,6 +9,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
GaussianProcesses = "891a1506-143c-57d2-908e-e1f8e92e6de9"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try this, yes (this is what worked for @glwagner in Oceananigans, right?)

@odunbar odunbar changed the title Ag/eks implementation corrected EKS implementation Nov 12, 2020
@odunbar odunbar changed the title corrected EKS implementation Corrected EKS implementation Nov 12, 2020
@bielim
Copy link
Contributor

bielim commented Nov 17, 2020

bors r+

bors bot added a commit that referenced this pull request Nov 17, 2020
83: Corrected EKS implementation r=bielim a=agarbuno

This kills a bug in the EKS method and add a linear example as a test. 

Co-authored-by: Alfredo Garbuno <alfredo.garbuno@itam.mx>
Co-authored-by: odunbar <47412152+odunbar@users.noreply.github.com>
Co-authored-by: Melanie <melanie@charney.bieli.email>
@bors
Copy link
Contributor

bors bot commented Nov 17, 2020

Build failed:

@jakebolewski
Copy link
Contributor

bors r+

bors bot added a commit that referenced this pull request Nov 18, 2020
83: Corrected EKS implementation r=jakebolewski a=agarbuno

This kills a bug in the EKS method and add a linear example as a test. 

Co-authored-by: Alfredo Garbuno <alfredo.garbuno@itam.mx>
Co-authored-by: odunbar <47412152+odunbar@users.noreply.github.com>
Co-authored-by: Melanie <melanie@charney.bieli.email>
@bors
Copy link
Contributor

bors bot commented Nov 18, 2020

Build failed:

agarbuno and others added 7 commits November 18, 2020 10:01
…mentation (#84)

Also, restructure `Project.toml` such that Plots.jl is only required for running
tests.

Co-authored-by: Melanie <melanie@charney.bieli.email>
…old one

They both essentially test the same thing, but `runtests-linear-model.jl`
uses a better example problem.
Recommendation: In general, unit tests should also test "trivial code" (e.g.,
getters and setters) and check for things like type stability. The ones we
currently have focus on functionality and could use some more of these simpler
checks - ideally, all functions and objects should get "touched" at least once.
A future PR to expand the tests in this spirit is warranted.
@jakebolewski
Copy link
Contributor

bors r+

@bors
Copy link
Contributor

bors bot commented Nov 18, 2020

Build succeeded:

@bors bors bot merged commit 33742ea into master Nov 18, 2020
@bors bors bot deleted the ag/eks-implementation branch November 18, 2020 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants