I am modeling multi normal distribution with precision matrix (which currently I’m using the inbuilt function multi_normal_prec
which works fine but extremely slow with large number of variables). Here I am trying to use multi_normal_cholesky
and use transfered parameter MM’ as the covariance matrix, from precision matrix LL’.
Part of my model looks like this (whole stan code attached in the end):
parameters {
vector[D] logit_theta; //
....
....
matrix[D,D] L;
}
transformed parameters {
vector<lower=0,upper=1>[D] theta; //
matrix[D,D] M;
theta = inv_logit(logit_theta);
// Below: let MM' = (LL')^(-1)
M = cholesky_decompose(inverse(multiply_lower_tri_self_transpose(L)));
}
model {
int count;
count = 1;
logit_theta ~ multi_normal_cholesky(rep_vector(0,D), M);
...
...
//each elements in L is assigned separate priors below:
for(j in 1:(D-1)){
for(i in (j+1):D){
L[i,j] ~ normal(0,square(sigma_lower_tri*tau_lower_tri[count]));
count = count+1;
}
L[j,j] ~ normal(0,square(sigma_diag*tau_diag));
}
...
...
}
When sampling, it gives error (only part of it is shown):
Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: cholesky_decompose: m is not symmetric. m[1,2] = 3.66101e+11, but m[2,1] = 3.661e+11 (in ‘model34f863bd86ee_sparse_network’ at line 25)Rejecting initial value:
Error evaluating the log probability at the initial value.
Exception: cholesky_decompose: m is not symmetric. m[1,2] = -5.30476e+15, but m[2,1] = -5.30476e+15 (in ‘model34f863bd86ee_sparse_network’ at line 25)Initialization between (-2, 2) failed after 100 attempts.
Seems that the issue is this line:
M = cholesky_decompose(inverse(multiply_lower_tri_self_transpose(L)));
But the error says the matrix is non-symmetric but to me it seems to be symmetric…? Anyone could suggest where the problem is…? Or is there an alternative way to make multi_normal_prec
faster? Any advises would be appreciated! Thank you.
sparse_network.stan (1.1 KB)