I am attempting to fit (what I think is) a very straightforward model, I have y that I believe to be generated from a uniform distribution, so:
y \sim \textrm{Uniform}(\alpha, \beta)
Where \alpha and \beta are unknown. I know the data to be positive, so I defined the bounds of the uniform distribution to be positive_ordered and attempted to put priors on where I believe the bounds to be located.
My model code is below:
data {
int<lower=0> N; // num rows
vector[N] y;
}
parameters {
positive_ordered[2] bounds;
}
model {
bounds[1] ~ normal(1180, 10);
bounds[2] ~ normal(1220, 10);
y ~ uniform(bounds[1], bounds[2]);
}
When attempting to fit this, I get the following error:
Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can't start sampling from this initial value.
I have attempted to change my priors, use default priors, change the parameter type, etc. but have been unable to find the bug thatās not allowing this model to be fit. I feel like I have a fundamental misunderstanding of what Stan is doing here. My bet is that Iām not specifying my priors correctly.
I would appreciate any help at tracking down this bug, and more importantly, any explanation as to what Iām missing here would be very helpful. Iām new to Stan and sometimes I run into these issues that I find absolutely bewildering that I know are born from ignorance that makes even knowing how to start debugging a challenge.
Iām just using the default model call with pystan, so the line is:
sm.sampling(data={'N': n, 'y': y})
Where sm is the StanModel compiled from the above code. I see there is an init parameter that defaults to init='random'. I imagine may be the right path to go down.
No change with init=1 ā digging into the documentation for that parameter, I found:
init : {0, '0', 'random', function returning dict, list of dict}, optional
Specifies how initial parameter values are chosen: 0 or '0'
initializes all to be zero on the unconstrained support; 'random'
generates random initial values; list of size equal to the number
of chains (`chains`), where the list contains a dict with initial
parameter values; function returning a dict with initial parameter
values. The function may take an optional argument `chain_id`.
Trying 0, ā0ā and ārandomā get me nowhere, Iām trying to dig into the option to pass a list of dicts into the sampling. Iāve gotten here:
Which gets me closer, it looks like 3 of the 4 chains do properly sample, but the last does not. This feels like Iām doing things in a rather arbitrary fashion, surely there is a better way to approach this?
Went ahead and changed the bounds to (0, 1) for each, got the error:
Initialization between (-2, 2) failed after 1 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
Suppose it could be a pystan issue? I can switch over to R and give it shot there.
Stanās sampler starts by picking a random parameter value that is consistent with the declared constraint (but only the ones in parameters block; transformed parameters and model are ignored). Because this initial value is completely arbitrary it usually very far from both prior and posterior.
After choosing the initial value the HMC algorithm begins gradient ascend like random walk towards the target distribution.
But this only works if the initial point has a gradient. The uniform distribution rejects a parameter value that puts any y outside of the bounds.
positive_ordered only says that the upper bound is larger than the lower bound. In particular, Stan tries to initialize it to a value like [1,2] which is not consistent with your data.
So if Iām understanding correctly ā by setting the parameter limits based on the data, y, Stanās sampler is guaranteed to pick an initialization point that is compatible with the uniform model and thus can appropriately compute a gradient?
Yes. In general the parameter limits should select the region where probability is nonzero so that the sampler knows not to explore āimpossibleā parameter values.