Hi,
i tried to include init parameters to my model via the rstan interface. I have a unitvector unit_vector[2] v_a_mu[K] and filled it with values of the sine and cosine of K angles.
I defined my init function like this:
init_fun <- function(){
v_a_mu <- array(NA, dim = c(K, 2))
kapp <- NULL
d_mu <- NULL
d_sigma <- NULL
values <- list(v_a_mu = v_a_mu, d_mu = d_mu, kapp = kapp, d_sigma = d_sigma, rho_1 = rho_1, rho_2 = rho_2)
return(list(values))
}
and defined my arrays, including v_a_mu, inside the function like this:
v_a_mu[1,1] <- -0.416146836547
v_a_mu[1,2] <- 0.909297426826
v_a_mu[2,1] <- 0.540302305868
v_a_mu[2,2] <- 0.841470984808
v_a_mu[3,1] <- -0.540302305868
v_a_mu[3,2] <- -0.841470984808
v_a_mu[4,1] <- -0.9899924966
v_a_mu[4,2] <- 0.14112000806
v_a_mu[5,1] <- -0.9899924966
v_a_mu[5,2] <- -0.14112000806
v_a_mu[6,1] <- -0.9899924966
v_a_mu[6,2] <- -0.14112000806
v_a_mu[7,1] <- -0.416146836547
v_a_mu[7,2] <- 0.909297426826
This didn’t work, and didn’t work as well when I defined init_r to [-pi, pi], the range of my angles.
Rejecting initial value:
Log probability evaluates to log(0), i.e. negative infinity.
Stan can't start sampling from this initial value.
Initialization between (-3.14159, 3.14159) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
My model works fine if I don"t specify an init, so I thought I’d take the values of v_a_mu which are produced by my stan model when I don’t define a specific init, because with those sampling can be done. I printed them and filled my unitvector
v_a_mu[1,1] <- 0.978121
v_a_mu[1,2] <- 0.208038
v_a_mu[2,1] <- -0.742142
v_a_mu[2,2] <- 0.670242
v_a_mu[3,1] <- 0.624176
v_a_mu[3,2] <- 0.781283
v_a_mu[4,1] <- 0.850055
v_a_mu[4,2] <- 0.526694
v_a_mu[5,1] <- -0.254035
v_a_mu[5,2] <- -0.967195
v_a_mu[6,1] <- -0.42736
v_a_mu[6,2] <- -0.904081
v_a_mu[7,1] <- 0.761295
v_a_mu[7,2] <- -0.648406
And I call my model with
uni <- stan(uni_mu.stan", data = list(K = K, N = N, angle = angle, dist = dist, d_min = d_min), chains = nb_chain, iter = iteration, init = init_fun(), init_r = pi ,cores = 4)
but I get this error messages
SAMPLING FOR MODEL 'uni_mu' NOW (CHAIN 1).
[1] "Error in sampler$call_sampler(args_list[[i]]) : "
[2] " Error transforming variable v_a_mu: stan::io::unit_vector_unconstrain: Vector is not a valid unit vector. The sum of the squares of the elements should be 1, but is 1"
error occurred during calling the sampler; sampling not done
Stan model 'uni_mu' does not contain samples.
I don’t know what my mistake is, but this second error message doesn’t make any sense?
I guess something has to be wrong with my list definition, i can’t think of anything else. Does anyone have an idea?