From 7eb631af8b9888515ff306abcf135b820b83e613 Mon Sep 17 00:00:00 2001 From: nefrathenrici Date: Fri, 16 Feb 2024 16:42:39 -0800 Subject: [PATCH] nicer docs --- docs/src/emulate_sample.md | 49 ++++++++++++++++++++++++++++++++++++++ test/Project.toml | 1 + 2 files changed, 50 insertions(+) diff --git a/docs/src/emulate_sample.md b/docs/src/emulate_sample.md index 6780c2e2..d1796710 100644 --- a/docs/src/emulate_sample.md +++ b/docs/src/emulate_sample.md @@ -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") ``` \ No newline at end of file diff --git a/test/Project.toml b/test/Project.toml index b017bfec..8052a3e3 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -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"