mirror of
https://github.com/aportelli/LatAnalyze.git
synced 2024-11-10 00:45:36 +00:00
StatArray: correlation matrix calculation
This commit is contained in:
parent
b7a5dd51de
commit
a9bb53bc1b
@ -59,6 +59,7 @@ public:
|
||||
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 correlationMatrix(const Index pos = 0, const Index n = -1) const;
|
||||
public:
|
||||
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);
|
||||
}
|
||||
|
||||
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 ////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
inline T ReducOp::sum(const T &a, const T &b)
|
||||
|
Loading…
Reference in New Issue
Block a user