9#include <gtest/gtest.h> 
   11#include <tracking/trackFindingVXD/filterTools/DecorrelationMatrix.h> 
   12#include <tracking/trackFindingVXD/filterTools/DecorrelationMatrixHelper.h> 
   25  using TestMatrix = Eigen::Matrix<double, 3, 3, Eigen::RowMajor>;
 
   28  const std::vector<double> 
v1 = {
 
   42  const std::vector<double> 
v2 = {
 
   56  const std::vector<double> 
v3 = {
 
   83      tmpMatrix << 3.132492133948475, 0.974827954209597, -0.761264020048923,
 
   84                0.974827954209597, 1.486186070946439, -0.840189849104485,
 
   86                -0.761264020048923, -0.840189849104485, 0.739017883637750;
 
  106    EXPECT_EQ(3, m_testData.size());
 
  107    for (
const auto& vec : m_testData) { EXPECT_EQ(10, vec.size()); }
 
  114    const auto& internalMatrix = matrix.
getMatrix();
 
  116    for (
auto i = 0; i < internalMatrix.outerSize(); ++i) {
 
  117      for (
auto j = 0; j < internalMatrix.innerSize(); ++j) {
 
  118        EXPECT_DOUBLE_EQ(m_identity(i, j), internalMatrix(i, j));
 
  130    std::vector<double> testVec = { m_testData[0][0], m_testData[1][0], m_testData[2][0] };
 
  131    auto outputVec = matrix.decorrelate(testVec);
 
  132    EXPECT_EQ(testVec.size(), outputVec.size());
 
  135    auto outputData = matrix.decorrelate(m_testData);
 
  137    for (
auto i = 0; i < covMat.outerSize(); ++i) {
 
  138      for (
auto j = 0; j < covMat.innerSize(); ++j) {
 
  140          EXPECT_FLOAT_EQ(m_identity(i, j), covMat(i, j)); 
 
  142          EXPECT_NEAR(m_identity(i, j), covMat(i, j), 1e-15); 
 
  155    EXPECT_EQ(covMat.outerSize(), 3);
 
  156    EXPECT_EQ(covMat.innerSize(), 3);
 
  157    for (
auto i = 0; i < covMat.outerSize(); ++i) {
 
  158      for (
auto j = 0; j < covMat.innerSize(); ++j) {
 
  159        EXPECT_DOUBLE_EQ(m_covMatrix(i, j), covMat(i, j));
 
  164    auto badTestData = m_testData;
 
  165    badTestData[0].erase(badTestData[0].begin()); 
 
  167    EXPECT_EQ(3, badMat.outerSize());
 
  168    EXPECT_EQ(3, badMat.innerSize());
 
  169    EXPECT_TRUE(badMat == m_identity);
 
  177    const char* filename = 
"tmp_matrix_testoutput.dat";
 
  179    ofstream ofs(filename);
 
  181    ofs << covMatrix.
print() << std::endl;
 
  184    ifstream ifs(filename);
 
  186    EXPECT_TRUE(inMatrix.readFromStream(ifs));
 
  189    const TestMatrix& inMat = inMatrix.getMatrix();
 
  190    for (
auto i = 0; i < m_covMatrix.outerSize(); ++i) {
 
  191      for (
auto j = 0; j < m_covMatrix.innerSize(); ++j) {
 
  192        EXPECT_DOUBLE_EQ(m_covMatrix(i, j), inMat(i, j));
 
  196    ASSERT_EQ(0, remove(filename)); 
 
Class holding a Matrix that can be used to decorrelate input data to Machine Learning classifiers.
const MatrixT & getMatrix() const
get the currently stored matrix
TestMatrix m_covMatrix
covariance matrix of the data as calculated via MATLAB
virtual void SetUp()
Fills the data into the internal data structure that is used for testing.
TestMatrix m_identity
provide the identity matrix as class-member since it is used in many testcases
std::array< std::vector< double >, 3 > m_testData
data that is used in the tests
const Eigen::Matrix< double, Ndims, Ndims, Eigen::RowMajor > calculateCovMatrix(std::array< std::vector< double >, Ndims > inputData)
calculates the empirical covariance matrix from the inputData.
void calculateDecorrMatrix(std::array< std::vector< double >, Ndims > inputData, bool normalise=true)
calculate the transformation matrix that when applied to the input data yields linearly uncorrelated ...
std::string print() const
print the matrix to a string.
Abstract base class for different kinds of events.
helper struct for testing purposes providing the necessary coordinate accessors NOTE: this is only te...
const std::vector< double > v3
MATLAB generated random vector.
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > TestMatrix
typedef for less typing effort
const std::vector< double > v2
MATLAB generated random vector.
const std::vector< double > v1
MATLAB generated random vector.