Hi there, my generated quantities block needs to be vectorized and I appreciate if anyone could help me with that. Here is the code that needs to be vectorized:
generated quantities {
vector[N_pred] y_pred;
for (n in 1:N_pred){
if (bernoulli_logit_rng(X[n] * beta1)) { //beta1 is defined as vector[I], X is a matrix of N_pred * D
y_pred[n] = normal_rng(X[n] * beta2, sigma); //beta2 is defined as vector[I], sigma is a real value
}
}
}
ValueError: SYNTAX ERROR, MESSAGE(S) FROM PARSER:
No matches for:
normal_rng(vector, real)
Available argument signatures for normal_rng:
normal_rng(real, real)
I tried changing sigma to rep_vector(1, N_pred) * sigma to have it as normal_rng(vector, vector) but still get an error. I believe I am doing similar thing to this, so I can not figure out what is wrong. I appreciate if anyone could take a look please.
@maswiebe but it still gives “No matches for normal_rng(vector, vector)”. right? Previously I tried rep_vector(1, N_pred) * sigma to have both mean and var of normal as vectors but it did not work.
The issue here is with the return type actually. The vectorised rng functions will always return an array, rather than a vector. So you just to convert the result to a vector before you assign it to an output:
Hey @andrjohns, is there a way to build on these sensibilities to compute the log_lik with vectorized style syntax, instead of the typical for loop syntax like shown in the loo documentation?