Possible bug in command stan init file


I have a model with a parameter that is a large vector of 17,840 elements. For the model to run, I need to call command stan with the init values.

I created a file for init values of the parameters (both the large one, and a few smaller). However, when calling stan, I get an error about variable dimensions. It seems like no matter what I do to the vector of values in the init file, Stan will only read 1,685 of them. Is there some kind of hard limit in the code?

The error message was:

mismatch in dimension declared and found in context; processing stage=initialization; variable name=student_re; position=0; dims declared=(1685); dims found=(17840)

Note: The init file does contain a vector 17804 elements.

Pretty sure that error is actually telling you that your declared size in the program is 1685, so I would double-check that variable first.

You’re correct, that fixed it.

Can’t believe I missed that. Thanks!

On a side note, it can be a bit cumbersome to have a vector of 0.1 repeated 1600 times. Might be helpful to have a way to indicate a large vector of the same value in the init file. (i.e. alpha[16000] <- 0.1)

The current rdump format is a relic and probably going out the window entirely as soon as somebody on the dev team gets to it.

@sakrejda is right — we (by which I mean he) will be deprecating this as soon as we get the JSON and protobuf implementations in place.

If you are doing that in your data file, may I suggest instead

transformed data {
  vector[K] alpha = rep_vector(0.1, K);

Then you don’t need to pass in constants and you know it’ll match in size by construction (using the intended size K or whatever that is).


I’m attempting to give command Stan suggested starting values for the parameters of the model, using an init file as described on page 54 and 84 of the CmdStan User’s Guide (Version 2.15.0) .

Don’t understand what you mean by doing that in the transformed data block. Don’t the initialisation values need to be in the init file?


Initialization is for parameters. The data is passed in separately. If you have data that’s derivable from other pieces of data, you can define it in the transformed data block, as I showed above for alpha.