# Does logp of a variable include its prior?

#1

I have a reference notebook for this question.

As you can see I have a hierarchical model, where a Dirichlet process is the prior for a weight distribution of a gaussian mixture model.

When I calculate the gradient of logp_elemwiset wrt beta, it returns me a value independent of the alpha value.

This is a bit puzzling, because if as listed here https://docs.pymc.io/theano.html in the section “How pymc3 uses Theano?”, the logp value of a variable includes its prior. Then the prior of the beta logp value is a function of alpha. In this model, alpha is a free rv, so beta.logp should return a missing input error.

Even if beta is specified, the prior logP(beta), in logp(beta) as defined by:
logP(Data|beta)+logP(beta)=:logp(beta)
It is a function of alpha.

Can someone explain what value of alpha is being assumed under the hood?

#2

My understanding is that, it does not include its prior. As the logp function of a single RV (element-wise or not) is \pi(y \mid \theta) that depends on only its immediate input \theta, if \theta follows some distribution \theta \sim \pi(\theta \mid \gamma) you need to express that in \pi (y \mid \theta) also.

From the computation perspective in PyMC3, as shown in the doc (small rewrite for clarity):

# For illustration only, those functions don't actually exist
# in exactly this way!
model = pm.Model()

mu = tt.scalar('mu')
mu2 = tt.scalar('mu2')

as you can see, logp_obs is only depends on mu2, which is a theano scaler. You can not take gradient of logp_obs wrt mu, unless you chain the logp together by doing logp_mu2+logp_obs. It is different than say mu2 = function(mu).