Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Feb 23, 2024
1 parent 2753b69 commit 564329a
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 49 deletions.
Binary file removed docs/src/assets/eki_file_for_emulate_example.jld2
Binary file not shown.
44 changes: 0 additions & 44 deletions docs/src/emulate_sample_example.jl

This file was deleted.

16 changes: 12 additions & 4 deletions src/emulate_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,20 @@ function gp_emulator(input_output_pairs, obs_noise_cov)
end

"""
sample(emulator, y_obs, prior, init_params; n_samples = 100_000)
sample(
emulator,
y_obs,
prior,
init_params;
n_samples = 100_000,
init_stepsize = 0.1,
discard_initial = 0
)
Constructs a MarkovChainMonteCarlo object, optimizes its stepsize, and takes
`n_samples` number of samples.
The initial stepsize can be specified by `init_stepsize` with a default of 0.1,
and the number of initial samples to discard can be set by `discard_initial` with a default of 0.
The initial stepsize can be specified by `init_stepsize`,
and the number of initial samples to discard can be set by `discard_initial`.
Returns both the MCMC object and the samples in a NamedTuple.
"""
function sample(
Expand All @@ -62,7 +70,7 @@ function sample(
end

"""
save_posterior(mcmc, chain, prior; filename = "samples.jld2")
save_posterior(mcmc, chain; filename = "samples.jld2")
Given an MCMC object, a Markov chain of samples, and a prior distribution,
constructs the posterior distribution and saves it to `filename`.
Expand Down
2 changes: 1 addition & 1 deletion test/test_emulate_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ emulator = CAL.gp_emulator(input_output_pairs, y_noise_cov)
(; mcmc, chain) = CAL.sample(emulator, y_obs, prior, init_params)
@test mean(chain.value[1:100000]) 4.19035299 rtol = 0.0001

constrained_posterior = CAL.save_posterior(mcmc, chain, prior)
constrained_posterior = CAL.save_posterior(mcmc, chain)
@test mean(constrained_posterior["equator_pole_temperature_gradient_wet"])
66.046965013381 rtol = 0.0001

0 comments on commit 564329a

Please sign in to comment.