Deterministic values to not end up in MCMC sampling

I’ve got a model that I’m fitting using NUTS, which includes a deterministic variable of interest

    diff = pyro.deterministic('diff', torch.matmul(X_pred, w) - torch.matmul(X_pred, w_aaa))

which, according to the docstring should add these values to the MCMC trace. However, when I look at the resulting trace after sampling, this node is not present:

trace.keys()

dict_keys(['beta', 'w_aaa', 'w'])

Is there something else I need to do in order to have these values recorded during sampling, or am I misreading the docs? As you can see, w and w_aaa are sampled distributions in the model, and diff is just a deterministic transformation of them.

Running pyro 1.6.0 on Linux.

Hi @fonnesbeck, currently, MCMC only collects the sample sites. For deterministic sites, you will need to use Predictive:

predictive = Predictive(model, posterior_samples, return_sites=...)
samples_including_deterministic = predictive(*args, **kwargs)
1 Like

Thanks. Is there a usage example in the docs for this? I did not see one in the API reference.

Currently, there are no examples in docs. You can find the usage of Predictive with SVI in bayesian_regression tutorial and baseball example. I agree that it would be nice to add an example to Predictive. Would you mind making an FR for that? :slight_smile:

Will do, thanks!