Hi all,
I have a vector which I would like to initialize. In some settings
this vector has length 1 (the context is a GLM where I might only have
an intercept), which breaks the initialization (I think because R
doesn't distinguish between a scalar and a length one vector).
Consider the super simple model:
data {
int<lower=0> P;
}
parameters {
vector[P] beta;
}
model {
beta ~ normal(0,1);
}
Then both sampling and optimizing are fine if P=2:
sm=stan_model("length_one_vector.stan")
P=2
optimizing(sm, dat=list(P=P), init=list(beta=rep(1,P))) # this is fine
sampling(sm, dat=list(P=P), init=list( list(beta=rep(1,P) ) ),
chains=1) # this is fine
But if P=1 then it fails.
P=1
optimizing(sm, dat=list(P=P), init=list(beta=rep(1,P)))
sampling(sm, dat=list(P=P), init=list( list(beta=rep(1,P) ) ), chains=1)
# Error: Initialization from source failed.
# mismatch in number dimensions declared and found in context;
processing stage=initialization; variable name=beta; dims
declared=(1); dims found=()
Trying to initialization beta as a 1x1 matrix doesn't help:
optimizing(sm, dat=list(P=P), init=list(beta=matrix(1,dat$P,1)))
# Error: Initialization from source failed. mismatch in number
dimensions declared and found in context; processing
stage=initialization; variable name=beta; dims declared=(1); dims
found=(1,1)
Obviously I can work around this by having a special case model for
the P=1 case, but that seems in poor taste. Any thoughts much
appreciated.
Thanks a lot
David.
--
David A. Knowles,
Stanford University.
E-mail:
know...@gmail.com
Web:
http://cs.stanford.edu/~davidknowles/