hello STAN community, I faced troubles with indexing
I want to get mean value and covariance matrix of GP posterior.
GP posterior is, \mathcal{L}(\theta)\vert\mathcal{D} \sim \mathcal{N}(\mu_c(\theta), \Sigma_c(\theta)) (\mathcal{D} is data and \vartheta is observations)
Only want to get \mu_c(\theta), \Sigma_c(\theta) where \theta is 2-dimension.
\mu_c(\theta)= m_c(\theta)+K_{\ast}^T\tilde{K}^{-1}(\mathcal{L}(\vartheta)-m_c(\vartheta))
\Sigma_c(\theta)=K_{\ast,\ast}-K_{\ast}^T\tilde{K}^{-1}K_{\ast}
here is my code.
functions {
vector getmean(row_vector x) {
int J=rows(x);
real m=mean(x);
vector[J] mu=rep_vector(m,J);
return mu;
}
vector getmc(vector mu, matrix k1, matrix k2, vector L, vector mc) {
int N =rows(mu);
vector[N] muc=mu-k1'*inverse(k2)*(L-mc);
return log(muc);
}
matrix getsigmac(matrix k1, matrix k2, matrix k3) {
return k1-k2'*inverse(k3)*k2;
}
}
data {
int<lower=1> J; // number of samples
int<lower=1> N; // number of data points
real<lower=0> alpha; // hyperparameter
real<lower=0> rho; // hyperparameter
// data
row_vector[2] vartheta1[J];
row_vector[2] theta1[N];
vector[J] l1;
}
transformed data {
vector[J] mu11=getmean(vartheta1); // I got error at this line
vector[N] mu12=getmean(theta1); // I got error at this line
matrix[J, J] k13 = cov_exp_quad(vartheta1,vartheta1,alpha,rho);
matrix[N, N] k11 = cov_exp_quad(theta1,theta1,alpha,rho);
matrix[J, N] k12 = cov_exp_quad(vartheta1,theta1,alpha,rho);
matrix[N, N] k1 = getsigmac(k11,k12,k13);
vector[N] k10=diagonal(k1)
vector[N] mu1=getmc(mu12,k11,k13,l1,mu11);
}
generated quantities {
vector[J] mu0=mu;
matrix[N,N] cov=1/2*k0;
}
I got error with this messages.
No matches for:
getmean(row_vector[ ])
Available argument signatures for getmean:
getmean(row_vector)
error in ‘model2e44a2d5469_fit1’ at line 33, column 35
31:
32: transformed data {
33: vector[J] mu11=getmean(vartheta1);
^
34: vector[N] mu12=getmean(theta1);
How can I fix it?
Thank you.