Hello,
I’ve been having problems initializing simplex variables. I’ve seen this hinted at throughout the discussion boards (old and new, e.g. https://github.com/standev/stan/issues/255). However, it’s not obvious to me if there’s a fix.
Here is a minimum working example: test_simplex_init.R (885 Bytes)
Using this Stan model:
data{
int N;
int V;
int<lower=1,upper=V> x[N];
}
parameters{
simplex[V] nu;
}
model{
nu ~ dirichlet(rep_vector(1.0, V));
for(n in 1:N)
x[n] ~ categorical(nu);
}
I generate data in R, then test parameter recovery. I get the following strange behavior:
 If I don’t initialize parameters, it works fine (i.e. parameters are recovered), regardless of
N
orV
 If I initialize
nu
to be a rounded version of the truth (2 decimals), with some renormalization so that it sums to 1, I get different behavior depending on the value ofV
:
if
V = 10
, everything works as expected 
if
V = 100
, I get:Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can’t start sampling from this initial value.

I encountered similar behavior in a more complicated model, again when trying to initialize a simplex variable. However, in that case, I often get the message:
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: dirichlet_lpmf: probabilities is not a valid simplex. sum(probabilities) = nan, but should be 1
Is this a bug? Is there a workaround, besides for replacing the dirichlet with some unconstrained parameter and then pushing it through softmax?
Thanks,
Ryan