You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Stan has a vectorized $\Phi(x)$ (standard cumulative distribution function) but lacks a corresponding vectorized $\varphi(x)$ (standard normal density). You can't get this using std_normal_lpdf(), as it sums the log density values; I'm asking for something that returns a vectorized result.
One use case for a vectorized $\Phi(x)$ is in computing a quasi-hinge function based on $\Phi(x)$:
$h(x) = x \Phi(x) + \varphi(x)$.
This function has range $(0,\infty)$ with $h(x) \to 0$ as $x\to -\infty$, $h(x)/x \to 1$ as $x\to \infty$, and $h'(x) = \Phi(x)$.
We do have a vectorized erf(), so a standard normal is just a factor of sqrt(2) away. Did you want the same signatures as we provide for erf()? That'd be
There are other feature requests asking us to supply vectorized versions of all of our probability functions. They're useful for things like log likelihoods for leave-one-out cross-validation.
Thanks @rok-cesnovar. This is the list you get from using the automatic vectorization of a unary function, which will be an easy way to implement this. Better to provide an analytic gradient for reverse mode. Callingstd_normal_lpdf function to implement unary standard normal is probably too heavy.
Related, I have #2751 which vectorizes the normal_lpdf in a way that allows for a scalar or vector return.
One thing we could do is, if we can agree on the form/code for the normal_lpdf in that branch then this is a good thing to have a swarm of claude's apply through the math library.
Activity
bob-carpenter commentedon Jul 6, 2023
We do have a vectorized
erf(), so a standard normal is just a factor of sqrt(2) away. Did you want the same signatures as we provide forerf()? That'd beThere are other feature requests asking us to supply vectorized versions of all of our probability functions. They're useful for things like log likelihoods for leave-one-out cross-validation.
rok-cesnovar commentedon Jul 7, 2023
The Phi function supports the following signatures in the latest few versions:
bob-carpenter commentedon Jul 7, 2023
Thanks @rok-cesnovar. This is the list you get from using the automatic vectorization of a unary function, which will be an easy way to implement this. Better to provide an analytic gradient for reverse mode. Calling
std_normal_lpdffunction to implement unary standard normal is probably too heavy.SteveBronder commentedon Sep 1, 2026
Related, I have #2751 which vectorizes the
normal_lpdfin a way that allows for a scalar or vector return.One thing we could do is, if we can agree on the form/code for the
normal_lpdfin that branch then this is a good thing to have a swarm of claude's apply through the math library.