neg_binomial_2_log_rng

114 views
Skip to first unread message

Linas Mockus

unread,
Oct 2, 2015, 12:01:52 PM10/2/15
to Stan users mailing list
Hi,

For the first chain I am getting the error below while the second chain converges.  Does anybody have any suggestions how to overcome this? This occurs during the warm up.

stan::math::neg_binomial_2_log_rng: Random number that came from gamma distribution is 2.97006e+009, but must be less than 1.07374e+009.  The parameter eta is already constrained as specified in the manual.

The code which generated this error is:
generated quantities {
    int <lower = 0> flow_pred[N];            
   
    for (i in 1:N) {
        real etai;

        etai <- fmin(eta[i], 15);
        flow_pred [i] <- neg_binomial_2_log_rng(etai, phi[i]);
    }
}

Thanks for any suggestions,
Linas

Ben Goodrich

unread,
Oct 2, 2015, 12:52:44 PM10/2/15
to Stan users mailing list
On Friday, October 2, 2015 at 12:01:52 PM UTC-4, Linas Mockus wrote:
The code which generated this error is:
generated quantities {
    int <lower = 0> flow_pred[N];            
   
    for (i in 1:N) {
        real etai;

        etai <- fmin(eta[i], 15);
        flow_pred [i] <- neg_binomial_2_log_rng(etai, phi[i]);
    }
}

Thanks for any suggestions,

The poisson_rng, which is used by neg_binomial_2_log_rng is not very robust. I have worked around this problem with
    real mean_PPD;
    mean_PPD
<- 0;
   
for (n in 1:N) {
        real gamma_temp
;
       
if (is_inf(theta)) gamma_temp <- nu[n];
       
else gamma_temp <- gamma_rng(theta, theta / nu[n]);
       
if (gamma_temp < poisson_max)
          mean_PPD
<- mean_PPD + poisson_rng(gamma_temp);
       
else mean_PPD <- mean_PPD + normal_rng(gamma_temp, sqrt(gamma_temp));
   
}
    mean_PPD
<- mean_PPD / N;

where poisson_max is pow(2.0, 30.0), theta is the overdispersion, and nu is a vector of (positive) parameters. It would be slightly different if you are utilizing the _log variants.

Ben



Linas Mockus

unread,
Oct 2, 2015, 8:29:08 PM10/2/15
to stan-...@googlegroups.com
Ben, thanks a lot.  Should I just ignore this and run more chains?  This never occurs when sampling.  I wonder if it is possible to suppress generated quantities block during warm up?

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/4QkmS65_6pw/unsubscribe.
To unsubscribe from this group and all its topics, send an email to stan-users+...@googlegroups.com.
To post to this group, send email to stan-...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Ben Goodrich

unread,
Oct 2, 2015, 11:00:17 PM10/2/15
to Stan users mailing list
On Friday, October 2, 2015 at 8:29:08 PM UTC-4, Linas Mockus wrote:
I wonder if it is possible to suppress generated quantities block during warm up?

Not in RStan.


Reply all
Reply to author
Forward
0 new messages