- Bob
On 10/25/13 2:27 PM, Ross Boylan wrote:
> Error message:
> Error in function stan::prob::bernoulli_logit_log(N4stan5agrad3varE):
> Logit transformed probability parameter[1] is nan:0, but must not be
> nan!Rejecting proposed initial value with zero density.
>
> What is causing this and what does nan:0 mean? When I print out the
> relevant values, they also show the :0 suffix. I see the :0 in some
> other output too, suggesting it indicates floating point numbers (rather
> than an error).
The ":0" is an artifact of the way parameters print.
Data will print without it, any parameters, transformed
parameters, or local variables in those blocks or in
the model block will be auto-diff variables. The :0 indicates
the gradient at the time of print.
We should clean up our diagnostic printing. I created an issue
https://github.com/stan-dev/stan/issues/330
but it's not prioritized because it's a lot of work given the
templating involved.
>
> print output:
> 1 theta_x=-8.28481:0
> theta=[3.17291:0,0.70838:0,1.64412:0,0.960729:0,-2.74281:0,1.45019:0,-2.84672:0,-0.110114:0,-1.8066:0,-0.3441:0,-3.47609:0,0.574026:0,-1.21811:0,3.21109:0,0.584489:0,-2.99691:0,1.28483:0,-0.488034:0,-0.805839:0,0.035148:0,2.51912:0,0.652776:0,-2.47\
> 6:0,-0.260721:0,-2.36909:0,3.40766:0,2.68725:0,-1.36023:0]
> alpha_m=-4.58418:0
>
> But if the theta_x value is OK, what's going wrong? is -8 just too
> extreme for it?
-8 isn't too extreme and should not be causing an issue.
The only time you should see the error you saw is if NaN is
passed in for the value. There's only one line in the code that
produces that error report, and it only checks for NaN inputs.
Your input shouldn't be causing an issue. I'm going to try
to create a reproducible isolated test case because with the above
theta_x value, I don't see how you can get the error message you're
getting. If I can't, I'll ask later if I can get your data to reproduce.
> Also, does parameter[1] mean the first argument to bernoulli_logit_log?
> That's just 0 or 1. mnDetail[1] = 1.
Ooh. We should change that, too. It's indexed C++ style from
0 because it's being reported through the API. I'm not sure what
the right thing to do here is, because it's broken in the API if
we do it from 0 and it's broken in the model output from the error
message. Here's another issue:
https://github.com/stan-dev/stan/issues/331
We should at least doc what's going on now.
And we should be giving you credit for the number of these
inconsistencies and errors you've brought to our attention!
>
> Code snippet:
> for (n in 1:N) {
> beta_x[n] <- (x[n] * beta)+alpha[iCluster[n]]+gamma[n];
> theta_x[n] <- (x[n] * theta)+alpha_m[iCluster[n]];
> // print(n, " mnDetail=", mnDetail[n], " beta_x=", beta_x[n], " theta_x=", theta_x[n]);
> // print("x=", x[n], " beta=", beta, " iCluster=", iCluster[n], " alpha=", alpha[iCluster[n]],
> // " gamma=", gamma[n]);
> print(n, " theta_x=", theta_x[n], " theta=", theta, " alpha_m=", alpha_m[iCluster[n]]);
> if (mnDetail[n] == 1)
> //----> next line should be the relevant one for this case
> increment_log_prob(log_sum_exp(bernoulli_logit_log(1, theta_x),
> bernoulli_logit_log(0, theta_x) + poisson_log_log(0, beta_x[n])));
> else {
> increment_log_prob(bernoulli_logit_log(0, theta_x));
> if (mnDetail[n] < 10)
> increment_log_prob(poisson_log_log(mnDetail[n]-1, beta_x[n]));
> else
> increment_log_prob(poisson_ccdf_log(8, exp(beta_x[n])));
> }
Thanks for the code and print output.
- Bob