Permalink
Browse files

Separate covariance matrix computation from projection.

  • Loading branch information...
1 parent e337265 commit 1b9a79cc9fa9dc3bd7cc46d48a6528f4e71b2117 @daviddoria committed Jun 4, 2012
Showing with 15 additions and 6 deletions.
  1. +11 −5 EigenHelpers.cpp
  2. +4 −1 EigenHelpers.h
View
@@ -159,19 +159,16 @@ Eigen::MatrixXf ConstructCovarianceMatrix(const EigenHelpers::VectorOfVectors& v
return covarianceMatrix;
}
-VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vectors,
+EigenHelpers::VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vectors,
+ const Eigen::MatrixXf& covarianceMatrix,
const unsigned int numberOfDimensions)
{
- Eigen::MatrixXf covarianceMatrix = ConstructCovarianceMatrix(vectors);
- std::cout << "covarianceMatrix: " << covarianceMatrix << std::endl;
-
typedef Eigen::JacobiSVD<Eigen::MatrixXf> SVDType;
SVDType svd(covarianceMatrix, Eigen::ComputeFullU | Eigen::ComputeFullV);
// Only keep the first N singular vectors of U
Eigen::MatrixXf truncatedU = TruncateColumns(svd.matrixU(), numberOfDimensions);
-
VectorOfVectors projected;
for(unsigned int i = 0; i < vectors.size(); ++i)
{
@@ -181,4 +178,13 @@ VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vec
return projected;
}
+VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vectors,
+ const unsigned int numberOfDimensions)
+{
+ Eigen::MatrixXf covarianceMatrix = ConstructCovarianceMatrix(vectors);
+ std::cout << "covarianceMatrix: " << covarianceMatrix << std::endl;
+
+ return DimensionalityReduction(vectors, covarianceMatrix, numberOfDimensions);
+}
+
}
View
@@ -51,6 +51,9 @@ Eigen::MatrixXf ConstructCovarianceMatrix(const EigenHelpers::VectorOfVectors& v
EigenHelpers::VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vectors,
const unsigned int numberOfDimensions);
+
+EigenHelpers::VectorOfVectors DimensionalityReduction(const EigenHelpers::VectorOfVectors& vectors,
+ const Eigen::MatrixXf& covarianceMatrix);
}
-
+
#endif

0 comments on commit 1b9a79c

Please sign in to comment.