Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
nefrathenrici committed Feb 16, 2024
1 parent 76aa8d1 commit 1fcf2ab
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/emulate_sample.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ function sample(emulator, y_obs, prior, init_params; n_samples = 100_000)
N = 2000,
discard_initial = 0,
)
println("Begin MCMC - with step size ", new_step)
chain = MarkovChainMonteCarlo.sample(
mcmc,
n_samples;
Expand Down
1 change: 1 addition & 0 deletions test/Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[deps]
CLIMAParameters = "6eacf6c3-8458-43b9-ae03-caf5306d3d53"
CalibrateAtmos = "4347a170-ebd6-470c-89d3-5c705c0cacc2"
CalibrateEmulateSample = "95e48a1f-0bec-4818-9538-3db4340308e3"
ClimaCore = "d414da3d-4745-48bb-8d80-42e94e092884"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
EnsembleKalmanProcesses = "aa8a2aa5-91d8-4396-bcef-d4f2ec43552d"
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ using Test

include("test_init.jl")
include("test_atmos_config.jl")
include("test_emulate_sample.jl")
Binary file added test/test_case_inputs/eki_test.jld2
Binary file not shown.
4 changes: 4 additions & 0 deletions test/test_case_inputs/sphere_hs_rhoe.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
["equator_pole_temperature_gradient_wet"]
prior = "Parameterized(Normal(4.779568,0.31223328))"
constraint = "[bounded_below(0)]"
type = "float"
36 changes: 36 additions & 0 deletions test/test_emulate_sample.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import JLD2
import Statistics: mean

using CalibrateEmulateSample.Emulators
using CalibrateEmulateSample.MarkovChainMonteCarlo
import EnsembleKalmanProcesses as EKP
using EnsembleKalmanProcesses.ParameterDistributions
using EnsembleKalmanProcesses.TOMLInterface

import CalibrateAtmos as CAL

y_obs = [261.5493]
y_noise_cov = [0.02619;;]
ekp = JLD2.load_object(joinpath("test_case_inputs", "eki_test.jld2"))
init_params = [EKP.get_u_final(ekp)[1]]

prior_path = joinpath("test_case_inputs", "sphere_hs_rhoe.toml")

prior = CAL.get_prior(prior_path)

input_output_pairs = CAL.get_input_output_pairs(ekp)

@test input_output_pairs.inputs.stored_data ==
hcat([ekp.u[i].stored_data for i in 1:(length(ekp.u) - 1)]...)
@test input_output_pairs.outputs.stored_data ==
hcat([ekp.g[i].stored_data for i in 1:length(ekp.g)]...)

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

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

0 comments on commit 1fcf2ab

Please sign in to comment.