Hello,
I’m trying to dive into PyMC3 source code and I’d like to check my understanding of what is done by Model.logpt()
. Let (x_1,\ldots,x_n) denote the model’s variables, divided into observable variables \mathbf y and free variables \mathbf z.
This is my guess at what logpt()
does:
 it’s goal is computing the log of the unnormalized posterior (since this is what we need for MAP and MCMC)
 the unnormalized posterior is proportional to the joint after clamping the observed variables to their values: p(\mathbf y\mathbf z) \propto p(\mathbf z, \mathbf y), so to get the logunnormalizedposterior it suffices to implement the computation of the joint
 the joint probability is computed using the chain rule relative to the DAG defined by the model: p(x_1,\ldots,x_n) = \prod_i p(x_i\mathrm{pa}_{x_i}) where \mathrm{pa}_{x_i} can include both observed and free nodes

logpt
adds together the logs of the local CPDs and clamps the observed variables to their values
For example take a simple DAG z_1 \rightarrow y_1 \rightarrow z_2 and let y_1 = y_1^* denote the observations, then logpt()
encodes the function (z_1,z_2) \mapsto \log p(z_1,z_2, y_1^*) =\log p(z_2y_1^*) +\log p(y_1^*z_1) + \log p(z_1)
Is this correct? Thanks a lot
(Side question: is FreeRV
used as a synonym for “hidden variable”?).