Hello all,
I am writing a code to do posterior predictive with a customDist function. My code is listed below. The error message there is returned is “random() missing 1 required positional argument: ‘beta’”. If my code is just doing sampling (pm.sample), it is fine. The error message came up when I did posterior predictive. I do not know where to add the positional argument accordingly. Thank you very much for your kind reply.
with pm.Model(coords=coords) as model:
x = pm.MutableData("x", x_train)
rloss = pm.MutableData("rloss", rloss_train)
# Priors
a = pm.Normal("a", mu=0, sigma=1, dims="coeffs")
b = pm.Normal("b", mu=0, sigma=1, dims="coeffs")
# Linear model
a1 = pm.math.dot(x, a)
b1 = pm.math.dot(x, b)
# Link function
mu = pm.Deterministic("mu", pm.math.invlogit(a1))
phi = pm.Deterministic("phi", pm.math.exp(b1))
alpha = pm.Deterministic("alpha", mu * phi)
beta = pm.Deterministic("beta", (1 - mu) * phi)
def logp_beta(obsLoss, alpha, beta):
return pm.logp(pm.Beta.dist(alpha=alpha, beta=beta), obsLoss)
def random(obsLoss, alpha, beta, rng= None, size=None) :
return pm.Beta.dist(alpha, beta).random(size=size)
# Likelihood using the custom distribution
rloss_custom = pm.CustomDist('rloss_custom', alpha, beta, logp=logp_beta, random=random, observed=rloss)
with model:
step = pm.Metropolis()
idata = pm.sample(1200, step=step, chains=4)
with model:
pm.set_data({"x": x_test}, coords = {"coeffs": labels})
pp = pm.sample_posterior_predictive(idata, predictions=True).predictions