Skip to content

Commit

Permalink
nicer docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Feb 17, 2024
1 parent 6956aef commit 7eb631a
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
49 changes: 49 additions & 0 deletions docs/src/emulate_sample.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,55 @@
# Emulate and Sample
Once you have run a successful calibration, we can fit an emulator to the resulting input/output pairs.

First, import the necessary packages:
```julia
using CalibrateEmulateSample.Emulators
using CalibrateEmulateSample.MarkovChainMonteCarlo

import EnsembleKalmanProcesses as EKP
using EnsembleKalmanProcesses.ParameterDistributions
using EnsembleKalmanProcesses.TOMLInterface

import JLD2

import CalibrateAtmos as CAL
```

Next, load in the data, EKP object, and prior distribution.
```julia
y_obs = [261.5493]
y_noise_cov = [0.02619;;]
ekp = JLD2.load_object(
joinpath(
pkgdir(CAL),
"docs",
"src",
"assets",
"eki_file_for_emulate_example.jld2",
),
)
init_params = [EKP.get_u_final(ekp)[1]]

prior_path = joinpath(
pkgdir(CAL),
"experiments",
"sphere_held_suarez_rhoe_equilmoist",
"parameters.toml",
)

prior = CAL.get_prior(prior_path)
```
Get the input-output pairs which will be used to train the emulator:
```julia
input_output_pairs = CAL.get_input_output_pairs(ekp)
```
Create the Gaussian Process-based emulator, obtain samples, and save the samples to a JLD2 file.
```julia
emulator = CAL.gp_emulator(input_output_pairs, y_noise_cov)
(; mcmc, chain) = CAL.sample(emulator, y_obs, prior, init_params)
constrained_posterior = CAL.save_samples(mcmc, chain, prior; filename = "samples.jld2")
```

```@example
include("emulate_sample_example.jl")
```
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ EnsembleKalmanProcesses = "aa8a2aa5-91d8-4396-bcef-d4f2ec43552d"
JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

0 comments on commit 7eb631a

Please sign in to comment.