c++gaussianprobability-densitydeterminants

c++ - implementing a multivariate probability density function for a likelihood filter


I'm trying to construct a multivariate likelihood function in c++ code with the aim of comparing multiple temperature simulations for consistency with observations but taking into account autocorrelation between the time steps. I am inexperienced in c++ and so have been struggling to understand how to write the equation in c++ form. I have the covariance matrix, the simulations I wish to judge and the observations to compare to. The equation is as follows:

f(x,μ,Σ) = (1/√(∣Σ∣(2π)^d))*exp(−1/2(x-μ)Σ^(-1)(x-μ)')

So I need to find the determinant and the inverse of the covariance matrix. Does anyone know how to do that in c++ if x,μ and Σ are all specified?


Solution

  • I have found a few examples and resources to follow

    https://github.com/dirkschumacher/rcppglm

    https://www.youtube.com/watch?v=y8Kq0xfFF3U&t=953s

    https://www.codeproject.com/Articles/25335/An-Algorithm-for-Weighted-Linear-Regression

    https://www.geeksforgeeks.org/regression-analysis-and-the-best-fitting-line-using-c/

    https://cppsecrets.com/users/489510710111510497118107979811497495464103109971051084699111109/C00-MLPACK-LinearRegression.php

    https://stats.stackexchange.com/questions/146230/how-to-implement-glm-computationally-in-c-or-other-languages