sampling from gamma

66 views
Skip to first unread message

Linas Mockus

unread,
Mar 2, 2015, 9:28:38 PM3/2/15
to stan-...@googlegroups.com
Hi,

For some reason sampling from gamma (u~gamma(0.001, 0.001) gives the following error:
Error :

Initialization between (-2, 2) failed after 100 attempts.
 Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

The same error occurs with any parameter values to gamma.

However, when the sampling statement is commented out the error is not thrown.

Is gamma not functioning correctly? Is there a work around?

Thank you,
Linas
poissongamma.stan

Andrew Gelman

unread,
Mar 2, 2015, 9:30:18 PM3/2/15
to stan-...@googlegroups.com
No, you do not want to be using gamma(.001,.001), I’m pretty sure!

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

Linas Mockus

unread,
Mar 2, 2015, 9:37:56 PM3/2/15
to stan-...@googlegroups.com
Obviously I have tried different combinations 0.001, 1000; 1, 1 - the same result.  I also did gamma(r,1/r), r~cauchy (0, 0.25) without any success.
Thank you,
Linas
 
You received this message because you are subscribed to a topic in the Google Groups "Stan users mailing list" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/stan-users/7wy82PLLlM8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.

Andrew Gelman

unread,
Mar 2, 2015, 9:40:38 PM3/2/15
to stan-...@googlegroups.com
Yes, I figured as much.  I just couldn’t reisst saying something.  That gamma(.001,.001) is a red flag to me!  If you push my buttons, you’re gonna get a beep….

Linas Mockus

unread,
Mar 2, 2015, 9:56:39 PM3/2/15
to stan-...@googlegroups.com
The same with gamma(0.001,1000) and even gamma(1,1).  Beep?!...
Thank you,
Linas
 

Daniel Lee

unread,
Mar 2, 2015, 9:59:11 PM3/2/15
to stan-...@googlegroups.com
I'm wondering if this is related to issue 1308 (https://github.com/stan-dev/stan/issues/1308), but can't tell without data. Have a small simulated dataset you can share?

Bob Carpenter

unread,
Mar 2, 2015, 10:28:14 PM3/2/15
to stan-...@googlegroups.com
The problem is this:

parameters {
vector [N] u;
...
model {
u ~ gamma (0.001, 0.001);
...

You need to constrain the variable u to be positive because
gamma() only has support on (0,inf).

And following Andrew, I'll beep at the extra spaces
before "[" and "(". It makes the programs hard to read
because it violates standard formatting conventions. To me,
i t i s l i k e w r i t i n g t e x t l i k e t h i s .

We seem to get a lot of creative spacing from users in Stan,
some of it derived from R's unusual conventions, such as

return(x) vs. return x

if(foo) vs. if (foo)

line breaks to denote ends of statements vs. semicolons

I find the ones on the left hard to read --- every other language
I know conventionally uses the forms on the right (other than
Python, which uses spaces and line breaks; Lisp and its descendants
where it's all parens, and make, which uses tabs).

- Bob

Bob Carpenter

unread,
Mar 2, 2015, 10:31:55 PM3/2/15
to stan-...@googlegroups.com
I should've added that this is largely our fault for not
supplying error messages for initialization errors (either
user-supplied or random). I thought that got fixed, but
apparently not, as of RStan 2.6, which has:

> fit <- stan(model_code="parameters { vector[100] u; } model { u ~ gamma(1,1); }")

TRANSLATING MODEL 'anon_model' FROM Stan CODE TO C++ CODE NOW.
COMPILING THE C++ CODE FOR MODEL 'anon_model' NOW.

SAMPLING FOR MODEL 'anon_model' NOW (CHAIN 1).
Error :

Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.

error occurred during calling the sampler; sampling not done


I've opened an issue in Stan, which is where the errors should
come from:

https://github.com/stan-dev/stan/issues/1326

- Bob


> On Mar 3, 2015, at 1:59 PM, Daniel Lee <bea...@alum.mit.edu> wrote:
>
Reply all
Reply to author
Forward
0 new messages