stan icon indicating copy to clipboard operation
stan copied to clipboard

vector-output log density functions

Open bob-carpenter opened this issue 9 years ago • 4 comments

Idea from Aki Vehtari on stan-dev:

In Stan 2.8, log density functions like normal_log() output the sum of the densities of their components (with appropriate broadcasting of scalars).

It would be nice to allow them to be specified to return a vector, for instance for WAIC or LOO calculations. Aki suggests somethign roughly like

log_lik <- normal_ld<norm=true, sum=false>(y | X * b, sigma);

or maybe with vec=true instead of sum=false.

The result of #1683 will help with implementation.

bob-carpenter avatar Nov 19 '15 19:11 bob-carpenter

Just found this, this would be really useful in many situations.

danielinteractive avatar Dec 23 '21 15:12 danielinteractive

+1. There have been more and more cases where I've wanted to do this. It shouldn't be too hard by decorating the log density functions with one more layer of suffix.

bob-carpenter avatar Dec 30 '21 22:12 bob-carpenter

Yes I think it's very doable as laid out above, mostly need to find time do it. There's a few places we need to be careful but for the most part a couple template tricks should handle everything

SteveBronder avatar Dec 31 '21 05:12 SteveBronder

For me I think my question is whether the <> syntax is the right choice for this? The alternative that comes to my mind is if we add a keyword argument syntax

WardBrian avatar Dec 31 '21 16:12 WardBrian