mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2025-04-10 19:20:44 +01:00
StatArray: correlation matrix calculation
This commit is contained in:
parent
b7a5dd51de
commit
a9bb53bc1b
@ -59,6 +59,7 @@ public:
|
|||||||
const Index n = -1) const;
|
const Index n = -1) const;
|
||||||
T variance(const Index pos = 0, const Index n = -1) const;
|
T variance(const Index pos = 0, const Index n = -1) const;
|
||||||
T varianceMatrix(const Index pos = 0, const Index n = -1) const;
|
T varianceMatrix(const Index pos = 0, const Index n = -1) const;
|
||||||
|
T correlationMatrix(const Index pos = 0, const Index n = -1) const;
|
||||||
public:
|
public:
|
||||||
static const Index offset = os;
|
static const Index offset = os;
|
||||||
};
|
};
|
||||||
@ -218,6 +219,19 @@ T StatArray<T, os>::varianceMatrix(const Index pos, const Index n) const
|
|||||||
return covarianceMatrix(*this, pos, n);
|
return covarianceMatrix(*this, pos, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T, Index os>
|
||||||
|
T StatArray<T, os>::correlationMatrix(const Index pos, const Index n) const
|
||||||
|
{
|
||||||
|
T res = varianceMatrix(pos, n);
|
||||||
|
T invDiag(res.rows(), 1);
|
||||||
|
|
||||||
|
invDiag = res.diagonal();
|
||||||
|
invDiag = invDiag.cwiseInverse().cwiseSqrt();
|
||||||
|
res = (invDiag*invDiag.transpose()).cwiseProduct(res);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
// reduction operations ////////////////////////////////////////////////////////
|
// reduction operations ////////////////////////////////////////////////////////
|
||||||
template <typename T>
|
template <typename T>
|
||||||
inline T ReducOp::sum(const T &a, const T &b)
|
inline T ReducOp::sum(const T &a, const T &b)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user