First of all, thank you for developing this great library and for the strong community support! I built a generative latent variable model:
@config_enumerate
def model(data=None):
base_G_c = dist.Normal(torch.ones(self.n_c), torch.ones(self.n_c))
lam_G_c = pyro.sample("lam_G_c", dist.TransformedDistribution(base_G_c, [transforms.OrderedTransform()]))
base_Q_c = dist.Gamma(torch.ones(self.n_c), torch.ones(self.n_c))
lam_Q_c = pyro.sample("lam_Q_c", dist.TransformedDistribution(base_Q_c, [transforms.OrderedTransform()]))
base_T_c = dist.Normal(torch.ones(self.n_c) * (-1), torch.ones(self.n_c) * 1)
lam_T_c = pyro.sample("lam_T_c", dist.TransformedDistribution(base_T_c, [transforms.OrderedTransform(),transforms.SigmoidTransform()]))
pi_Z_c = pyro.sample("pi_Z_c", dist.Dirichlet(torch.ones(self.n_c) / self.n_c))
with pyro.plate('data_plate', data["mask"]["Q"].shape[0]):
Z = pyro.sample('Z', dist.Categorical(pi_Z_c), infer={"enumerate": "parallel"})
G = pyro.sample('G', dist.Normal(Vindex(lam_G_c)[Z], torch.ones(1)).mask(data["mask"]["G"]),obs=data["data"]["G"])
Q = pyro.sample('Q', dist.Poisson(Vindex(lam_Q_c)[Z]).mask(data["mask"]["Q"]), obs=data["data"]["Q"])
T = pyro.sample('T', dist.Binomial(probs=Vindex(lam_T_c)[Z], total_count=data["n_k"]["T"] - 1).mask(data["mask"]["T"]), obs=data["data"]["T"])
The model works fine and I can infer posterior params via MCMC. Now, I am trying to evaluate the model based on its (A) predictive likelihood and based on (B) point predictions on held-out data for âGâ, âQâ and âTâ.
(A) Predictive Likelihood_____________
Since the Predictive class does not return traces anymore and Predictive.get_vectorized_trace throws me the error âShape mismatch inside plate(âdata_plateâ) at site Z dim -1â (any ideas how to resolve this?), I am resorting to
conditioned_model = poutine.condition(model, mcmc_posterior_params)
trace = poutine.trace(conditioned_model).get_trace(data)
trace.compute_log_prob()
where mcmc_posterior_params
is e.g. the mean of the mcmc posterior params (I am aware of this discussion). However, I am worried that this is not doing what I want: I would like to obtain the log_prob for each of the observed sites, while knowing the other sites, e.g. log p(G* | Q*, T*, thetas) in the generative model. Do replay and block or infer_discrete help here?
(B) Point Predictions_____________
Inspired by several tutorials, I would like to evaluate the generative model by predicting one observed site, e.g. G = None, when passing only the values of the observed sites âTâ and âQâ. This can be seen as an imputation task, thus, I set impute_data["G"]["data"] = None
and impute_data["G"]["mask"] = [False, False, ....]
while keeping the true values in Q and T, e.g. impute_data["Q"]["data"] = [0,0,0,1,....]
. Next, I am doing
Predictive(model, mcmc_posterior_params)(impute_data)
and take the mean or mode over the predicted values per site and sample (MAP style). In the best case, this results in predictions equalling a majority vote baseline. Do you have any insights on how to get it right? I assume, I somehow need to condition on observed sites and params agains.
Since these discussions and tutorials like the Baseball one did not help me, I would so much appreciate your help! My case is slightly different to discriminative settings such as logistic regression since it is a generative model and the data features âXâ (âat_batsâ in the tutorial) are generated, observed sample sites and targets at the same time.