In PyMC3, pm.Deterministic was sufficient to make sure that the point-wise log-likelihood is stored in the output InferenceData (because this only happens automatically for “observed” variables):
with pm.Model() as my_model:
...
# Store the model log-likelihood as well
loglik = pm.Deterministic('log_likelihood', model.logpt)
i.e., The goal is to get InferenceData that looks like this:
Inference data with groups:
> posterior
> log_likelihood
> sample_stats
> observed_data
Whereas without adding pm.Deterministic it looks like this:
Inference data with groups:
> posterior
> sample_stats
However, in PyMC v4.0.0 (pre-release) this generates:
File "/usr/local/dev/mod17/lib/python/mod17/calibration.py", line 751, in compile_npp_model
loglik = pm.Deterministic('log_likelihood', model.logpt)
File "/usr/local/python-env/mod17/lib/python3.10/site-packages/pymc/model.py", line 1886, in Deterministic
var = var.copy(model.name_for(name))
AttributeError: 'function' object has no attribute 'copy'
I think the suggested approach now is to use pm.DensityDist but it’s unclear how to do so from the currently limited API documentation.
Does anyone have an example of using pm.DensityDist for this purpose?