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

Substitute types with abstractions #132

Merged
merged 1 commit into from
Apr 29, 2022
Merged

Conversation

tsj5
Copy link
Collaborator

@tsj5 tsj5 commented Jan 28, 2022

This PR implements the abstract typing done in CliMA/EnsembleKalmanProcesses.jl#100, e.g. Array{FT, 2}AbstractMatrix{FT}, in order to be consistent with that dependency.

See the discussion concerning performance at that PR; use of abstract types is recommended against for perf reasons, but the rationale here is that the code is essentially "glue" rather than numerical routines appearing in hot loops, so writing for generality over perf is justified.
Another downside is that existing abstract types aren't "abstract" enough, e.g. UniformScaling is not a subtype of AbstractMatrix and must be handled separately.

As a benefit, the changes made here result in some method signatures being more strongly typed than they are in master, allowing us to replace repeated code with multiple dispatch ("Don't Repeat Yourself").

MCMC is changed to a mutable struct, instead of continuing the current code's practice of enabling mutability by making fields of the struct 1x1 Arrays instead of scalars. This change is a moot point, however, since it will be overridden by PR #130.

@tsj5 tsj5 self-assigned this Jan 28, 2022
@tsj5 tsj5 changed the title Substitute types with abstractions [WIP] Substitute types with abstractions Jan 28, 2022
@tsj5 tsj5 force-pushed the tsj/abstract-types branch from b104811 to 72ed703 Compare January 28, 2022 03:08
@tsj5
Copy link
Collaborator Author

tsj5 commented Jan 28, 2022

TODO: add tests with different covariance matrix types

@tsj5 tsj5 changed the base branch from staging to master February 4, 2022 05:00
Copy link
Collaborator

@odunbar odunbar left a comment

Choose a reason for hiding this comment

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

Hi Tom - This looks great! I only had a couple of very small comments.

Beside these I should point out that:

  1. I definitely like the removal of decomposition wrapper
  2. I like the VecOrMat types to deal with reshaping issues
  3. I like the mutability of MCMC (finally we can remove the [1] array changes)

Just a small point in the SVD

src/Emulator.jl Outdated Show resolved Hide resolved
src/GaussianProcess.jl Outdated Show resolved Hide resolved
@odunbar
Copy link
Collaborator

odunbar commented Apr 5, 2022

LGTM! Merge away

@tsj5 tsj5 force-pushed the tsj/abstract-types branch from b47ba89 to cbaf482 Compare April 26, 2022 05:40
@tsj5
Copy link
Collaborator Author

tsj5 commented Apr 26, 2022

Update: 5d9def7 is a rebase & squash of commits made up to @odunbar's approval. Extra commits should be non-controversial:

  • MCMC struct was made immutable by mistake in a merge; as described above, we make it mutable in this PR with the expectation that it will be replaced by a more robust implementation in [WIP] Modular Sampler interface #130.
  • We support covariance matrices of type Matrix (dense), Diagonal and UniformScaling, for parity with Substitute types by abstractions. EnsembleKalmanProcesses.jl#100. UniformScaling is cast to Diagonal in the constructor for Emulator, since otherwise needed functionality isn't implemented. Identical unit tests are done for these three cases.

@tsj5
Copy link
Collaborator Author

tsj5 commented Apr 26, 2022

bors try

bors bot added a commit that referenced this pull request Apr 26, 2022
@bors
Copy link
Contributor

bors bot commented Apr 26, 2022

try

Build failed:

@tsj5
Copy link
Collaborator Author

tsj5 commented Apr 28, 2022

bors try

bors bot added a commit that referenced this pull request Apr 28, 2022
@bors
Copy link
Contributor

bors bot commented Apr 28, 2022

Implements abstract typing done in EnsembleKalmanProcesses.jl#100.
Adds support & tests for covariance as a dense matrix, Diagonal or
UniformScaling type.

Use abstract types in Emulator

Combine logic for GaussianProcess predict()

Use abstract types in GaussianProcess

Use abstract types in MarkovChainMonteCarlo

Add UniformScaling as a covariance type

Correct SVD transformation

Qualify use of GaussianProcesses.GPE, for clarity

Fix DataContainers import

Make MCMC struct mutable (to be reverted in PR #130)

Methods & tests for Diagonal, UniformScaling cov types
@tsj5 tsj5 force-pushed the tsj/abstract-types branch from cbaf482 to 9e69409 Compare April 29, 2022 04:27
@tsj5
Copy link
Collaborator Author

tsj5 commented Apr 29, 2022

bors r+

@bors
Copy link
Contributor

bors bot commented Apr 29, 2022

@bors bors bot merged commit 04d5954 into CliMA:master Apr 29, 2022
@tsj5 tsj5 changed the title [WIP] Substitute types with abstractions Substitute types with abstractions Apr 29, 2022
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.

2 participants