Hi, I am dealing with estimating the intensity map of the brain using **Log-Gaussian Cox Processes**.

I get **bad_alloc error** while calculating covariance matrices, **with 64GB of RAM**.

I guess it is from intensive calculation using **cov_exp_quad** for all the voxels.

```
model {
{
matrix[V, V] cov[2];
matrix[V, V] L_cov[2];
matrix[V, K] betas;
// covariance matrix
// for beta0
cov[1] = cov_exp_quad(brain_mask, sigma[1], rho[1])
+ diag_matrix(rep_vector(square(noise[1]), V));
L_cov[1] = cholesky_decompose(cov[1]);
// for beta1
cov[2] = cov_exp_quad(brain_mask, sigma[1], rho[1])
+ diag_matrix(rep_vector(square(noise[2]), V));
L_cov[2] = cholesky_decompose(cov[2]);
// betas are later used for calculaing lambda
betas[,1] = mu[1] + L_cov[1]*eta[1];
betas[,2] = mu[2] + L_cov[2]*eta[2];
}
...
}
```

**The total number of voxels are now 48846**, from 4mm isotropic brain mask.

The number has already been reduced from 352328.

Is there any workaround to get things done?

Would it be a better idea to start using GPUs?

Thank you in advance for all the comments.