so I have a model y = f(x; \theta).
using (x, y) pairs, I get a posterior over theta. this constitutes “model calibration”.
now I wanna use this posterior as the prior for an inverse problem, where I observe y and wanna predict x. “yesterday’s posterior is today’s prior”
a way I’ve been doing this is to fit a multi-variate Gaussian to theta from my model calibration phase. then I have an analytical distribution to impose as my prior for the inverse problem.
but I don’t want to impose this parametric family on my prior; I wanna use my samples!
so of course one way to do this, is in the “@model” definition of the forward model for my inverse problem, simply sample a random row from my model calibration posterior’s data frame each time I wanna sample a theta from the prior for my inverse problem, then voila that works just fine. HOWEVER, then when I get my data frame of the posterior samples from my inverse problem, it does not contain the variables I sampled, so I lost ALL info about the correlation between the theta’s and my inferred x from the inverse problem! is there some way to create an empirical distribution as a prior in Turing.jl? or store these samples from rows of my data frame in the data frame that the MCMC sampler returns?
thx.
appendix
so I want to know correlation e.g. of c
with h₀
but have no idea. I want to associate with each sample of h₀
the c
value that produced it.
@model function infer_h₀_model(
mdata::DataFrame, train_posterior::DataFrame, prior_only::Bool=false
)
#=
prior distributions
yesterday's posterior is today's prior
=#
# important: sample ROW to capture correlations
i = sample(1:nrow(train_posterior))
H = train_posterior[i, "H"]
α₀ = train_posterior[i, "α₀"]
α₁ = train_posterior[i, "α₁"]
α₂ = train_posterior[i, "α₂"]
P_t = train_posterior[i, "P_t"]
P_b = train_posterior[i, "P_b"]
c = train_posterior[i, "c"]
rₒ = train_posterior[i, "rₒ"]
σₕ = train_posterior[i, "σₕ"]
# initial liquid level
h₀ ~ Uniform(0.0, H) # cm
# initial time (shifts experiment time)
t₀ ~ Normal(0.0, 10.0) # s
# for prior, do not show the algo the data :)
if prior_only
return nothing
end
# set up, solve ODE
sim_data, h_of_t = sim_h(
h₀,
P_t, P_b, H,
c,
rₒ
)
# for prior, do not show the algo the data :)
if prior_only
return nothing
end
# account for observations
t = mdata[2, "t [s]"] # time for this data point
ĥ = h_of_t(t - t₀) # predicted liquid level
δ = α₀ .+ α₁ * ĥ .+ α₂ * ĥ .^ 2 # discrepancy
mdata[2, "h [cm]"] ~ Normal(ĥ + δ, σₕ)
return nothing
end