|
@@ -1,3 +1,7 @@
|
|
|
+/**
|
|
|
+ * CppUnit-Testcase.
|
|
|
+ * @brief CppUnit-Testcase to verify that all important methods of the gp-hik framework perform as desired
|
|
|
+ */
|
|
|
#ifdef NICE_USELIB_CPPUNIT
|
|
|
|
|
|
#include <string>
|
|
@@ -17,7 +21,9 @@
|
|
|
#include "gp-hik-core/quantization/Quantization.h"
|
|
|
#include "gp-hik-core/quantization/Quantization1DAequiDist0To1.h"
|
|
|
|
|
|
-#include "TestFastHIK.h"
|
|
|
+#include <gp-hik-core/GMHIKernel.h>
|
|
|
+
|
|
|
+#include <gtest/gtest.h>
|
|
|
|
|
|
const bool b_debug = false;
|
|
|
const bool verbose = false;
|
|
@@ -87,15 +93,7 @@ bool compareLUTs(const double* LUT1, const double* LUT2, const int & size, const
|
|
|
using namespace NICE;
|
|
|
using namespace std;
|
|
|
|
|
|
-CPPUNIT_TEST_SUITE_REGISTRATION( TestFastHIK );
|
|
|
-
|
|
|
-void TestFastHIK::setUp() {
|
|
|
-}
|
|
|
-
|
|
|
-void TestFastHIK::tearDown() {
|
|
|
-}
|
|
|
-
|
|
|
-void TestFastHIK::testKernelMultiplication()
|
|
|
+TEST(TestFastHIK,testKernelMultiplication)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelMultiplication ===================== " << std::endl;
|
|
@@ -125,7 +123,7 @@ void TestFastHIK::testKernelMultiplication()
|
|
|
|
|
|
if ( (n*d)>0)
|
|
|
{
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(fmk.getSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
|
|
|
+ ASSERT_NEAR(fmk.getSparsityRatio(), (double)nrZeros/(double)(n*d), 1e-8);
|
|
|
if (verbose)
|
|
|
std::cerr << "fmk.getSparsityRatio(): " << fmk.getSparsityRatio() << " (double)nrZeros/(double)(n*d): " << (double)nrZeros/(double)(n*d) << std::endl;
|
|
|
}
|
|
@@ -169,8 +167,8 @@ void TestFastHIK::testKernelMultiplication()
|
|
|
cerr << "K = " << K << endl;
|
|
|
|
|
|
// check the trace calculation
|
|
|
- //CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
|
|
|
+ //ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
|
|
|
+ ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
|
|
|
|
|
|
// let us compute the kernel multiplication with the slow version
|
|
|
Vector alpha_slow = K*y;
|
|
@@ -178,7 +176,7 @@ void TestFastHIK::testKernelMultiplication()
|
|
|
if (verbose)
|
|
|
std::cerr << "Sparse multiplication [alpha, alpha_slow]: " << std::endl << alpha << std::endl << alpha_slow << std::endl << std::endl;
|
|
|
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL((alpha-alpha_slow).normL1(), 0.0, 1e-8);
|
|
|
+ ASSERT_NEAR((alpha-alpha_slow).normL1(), 0.0, 1e-8);
|
|
|
|
|
|
// test the case, where we first transform and then use the multiply stuff
|
|
|
NICE::GeneralizedIntersectionKernelFunction<double> ghikSlow ( 1.2 );
|
|
@@ -193,12 +191,12 @@ void TestFastHIK::testKernelMultiplication()
|
|
|
|
|
|
Vector galpha_slow = gK * y;
|
|
|
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL((galpha-galpha_slow).normL1(), 0.0, 1e-8);
|
|
|
+ ASSERT_NEAR((galpha-galpha_slow).normL1(), 0.0, 1e-8);
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelMultiplication done ===================== " << std::endl;
|
|
|
}
|
|
|
|
|
|
-void TestFastHIK::testKernelMultiplicationFast()
|
|
|
+TEST(TestFastHIK, testKernelMultiplicationFast)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelMultiplicationFast ===================== " << std::endl;
|
|
@@ -269,8 +267,8 @@ void TestFastHIK::testKernelMultiplicationFast()
|
|
|
cerr << "K = " << K << endl;
|
|
|
|
|
|
// check the trace calculation
|
|
|
- //CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
|
|
|
+ //ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-12 );
|
|
|
+ ASSERT_NEAR( K.trace(), fmk.featureMatrix().hikTrace() + noise*n, 1e-8 );
|
|
|
|
|
|
// let us compute the kernel multiplication with the slow version
|
|
|
Vector alpha_slow = K*y;
|
|
@@ -278,7 +276,7 @@ void TestFastHIK::testKernelMultiplicationFast()
|
|
|
if ( verbose )
|
|
|
std::cerr << "Sparse multiplication [alpha, alphaFast, alpha_slow]: " << std::endl << alpha << std::endl << alphaFast << std::endl << alpha_slow << std::endl << std::endl;
|
|
|
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(0.0, (alphaFast-alpha_slow).normL1(), 1e-8);
|
|
|
+ ASSERT_NEAR(0.0, (alphaFast-alpha_slow).normL1(), 1e-8);
|
|
|
|
|
|
// test the case, where we first transform and then use the multiply stuff
|
|
|
NICE::GeneralizedIntersectionKernelFunction<double> ghikSlow ( 1.2 );
|
|
@@ -305,13 +303,13 @@ void TestFastHIK::testKernelMultiplicationFast()
|
|
|
delete q;
|
|
|
|
|
|
// final assertion
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL((galphaFast-galpha_slow).normL1(), 0.0, 1e-8);
|
|
|
+ ASSERT_NEAR((galphaFast-galpha_slow).normL1(), 0.0, 1e-8);
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelMultiplicationFast done ===================== " << std::endl;
|
|
|
}
|
|
|
|
|
|
|
|
|
-void TestFastHIK::testKernelSum()
|
|
|
+TEST(TestFastHIK, testKernelSum)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelSum ===================== " << std::endl;
|
|
@@ -377,14 +375,14 @@ void TestFastHIK::testKernelSum()
|
|
|
|
|
|
if (verbose)
|
|
|
std::cerr << "difference of beta_slow and betaSparse: " << fabs(beta_slow - betaSparse) << std::endl;
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(beta_slow, betaSparse, 1e-8);
|
|
|
+ ASSERT_NEAR(beta_slow, betaSparse, 1e-8);
|
|
|
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelSum done ===================== " << std::endl;
|
|
|
}
|
|
|
|
|
|
|
|
|
-void TestFastHIK::testKernelSumFast()
|
|
|
+TEST(TestFastHIK, testKernelSumFast)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelSumFast ===================== " << std::endl;
|
|
@@ -513,7 +511,7 @@ void TestFastHIK::testKernelSumFast()
|
|
|
delete [] TlookupOld;
|
|
|
|
|
|
// final assertion
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(beta_slow, beta_fast_sparse, 1e-8);
|
|
|
+ ASSERT_NEAR(beta_slow, beta_fast_sparse, 1e-8);
|
|
|
|
|
|
|
|
|
} // for-loop
|
|
@@ -526,7 +524,7 @@ void TestFastHIK::testKernelSumFast()
|
|
|
|
|
|
}
|
|
|
|
|
|
-void TestFastHIK::testLUTUpdate()
|
|
|
+TEST(TestFastHIK, testLUTUpdate)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testLUTUpdate ===================== " << std::endl;
|
|
@@ -657,14 +655,14 @@ void TestFastHIK::testLUTUpdate()
|
|
|
delete [] TNew;
|
|
|
|
|
|
// final assertion
|
|
|
- CPPUNIT_ASSERT(equal == true);
|
|
|
+ ASSERT_TRUE(equal == true);
|
|
|
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testLUTUpdate done ===================== " << std::endl;
|
|
|
|
|
|
}
|
|
|
|
|
|
-void TestFastHIK::testLinSolve()
|
|
|
+TEST(TestFastHIK, testLinSolve)
|
|
|
{
|
|
|
|
|
|
if (verboseStartEnd)
|
|
@@ -771,13 +769,13 @@ void TestFastHIK::testLinSolve()
|
|
|
delete pf;
|
|
|
|
|
|
// final assertion
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL((K_alphaRandomized-y).normL1(), 0.0, 1e-6);
|
|
|
+ ASSERT_NEAR((K_alphaRandomized-y).normL1(), 0.0, 1e-6);
|
|
|
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testLinSolve done ===================== " << std::endl;
|
|
|
}
|
|
|
|
|
|
-void TestFastHIK::testKernelVector()
|
|
|
+TEST(TestFastHIK, testKernelVector)
|
|
|
{
|
|
|
if (verboseStartEnd)
|
|
|
std::cerr << "================== TestFastHIK::testKernelVector ===================== " << std::endl;
|
|
@@ -833,8 +831,8 @@ void TestFastHIK::testKernelVector()
|
|
|
|
|
|
for (int i = 0; i < 5; i++)
|
|
|
{
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(k1[i]-k1GT[i], 0.0, 1e-6);
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL(k2[i]-k2GT[i], 0.0, 1e-6);
|
|
|
+ ASSERT_NEAR(k1[i]-k1GT[i], 0.0, 1e-6);
|
|
|
+ ASSERT_NEAR(k2[i]-k2GT[i], 0.0, 1e-6);
|
|
|
}
|
|
|
|
|
|
|
|
@@ -843,4 +841,4 @@ void TestFastHIK::testKernelVector()
|
|
|
|
|
|
}
|
|
|
|
|
|
-#endif
|
|
|
+#endif
|