1
0
mirror of https://github.com/aportelli/LatAnalyze.git synced 2024-11-10 00:45:36 +00:00

function to convert a variance matrix into a correlation matrix

This commit is contained in:
Antonin Portelli 2016-04-05 20:56:21 +01:00
parent 257c430745
commit ed4dd14504
2 changed files with 16 additions and 0 deletions

View File

@ -24,6 +24,19 @@
using namespace std;
using namespace Latan;
/******************************************************************************
* Custom math functions *
******************************************************************************/
DMat MATH_NAMESPACE::varToCorr(const DMat &var)
{
DMat res = var, invDiag = res.diagonal();
invDiag = invDiag.cwiseInverse().cwiseSqrt();
res = (invDiag*invDiag.transpose()).cwiseProduct(res);
return res;
}
/******************************************************************************
* Standard C functions *
******************************************************************************/

View File

@ -68,6 +68,9 @@ namespace MATH_NAMESPACE
return res;
}
// convert variance matrix to correlation matrix
DMat varToCorr(const DMat &var);
// Constants
const double pi = 3.1415926535897932384626433832795028841970;
const double e = 2.7182818284590452353602874713526624977572;