Re: probit problem with vector? [vectorization of CDFs]

56 views
Skip to first unread message

Bob Carpenter

unread,
Apr 21, 2014, 7:20:19 AM4/21/14
to stan...@googlegroups.com
[moving to stan-dev]

On Apr 21, 2014, at 9:53 AM, Andrew Gelman <gel...@stat.columbia.edu> wrote:

> Hi, the following model does not work:
...
> y ~ bernoulli(normal_cdf(X*b,0,1));
>
> But it seems to work when I change the model statement to:
>
> for (n in 1:N)
> y[n] ~ bernoulli(normal_cdf(X[n]*b,0,1));
...

> Is it a problem with vectorization?

That's a feature, not a bug, as they say.

Like our other vectorized functions, normal cdf is defined so that

normal_cdf(v,mu,sigma)

= SUM_k normal_cdf(v[k],mu[k],sigma[k])

The mu and sigma get implicitly broadcast by copying to
a vector if they are scalars.

Although this matches the log density function vectorization behavior,
it doesn't make as much sense to add CDF values!

Should we either (a) un-vectorize these, or (b) change the behavior to
return a vector?

At the very least, I think the doc should be clearer that the vectorization
works the same way for log densities and CDFs.

> I also tried Phi() and the same thing happened.

The version with Phi won't compile because Phi isn't
vectorized. One easy project for some volunteer to take on would
be vectorizing all of our scalar functions. I added some notes on how
we can use functionals and functors to automatically define vectorization
for our scalar functions:

https://github.com/stan-dev/stan/wiki/Functor-Functional-Design-for-Special-Functions

- Bob

Marcus Brubaker

unread,
Apr 21, 2014, 12:01:50 PM4/21/14
to stan...@googlegroups.com
Indeed, in general for all the vectorized functions there is a question about whether we want them to return a scalar sum of values or simply a vector of values.  For instance, people doing WAIC and the like would probably appreciate versions of the _log functions which return a vector of values.  I'm not sure what the solution is here, but I wanted to point out that this is actually connected to a larger issue than just CDFs where the answer is probably clear.  (I.E., summing CDFs almost never makes sense, so we should probably change them to return a vector.)

Cheers,
Marcus




- Bob

--
You received this message because you are subscribed to the Google Groups "stan development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to stan-dev+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages