Vectorisation of _cdf functions

When used with non-scalar arguments _cdf functions appear to return the sum of the elementwise application of the CDF to the inputs. This is (a) not strictly documented and (b) does not make much sense from an application perspective - in contrast to this behaviour being useful and documented for log probability functions.

I stumbled over the above behaviour trying to obtain a vector of CDF evaluations using the von_mises_cdf function, which is documented as returning type R, when in fact it returns a scalar real, like other _cdf functions in Stan. (See related issue on github).

The general issue popped up briefly on the old google group, and the idea of changing the behaviour was floated then, but I can’t seem to find any further references to this since.

Does this behaviour remain a design choice for _cdf functions? If so I am happy to put in a PR to explicitly add a mention of CDFs to the documentation section clarifying this for log probability functions. If not, is it a good idea to add a feature request to change the _cdf functions to have variable return types like the RNGs or functions like Phi? (Personally I would find this useful.)

1 Like

The vectorised CDFs return the product of the elementwise application of inputs, the vectorised LCDFs return the sum of the log CDFs.

This behaviour is consistent with the vectorised lpdffunctions, since the sum of the log-PDFs is the same as the log of the product of the PDFs

Yes, for reasons @andrjohns mentioned. We can’t change behavior on functions without breaking backward compatibility, so we’re not going to do that. On the other hand, we can always add new functions. We’ve been considering adding _vec versions of the prob functions that return vectors rather than reducing with product (cdf) or sum (all the log functions).

And yes, we’re always happy to take documentation PRs that clarify things that weren’t clear in our doc. The issue you opened in the docs is good and patching that would be really helpful. Thanks for posting the issue.

1 Like

Thanks both! The CDFs do indeed return the product of the elementwise application - my mistake - which makes more sense!
I’ll post another issue in /docs to explicitly add that to the vectorisation section of the manual.

Otherwise, I would find _vec versions of the probability functions useful - certainly if they improved performance over loops, but also simply as syntactic sugar.

1 Like