issues with truncated distributions

14 views
Skip to first unread message

Bob Carpenter

unread,
Mar 12, 2013, 6:06:48 PM3/12/13
to stan...@googlegroups.com, stan-...@googlegroups.com
Many of the CDFs we just released have a bug relating
to the boundary behavior when given constants rather
than variables to evaluate.

This will affect truncated distributions that have
constant (i.e., not a parameter, transformed parameter
or local model variable) values.

For efficiency sake, you should NOT be truncating with respect
to constant truncation points in Stan. Just define the
variate in question to be bounded. So rather than this:

parameters {
real y;
}
model {
y ~ normal(0,1) T[-1,1];
}

for a unit normal truncated to [-1,1], use this:

parameters {
real<lower=-1,upper=1> y;
}
model {
y ~ normal(0,1);
}

Having said that, we need to fix this bug.
For the dev team, here's an example of the issue in
neg_binomial CDF:

// Return if everything is constant and only proportionality is required
if (!include_summand<propto,T_shape,T_inv_scale>::value)
return 0.0;

Because the CDFs are on the linear scale, not a log
scale, this should be returning 1.0, not 0.0.

- Bob



Michael Betancourt

unread,
Mar 12, 2013, 6:18:46 PM3/12/13
to stan...@googlegroups.com
Gah, I thought I had caught those. Unfortunately I only went through the continuous distributions, which don't have a propto template argument in the CDFs (should they?). I'll fixed the discrete distributions tonight.
> --
> 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/groups/opt_out.
>
>

Michael Betancourt

unread,
Mar 12, 2013, 6:24:52 PM3/12/13
to stan...@googlegroups.com
And by tonight I mean right now. Let me know if we should add the propto arguments to the continuous CDFs (they weren't in the examples from which I worked, so I didn't add them).

On Mar 12, 2013, at 3:06 PM, Bob Carpenter wrote:

Marcus Brubaker

unread,
Mar 12, 2013, 6:35:13 PM3/12/13
to stan...@googlegroups.com
Bob, are you sure that's correct?  Don't you need to always truncate explicitly if any parameters are variables?  E.G., in

parameters {
  real<lower=0> sigma;
  real<lower=-1,upper=1> y;
}

this:

model {
    y ~ normal(0,sigma); 
 }

will produce an incorrect model because the normalization constant for a truncated normal depends on both the truncation points and the parameters.

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+unsubscribe@googlegroups.com.

Bob Carpenter

unread,
Mar 12, 2013, 6:58:31 PM3/12/13
to stan...@googlegroups.com
On 3/12/13 6:35 PM, Marcus Brubaker wrote:

> Bob, are you sure that's correct?

My original post is admittedly confusing. So let me
try to clarify.

We need both the truncation points AND the parameters to be
constant (but not the variate).

So in

y ~ normal(mu,sigma) T[L,H];

you don't need the truncation if mu, sigma, L, and H
are all constants.

I used an example from the negative binomial, where
the variate is an int, and can't be a parameter:

if (!include_summand<propto,T_shape,T_inv_scale>::value)
return 0.0;

To make this work properly for truncation, the return should
be 1.0. For the normal, we need T_y, T_loc, T_scale in
the include_summand.

But I don't think that really makes sense for "propto" independently
for CDFs.

- Bob

Bob Carpenter

unread,
Mar 12, 2013, 7:06:48 PM3/12/13
to stan...@googlegroups.com
I'm not sure any of the CDFs should have propto
template parameters. If they do, they have to
return 1 to make sense.

I'm OK with not having the propto and just leaving
it up to the users to not include them.

It's probably rare that the case they go away ever
comes up, but you see it in a lot of user code for
the uniform, for which I don't think we even have
a CDF yet!

- Bob
Reply all
Reply to author
Forward
0 new messages