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

Sinusoidal example #248

Merged
merged 1 commit into from
Jan 5, 2024
Merged

Sinusoidal example #248

merged 1 commit into from
Jan 5, 2024

Conversation

lm2612
Copy link
Collaborator

@lm2612 lm2612 commented Nov 2, 2023

Purpose

This will close #247

To-do

  • Copy sinusoidal example from EnsembleKalmanProcesses.jl for the calibration step
  • Create two emulators (Gaussian process, scalar random feature) and compare performance
  • Demonstrate sampling code and plot samples to show how to do uncertainty quantification
  • Documentation

Content


  • I have read and checked the items on the review checklist.

@lm2612 lm2612 self-assigned this Nov 2, 2023
Copy link

codecov bot commented Dec 6, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (a621a04) 88.09% compared to head (ab5a875) 88.16%.
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #248      +/-   ##
==========================================
+ Coverage   88.09%   88.16%   +0.07%     
==========================================
  Files           7        7              
  Lines        1134     1124      -10     
==========================================
- Hits          999      991       -8     
+ Misses        135      133       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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 @lm2612 This looks really good so far. I have focussed just on the Docs for now, I'll take a peak at the RF setup etc. in a bit. It's mostly minor comments, although there is one larger comment.

  • I find the marginal GP/RF validation plots quite opaque. It's very hard to interpret how far the data is from the training points etc. as only ordering in one axis is not very clear.

docs/src/examples/sinusoid_example.md Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Show resolved Hide resolved
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 @lm2612

A review on the example itself:

  • The difference in performance is due to it not being a fair experiment, I have detailed the small fix, and I observe this balances out the behaviour significantly. though the RF still has a heavier tail for theta_1 (Note RF still learns the noise where GP doesnt)

examples/Sinusoid/emulate.jl Outdated Show resolved Hide resolved
examples/Sinusoid/emulate.jl Outdated Show resolved Hide resolved
examples/Sinusoid/emulate.jl Outdated Show resolved Hide resolved
examples/Sinusoid/sample.jl Outdated Show resolved Hide resolved
examples/Sinusoid/emulate.jl Outdated Show resolved Hide resolved
examples/Sinusoid/emulate.jl Show resolved Hide resolved
@odunbar
Copy link
Collaborator

odunbar commented Dec 20, 2023

Another Kernel that performs very similarly to GP is the following vector-RF case without decorrelation:

kernel_structure = NonseparableKernel(LowRankFactor(2,nugget))
optimizer_options = Dict(
    "scheduler" => EKP.DataMisfitController(on_terminate = "continue"),
   "n_iteration" => 50,
    "rng" => rng,
)
random_features = VectorRandomFeatureInterface(
    n_features,
    input_dim,
    output_dim,
    rng = rng,
    kernel_structure = kernel_structure,
    optimizer_options = optimizer_options,
)
emulator_random_features = Emulator(random_features, input_output_pairs, normalize_inputs = true, obs_noise_cov=Γ, decorrelate=false)

sinusoid_MCMC_hist_RF

sinusoid_GP_vs_RF_emulator

@lm2612 lm2612 requested a review from odunbar December 21, 2023 20:38
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.

LGTM - this is a fantastic example! Please run the julia formatter - otherwise my comments are very minor.

Then we can squash&merge

docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/src/examples/sinusoid_example.md Outdated Show resolved Hide resolved
docs/make.jl Outdated Show resolved Hide resolved
@lm2612 lm2612 force-pushed the sinusoidal-example branch 2 times, most recently from 616ffa4 to fc42bdb Compare January 4, 2024 22:04
…usoidal example. This example is 2d->2d for a model of a sinusoid that depends on 2 parameters (amplitude, vertical shift) and given a system where we make noisy observations of its range and mean position.

New files in example:
    * Setup script (functions defined for the true model)
    * Calibrate (using ensemble kalman inversion)
    * Emulate  (using GP, RF and emulator validation plots)
    * Sample (with mcmc and plotting 2d posteriors).

New docs under page Simple example walkthrough: a walkthrough of these scripts with plots for each step.
@odunbar odunbar marked this pull request as ready for review January 5, 2024 12:51
@odunbar odunbar changed the title [WIP] Sinusoidal example Sinusoidal example Jan 5, 2024
@odunbar odunbar merged commit a03960f into main Jan 5, 2024
8 of 9 checks passed
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.

Add a simple transparent example to aid the user understanding
2 participants