Cleaned up the PCA code slightly.

--HG--
extra : convert_revision : svn%3Afdd8eb12-d10e-0410-9acb-85c331704f74/trunk%402724
This commit is contained in:
Davis King 2008-12-12 00:31:47 +00:00
parent 279e4d40f2
commit f672e45459
1 changed files with 8 additions and 7 deletions

View File

@ -188,6 +188,11 @@ namespace dlib
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
DLIB_ASSERT(samples.size() > 0,
"\tvoid vector_normalizer::train_pca()"
@ -327,13 +332,9 @@ namespace dlib
total += eigenvalues(r);
}
// so now we know we want to use num_vectors of the first eigenvectors.
temp.set_size(num_vectors, eigen.nr());
for (long i = 0; i < num_vectors; ++i)
{
set_rowm(temp,i) = trans(colm(pca,i));
}
temp.swap(pca);
// So now we know we want to use num_vectors of the first eigenvectors. So
// pull those out and discard the rest.
pca = trans(colm(pca,range(0,num_vectors-1)));
// Apply the pca transform to the data in x. Then we will normalize the
// pca matrix below.