|
@@ -25,35 +25,35 @@
|
|
|
#include "core/vector/VVector.h"
|
|
|
#include "vislearning/math/pdf/PDFGaussian.h"
|
|
|
|
|
|
-#include "vislearning/nice_nonvis.h"
|
|
|
+#include "objrec/nice_nonvis.h"
|
|
|
|
|
|
using namespace std;
|
|
|
using namespace NICE;
|
|
|
using namespace OBJREC;
|
|
|
|
|
|
-Matrix computeCovariance(const VVector & vecs)
|
|
|
+Matrix computeCovariance ( const VVector & vecs )
|
|
|
{
|
|
|
- Vector mean(vecs[0].size(), 0.0);
|
|
|
+ Vector mean ( vecs[0].size(), 0.0 );
|
|
|
|
|
|
- for (unsigned int i = 0; i < vecs.size(); ++i)
|
|
|
- mean += vecs[i];
|
|
|
-
|
|
|
- mean *= 1.0 / vecs.size();
|
|
|
+ for ( unsigned int i = 0; i < vecs.size(); ++i )
|
|
|
+ mean += vecs[i];
|
|
|
|
|
|
- Matrix cov(vecs[0].size(), vecs[0].size(), 0.0);
|
|
|
+ mean *= 1.0 / vecs.size();
|
|
|
|
|
|
- for (unsigned int i = 0; i < vecs.size(); ++i)
|
|
|
- {
|
|
|
- Vector diff = vecs[i] - mean;
|
|
|
- cov.addTensorProduct ( 1.0, diff, diff );
|
|
|
- }
|
|
|
+ Matrix cov ( vecs[0].size(), vecs[0].size(), 0.0 );
|
|
|
+
|
|
|
+ for ( unsigned int i = 0; i < vecs.size(); ++i )
|
|
|
+ {
|
|
|
+ Vector diff = vecs[i] - mean;
|
|
|
+ cov.addTensorProduct ( 1.0, diff, diff );
|
|
|
+ }
|
|
|
|
|
|
- cov *= 1.0 / ( vecs.size() );
|
|
|
+ cov *= 1.0 / ( vecs.size() );
|
|
|
|
|
|
- return cov;
|
|
|
+ return cov;
|
|
|
}
|
|
|
|
|
|
-CPPUNIT_TEST_SUITE_REGISTRATION(TestPDF);
|
|
|
+CPPUNIT_TEST_SUITE_REGISTRATION ( TestPDF );
|
|
|
|
|
|
|
|
|
|
|
@@ -67,42 +67,42 @@ void TestPDF::tearDown()
|
|
|
|
|
|
void TestPDF::TestPDFComputation()
|
|
|
{
|
|
|
- uint dim = 3;
|
|
|
- bool init_random = true ;
|
|
|
- uint samples = dim*500;
|
|
|
-
|
|
|
- NICE::Matrix C(dim, dim);
|
|
|
- NICE::Vector mean(dim, 0.0);
|
|
|
- VVector samplevectors;
|
|
|
- C.set(0.0);
|
|
|
- cerr << "Sample from Gaussian" << endl;
|
|
|
-
|
|
|
- if (init_random)
|
|
|
- srand48(time(NULL));
|
|
|
-
|
|
|
-
|
|
|
- for (uint i = 0 ; i < dim ; i++)
|
|
|
- for (uint j = i ; j < dim ; j++)
|
|
|
- {
|
|
|
- C(i, j) = drand48();
|
|
|
- C(j, i) = C(i, j);
|
|
|
- }
|
|
|
- C=C*C.transpose();
|
|
|
- cerr << "Ground-Truth covariance" << endl;
|
|
|
- cerr << C << endl;
|
|
|
-
|
|
|
- PDFGaussian pdf_gauss(C, mean);
|
|
|
-
|
|
|
-
|
|
|
- pdf_gauss.sample(samplevectors, samples);
|
|
|
- Matrix Cov_test = computeCovariance(samplevectors);
|
|
|
- cerr << "Estimated covariance" << endl;
|
|
|
- cerr<<Cov_test<<endl;
|
|
|
-
|
|
|
- NICE::Matrix diff = C-Cov_test;
|
|
|
- double frobNorm = diff.frobeniusNorm();
|
|
|
-
|
|
|
- cerr << "Frobenius norm: " << frobNorm << endl;
|
|
|
- CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN(0.0, frobNorm, 0.1);
|
|
|
-
|
|
|
+ uint dim = 3;
|
|
|
+ bool init_random = true ;
|
|
|
+ uint samples = dim * 500;
|
|
|
+
|
|
|
+ NICE::Matrix C ( dim, dim );
|
|
|
+ NICE::Vector mean ( dim, 0.0 );
|
|
|
+ VVector samplevectors;
|
|
|
+ C.set ( 0.0 );
|
|
|
+ cerr << "Sample from Gaussian" << endl;
|
|
|
+
|
|
|
+ if ( init_random )
|
|
|
+ srand48 ( time ( NULL ) );
|
|
|
+
|
|
|
+
|
|
|
+ for ( uint i = 0 ; i < dim ; i++ )
|
|
|
+ for ( uint j = i ; j < dim ; j++ )
|
|
|
+ {
|
|
|
+ C ( i, j ) = drand48();
|
|
|
+ C ( j, i ) = C ( i, j );
|
|
|
+ }
|
|
|
+ C = C * C.transpose();
|
|
|
+ cerr << "Ground-Truth covariance" << endl;
|
|
|
+ cerr << C << endl;
|
|
|
+
|
|
|
+ PDFGaussian pdf_gauss ( C, mean );
|
|
|
+
|
|
|
+
|
|
|
+ pdf_gauss.sample ( samplevectors, samples );
|
|
|
+ Matrix Cov_test = computeCovariance ( samplevectors );
|
|
|
+ cerr << "Estimated covariance" << endl;
|
|
|
+ cerr << Cov_test << endl;
|
|
|
+
|
|
|
+ NICE::Matrix diff = C - Cov_test;
|
|
|
+ double frobNorm = diff.frobeniusNorm();
|
|
|
+
|
|
|
+ cerr << "Frobenius norm: " << frobNorm << endl;
|
|
|
+ CPPUNIT_ASSERT_DOUBLES_EQUAL_NOT_NAN ( 0.0, frobNorm, 0.1 );
|
|
|
+
|
|
|
}
|