Commit f672e454 authored by Davis King's avatar Davis King

Cleaned up the PCA code slightly.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402724
parent 279e4d40
...@@ -188,6 +188,11 @@ namespace dlib ...@@ -188,6 +188,11 @@ namespace dlib
const double eps = 0.99 const double eps = 0.99
) )
{ {
// You are getting an error here because you are trying to apply PCA
// to a vector of fixed length. But PCA is going to try and do
// dimensionality reduction so you can't use a vector with a fixed dimension.
COMPILE_TIME_ASSERT(matrix_type::NR == 0);
// make sure requires clause is not broken // make sure requires clause is not broken
DLIB_ASSERT(samples.size() > 0, DLIB_ASSERT(samples.size() > 0,
"\tvoid vector_normalizer::train_pca()" "\tvoid vector_normalizer::train_pca()"
...@@ -327,13 +332,9 @@ namespace dlib ...@@ -327,13 +332,9 @@ namespace dlib
total += eigenvalues(r); total += eigenvalues(r);
} }
// so now we know we want to use num_vectors of the first eigenvectors. // So now we know we want to use num_vectors of the first eigenvectors. So
temp.set_size(num_vectors, eigen.nr()); // pull those out and discard the rest.
for (long i = 0; i < num_vectors; ++i) pca = trans(colm(pca,range(0,num_vectors-1)));
{
set_rowm(temp,i) = trans(colm(pca,i));
}
temp.swap(pca);
// Apply the pca transform to the data in x. Then we will normalize the // Apply the pca transform to the data in x. Then we will normalize the
// pca matrix below. // pca matrix below.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment