Hi Andrew,
The answer is almost. The answer below holds for all the univariate distributions, but not necessarily all the multivariate distributions.
Let's take the normal distribution as an example.
target += normal_lpdf(y | mu, sigma);
will always increment the target by:
- log(2 * pi()) - log(sigma) - (y - mu)^2 / (2 * sigma^2)
Always.
It's not so simple for:
y ~ normal(mu, sigma);
It depends on what y, mu, and sigma are. Here are the 8 cases:
parameter y, parameter mu, parameter sigma:
- log(sigma) - (y - mu)^2 / (2 * sigma^2)
// the constant term is dropped
parameter y, parameter mu, data sigma:
- (y - mu)^2 / (2 * sigma^2)
parameter y, data mu, parameter sigma:
- log(sigma) - (y - mu)^2 / (2 * sigma^2)
parameter y, data mu, data sigma:
- (y - mu)^2 / (2 * sigma^2)
data y, parameter mu, parameter sigma:
- log(sigma) - (y - mu)^2 / (2 * sigma^2)
// the constant term is dropped
data y, parameter mu, data sigma:
- (y - mu)^2 / (2 * sigma^2)
data y, data mu, parameter sigma:
- log(sigma) - (y - mu)^2 / (2 * sigma^2)
data y, data mu, data sigma:
0
// that's right. Nothing is computed
Right now, it's more efficient to write y ~ normal(mu, sigma) because we don't compute constants.
For user-defined distributions, it's all the same and will compute the full thing.
Daniel