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:
parent
257c430745
commit
ed4dd14504
13
lib/Math.cpp
13
lib/Math.cpp
@ -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 *
|
||||
******************************************************************************/
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user