I am trying to recover simulated values with an inverse integral projection model. When I run the model, I get the following error:
Rejecting initial value:
Error evaluating the log probability at the initial value.
Initialization between (-5, 5) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
I have tried adjusting the initialization range and supplying initial values with no success. I am sure that the problem is in the parameterization, but I can’t seem to find it. Any help in identifying the problem would be greatly appreciated!
The model and data are attached.
IPM_test2_stan.stan (2.1 KB)
IPM_rdump.R (18.0 KB)
Looking at your model, there’s two things I’d watch out for:
.1. Constraints in transformed parameters work differently than constraints in parameters. In transformed parameters the constraints are only checked but not enforced in the way they are for the parameters block.
If there’s some issue whereby every time Stan picks random initial parameter values that one constraint is being violated, it’ll reject those random parameter values. To test if this is the value, remove your transformed parameter constraints. If things work, you probably have a problem with one of your constaints or your eqs.
.2. Check that you’re initializing all the transformed parameters you’re using. They are by default NaNs, so if they aren’t initialized, then NaNs can sneak through and make the target log density a NaN and the sampler won’t be able to intialize.
If they’re violated, the state is rejected in all the algorithms. The problem is that these rejections destroy the Hamiltonian, so the sampler degrades or even fails.
In the parameters block, we automatically transform to ensure constraints are satisfied (within the bounds of floating point arithmetic, of course).
They don’t need to be initialized where declared, but they all need to be defined before they are used.
Ben and Bob,
Thank you very much for your responses. I have removed constraints on the transformed parameters and get the same error. All of the transformed parameters are defined. The model continues to fail to initialize. I should note that this model does run in JAGS. Do you have any other suggestions?
Thank you for your help.
When I removed the constraints on the parameters, I got the error:
Exception: multiply: Columns of m1 (100) and Rows of m2 (50) must match in size (in '/home/bbales2/Downloads/IPM_test2_stan.stan' at line 91)
Which points to the line
Which I think is wrong cause kern has dimensions
bins x years. The second dimension would need to have length bins for this to make sense.
Not that removing the constraints is a great idea, or that making that matrix bins x bins is going to make the model right. There are probably a few bugs here floating around and making it hard to figure out what’s going wrong. Only solution for that is to build up a big model like this is to start from a small as possible a model.
If you can’t break this model into pieces, then maybe fix some parameters as data and only add one or two at a time?
You can also use
print statements to help you figure out what’s going on (there is a print statement in Stan). The prints that happen before whatever error gets thrown that you’re fighting should make it out.
Thank you very much for finding that error, Ben! I have re-worked the structure of the problematic matrix and the model is running now.