Calculating log posterior

I would like to calculate log of posterior (without the constant of proportionality) at MCMC (or other) parameter draws.
Is it possible to get this from STAN’s MCMC output easily?
How about the log of approximate posterior at MCMC or other draws from STAN’s VB output?

In rstan, there is a log_prob function that does this.

Is it also possible to get log of approximate posterior from VB? For VB, I need log(q) not log(priors x likelihood) which seems that log_prob produces even when applied to a fit object from VB

Stan drops more than you may expect—it not only dosn’t normalize after Bayes’s rule, but it’s already dropped a bunch of constants from the joint density. For instance, if you have y ~ normal(0, 3), you don’t get the -sqrt(3) term in the log density, as it’s a constant.

Am I right to think that if one uses “target += normal_lpdf” instead of “normal”, the constant is kept?
I am now looking for a way of calculating the approximate VB log_posterior (with normalizing constant). Can this be somehow obtained using Stan’s VB output? If not, given that the Stan’s VB posterior is a Gaussian distribution with transformations for constrained parameters, I should be able to calculate it myself. But how can I know which transformations have been used?

That is not currently possible.

Yes, that’s right. But it still only gives you the joint density as the final value of target (written out as lp__ still).

There isn’t a built-in way to do this in Stan.

We typically sample from the unconstrained space then transform back to the constrained space. The transforms and Jacobians are detailed in the Stan reference manual.