Belle II Software development
VXDTFFilterTest Namespace Reference

helper struct for testing purposes providing the necessary coordinate accessors NOTE: this is only temporaryly stored in a separate header! More...

Classes

class  DecorrelationMatrixTest
 Test Class. More...
 
struct  TestSpacePoint
 Helper struct for SpacePoint Tests. More...
 

Typedefs

using TestMatrix = Eigen::Matrix< double, 3, 3, Eigen::RowMajor >
 typedef for less typing effort
 

Functions

 TEST_F (DecorrelationMatrixTest, TestSetUp)
 basic test of correct SetUp
 
 TEST_F (DecorrelationMatrixTest, TestConstructor)
 test if the default constructor initializes the internal matrix to the identity matrix
 
 TEST_F (DecorrelationMatrixTest, TestCalculateDecorrMatrix)
 test if the decorrelation matrix is correctly calculated from a given covariance matrix
 
 TEST_F (DecorrelationMatrixTest, TestCaluclateCovMatrix)
 test if the calculation of the covariance matrix is correct
 
 TEST_F (DecorrelationMatrixTest, TestDecorrelationMatrixIO)
 test if the IO methods work as advertised.
 

Variables

const std::vector< double > v1
 MATLAB generated random vector.
 
const std::vector< double > v2
 MATLAB generated random vector.
 
const std::vector< double > v3
 MATLAB generated random vector.
 

Detailed Description

helper struct for testing purposes providing the necessary coordinate accessors NOTE: this is only temporaryly stored in a separate header!

Typedef Documentation

◆ TestMatrix

using TestMatrix = Eigen::Matrix<double, 3, 3, Eigen::RowMajor>

typedef for less typing effort

Definition at line 25 of file decorrelationMatrix.cc.

Function Documentation

◆ TEST_F() [1/5]

TEST_F ( DecorrelationMatrixTest  ,
TestCalculateDecorrMatrix   
)

test if the decorrelation matrix is correctly calculated from a given covariance matrix

Definition at line 124 of file decorrelationMatrix.cc.

125 {
126 DecorrelationMatrix<3> matrix{};
127 matrix.calculateDecorrMatrix(m_testData);
128
129 // test that the size of the input and the output vector does not change
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());
133
134 // test that the covariance matrix of the decorrelated test data is indeed the identity (at least numerically)
135 auto outputData = matrix.decorrelate(m_testData);
136 auto covMat = calculateCovMatrix(outputData);
137 for (auto i = 0; i < covMat.outerSize(); ++i) {
138 for (auto j = 0; j < covMat.innerSize(); ++j) {
139 if (i == j) {
140 EXPECT_FLOAT_EQ(m_identity(i, j), covMat(i, j)); // the diagonal should be ones, even with considering numerics
141 } else {
142 EXPECT_NEAR(m_identity(i, j), covMat(i, j), 1e-15); // EXPECT_FLOAT_EQ is to stringent for the numerical calculations
143 }
144 }
145 }
146
147 // COULDDO: test non-normalized version as well
148 }
Class holding a Matrix that can be used to decorrelate input data to Machine Learning classifiers.
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 ...

◆ TEST_F() [2/5]

TEST_F ( DecorrelationMatrixTest  ,
TestCaluclateCovMatrix   
)

test if the calculation of the covariance matrix is correct

Definition at line 151 of file decorrelationMatrix.cc.

152 {
153 // test if the correct covariance matrix gets calculated
154 const TestMatrix covMat = calculateCovMatrix(m_testData);
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));
160 }
161 }
162
163 // check if an identity matrix is returned if the input is incorrect
164 auto badTestData = m_testData;
165 badTestData[0].erase(badTestData[0].begin()); // remove first element from the first vector in the array
166 const TestMatrix badMat = calculateCovMatrix(badTestData);
167 EXPECT_EQ(3, badMat.outerSize());
168 EXPECT_EQ(3, badMat.innerSize());
169 EXPECT_TRUE(badMat == m_identity);
170 }
Eigen::Matrix< double, 3, 3, Eigen::RowMajor > TestMatrix
typedef for less typing effort

◆ TEST_F() [3/5]

TEST_F ( DecorrelationMatrixTest  ,
TestConstructor   
)

test if the default constructor initializes the internal matrix to the identity matrix

Definition at line 111 of file decorrelationMatrix.cc.

112 {
113 DecorrelationMatrix<3> matrix{};
114 const auto& internalMatrix = matrix.getMatrix();
115
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));
119 }
120 }
121 }
const MatrixT & getMatrix() const
get the currently stored matrix

◆ TEST_F() [4/5]

TEST_F ( DecorrelationMatrixTest  ,
TestDecorrelationMatrixIO   
)

test if the IO methods work as advertised.

First write to and then read in again from a temporary file and then compare the written out and read in matrix

Definition at line 175 of file decorrelationMatrix.cc.

176 {
177 const char* filename = "tmp_matrix_testoutput.dat";
178
179 ofstream ofs(filename);
180 DecorrelationMatrix<3> covMatrix(m_covMatrix);
181 ofs << covMatrix.print() << std::endl;
182 ofs.close();
183
184 ifstream ifs(filename);
185 DecorrelationMatrix<3> inMatrix{};
186 EXPECT_TRUE(inMatrix.readFromStream(ifs));
187 ifs.close();
188
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));
193 }
194 }
195
196 ASSERT_EQ(0, remove(filename)); // assert that the temporarily created file gets deleted again
197 }

◆ TEST_F() [5/5]

TEST_F ( DecorrelationMatrixTest  ,
TestSetUp   
)

basic test of correct SetUp

Definition at line 104 of file decorrelationMatrix.cc.

105 {
106 EXPECT_EQ(3, m_testData.size());
107 for (const auto& vec : m_testData) { EXPECT_EQ(10, vec.size()); }
108 }

Variable Documentation

◆ v1

const std::vector<double> v1
Initial value:
= {
0.537667139546100,
1.833885014595086,
-2.258846861003648,
0.862173320368121,
0.318765239858981,
-1.307688296305273,
-0.433592022305684,
0.342624466538650,
3.578396939725760,
2.769437029884877
}

MATLAB generated random vector.

Definition at line 28 of file decorrelationMatrix.cc.

◆ v2

const std::vector<double> v2
Initial value:
= {
-1.349886940156521,
3.034923466331855,
0.725404224946106,
-0.063054873189656,
0.714742903826096,
-0.204966058299775,
-0.124144348216312,
1.489697607785465,
1.409034489800479,
1.417192413429614
}

MATLAB generated random vector.

Definition at line 42 of file decorrelationMatrix.cc.

◆ v3

const std::vector<double> v3
Initial value:
= {
0.671497133608080,
-1.207486922685038,
0.717238651328838,
1.630235289164729,
0.488893770311789,
1.034693009917860,
0.726885133383238,
-0.303440924786016,
0.293871467096658,
-0.787282803758638
}

MATLAB generated random vector.

Definition at line 56 of file decorrelationMatrix.cc.