I want to do a Bayesian calibration on an exterior model, in order to find the true value of the parameter “teta”.
I made a simple code to try to explain. Here “teta” is the parameter that I want to calibrate in the exterior model. The problem is that the exterior model can only receive integers or floats and not the variable FreeRV. How can I convert teta so that I can pass it to the exterior model?
import pymc3 as pm
def exterior_model(param):
if param > 2:
y = param * 3 + 2
else:
y = param * 1 + 2
return y
true_param = 3 # Should receive the posterior parameter mean value = 3
observation = exterior_model(true_param)
prior_param = 1
with pm.Model() as model:
#Prior parameter
teta = pm.Normal("teta", mu=prior_param, sigma=1)
model_mean = pm.Deterministic('mu', exterior_model(teta))
#Likelihood
likelihood = pm.Normal("y", mu = model_mean, sigma=1, observed=observation)
#posterior
trace = pm.sample(1000, cores=1)