How to calculate the value for a multivariate Gaussian

How to evaluate the value for a multivariate Gaussian. For instance, to evaluate the 20 dimensional Gaussian function value with respect to a 20 dimensional input vector x, I need calculate a 20 by 20 covariance matrix, its inverse and determinant. Is there any available code for this purpose? The computational cost for the determinant and matrix inverse seems very high (I need evaluate thousands of these multivarate Gaussians, so the computational efficiency is quite important). Is there any efficient way to evaluate the value for a multivariate Gaussian? Thanks.

• Do you mean how to estimate a covariance matrix from a sample of Gaussian vectors? Also a $20 \times 20$ matrix is not that big. – dsaxton Mar 4 '16 at 19:37
• Now, what I have is the mean values and coveriance matrics for these gaussians,they are all known, and what I need to do is to evaluate is the values for these gaussians with repsect to a parituclar input vector X which is in a high dimensional space. Since there are thousands of gaussians, and variable dimension is high, the computation is very slow, I want to finger out some way to solve this problem. – J.Doe Mar 4 '16 at 19:42
• There exist all kinds of solutions to this problem; they exploit special structures of the covariance matrices. If your Gaussians are completely generic, with no special structure, you're out of luck. What, then, can you tell us about these Gaussians that might make them special (and therefore amenable to faster computational algorithms)? – whuber Mar 4 '16 at 19:49
• I think they are just the generic gaussians. I simply calculate the coveriance matrics from the training samples, After that, I need calculate the posterior probabilities for a noval input sample using these gaussians, I think they are just generic gaussian without special structure. – J.Doe Mar 4 '16 at 19:54