luiarthur / TuringBnpBenchmarks

Benchmarks of Bayesian Nonparametric models in Turing and other PPLs
https://luiarthur.github.io/TuringBnpBenchmarks/
MIT License
29 stars 1 forks source link

Getting log likelihood or log posterior from Turing? #7

Closed luiarthur closed 4 years ago

luiarthur commented 4 years ago

In Turing, is there a way to get something like lp__ in STAN?

trappmartin commented 4 years ago

Is the lp__ field in Stan the log posterior predictive probability?

luiarthur commented 4 years ago

lp__ in STAN is a "scaled" log likelihood. STAN has some clever way of getting rid of proportionality constants, to save on some computation, hence you get a scaled log likelihood (more correctly, log of the scaled likelihood). If done correctly, you can save quite a bit of compute. One issue with this is you have to be careful when using it to compare models. You have to know what exactly what constants are removed in the process.

I would be content with a log likelihood.

EDIT: After some investigation, I think lp__ is actually the log joint probability (likelihood x prior), up to a proportionality constant. I'm struggling to find an exact definition from the STAN page.

trappmartin commented 4 years ago

I think you can use the logprob string macro for this or otherwise maybe also the predict function. We currently don't have a flag that allows you to store the intermediate log joint or log-likelihood values while sampling.

@mohamed82008 is that correct?

mohamed82008 commented 4 years ago

Yes this is correct. The logprob macro is documented here https://turing.ml/dev/docs/using-turing/guide#querying-probabilities-from-model-or-chain.

luiarthur commented 4 years ago

Worked! Thanks.