Hi, I use Stan to construct GP models, I model f(x)
as GP with mean
[ m(x) = h(x)^T \beta ]
and covariance function
[ \text{Cov}(x, \tilde{x}) = \sigma^2 C(x, \tilde{x}; \delta)]
Currently I use FitGP.stan to fit my model and deal with p (number of inputs) and Np (number of regression functions) greater than one. My question is could I specify my model where p=1 and Np=1 and how should I specify my beta and delta_par in parameters block. Currently, if I am just running my model as it is, I keep getting a nasty error message about the mismatch of dimensions.
Here is my short model code in R and the stan file enclosed:
Apologies for not posting the error message. Here is my error message when I am trying to specify a constant mean function, i.e. Np = 1.
SAMPLING FOR MODEL āFitGPā NOW (CHAIN 1).
[1] āInitialization from source failed.ā
[2] āmismatch in number dimensions declared and found in context; processing stage=initialization; variable name=beta; dims declared=(1,1); dims found=()ā
[3] "Error in sampler$call_sampler(args_list[[i]]) : "
error occurred during calling the sampler; sampling not done
SAMPLING FOR MODEL āFitGPā NOW (CHAIN 2).
[1] āInitialization from source failed.ā
[2] āmismatch in number dimensions declared and found in context; processing stage=initialization; variable name=beta; dims declared=(1,1); dims found=()ā
[3] "Error in sampler$call_sampler(args_list[[i]]) : "
error occurred during calling the sampler; sampling not done
here are whatever error messages were returned
[[1]]
Stan model āFitGPā does not contain samples.
[[2]]
Stan model āFitGPā does not contain samples.
Stan model āFitGPā does not contain samples.
Error in matrix(ParameterSamples$beta, ncol = 1) :
ādataā must be of a vector type, was āNULLā
In addition: Warning message:
In .local(object, ā¦) :
some chains had errors; consider specifying chains = 1 to debug
I think I do understand this error. When I have Np greater than 1, everything works fine. However, if I specify Np=1, I keep getting this error.
Does it mean that I cannot have beta as a vector of length 1? Is there exist a universal container that I could specify for beta so that it works for any positive integer Np?
In R, explicitly make beta a matrix. There is an ambiguity with R types when dimensions collapse like when Np=1. Stan can handle length 1 and length 0 without a problem.
This is an issue with R which automatically converts single element arrays into scalars which are then no longer recognized as arrays. When creating your initialization list youāll have to replace beta with something like
Still, donāt have any luck with the initialization step:
beta ā array(meanResponse$linModel$coefficients, dim = c(1, 1)
and include it in my init argument of stan function. And I am getting this error:
SAMPLING FOR MODEL āFitGPā NOW (CHAIN 1).
[1] āInitialization from source failed.ā
[2] āmismatch in number dimensions declared and found in context; processing stage=initialization; variable name=beta; dims declared=(1); dims found=(1,1)ā
[3] "Error in sampler$call_sampler(args_list[[i]]) : "
error occurred during calling the sampler; sampling not done
SAMPLING FOR MODEL āFitGPā NOW (CHAIN 2).
[1] āInitialization from source failed.ā
[2] āmismatch in number dimensions declared and found in context; processing stage=initialization; variable name=beta; dims declared=(1); dims found=(1,1)ā
[3] "Error in sampler$call_sampler(args_list[[i]]) : "
error occurred during calling the sampler; sampling not done
here are whatever error messages were returned
[[1]]
Stan model āFitGPā does not contain samples.
[[2]]
Stan model āFitGPā does not contain samples.
Stan model āFitGPā does not contain samples.
Stan model āFitGPā does not contain samples.
This states that the model declares beta as a 1-dimensional vector (dims declared=(1)) where as you defined it as a 1x1 matrix in the initialization file (dims found=(1,1)) which is consistent with the call I gave you. This suggests that you instead use
beta <- array(meanResponse$linModel$coefficients, dim = 1)
Why did I have dim = c(1, 1) before? Because your original error message was
[2] āmismatch in number dimensions declared and found in context; processing stage=initialization; variable name=beta; dims declared=(1,1); dims found=()ā
which states that the model originally requested a 1x1 matrix, so it looks like youāve changed your model since you first asked the question!
Yes, you are right. I did mess around with my model. But I got what you meant with array declaration for beta and now it is working! Thank you all for help!