Skip to content

Commit

Permalink
PCA bug partially solved
Browse files Browse the repository at this point in the history
  • Loading branch information
mazumdarparijat committed Mar 22, 2014
1 parent a804ca4 commit e20e711
Show file tree
Hide file tree
Showing 3 changed files with 258 additions and 167 deletions.
6 changes: 3 additions & 3 deletions src/shogun/preprocessor/PCA.cpp
Expand Up @@ -172,7 +172,7 @@ bool CPCA::init(CFeatures* features)
{
for (int32_t i=0; i<num_dim; i++)
transformMatrix.col(i) /=
sqrt(eigenValues[i+max_dim_allowed-num_dim]);
sqrt(eigenValues[i+max_dim_allowed-num_dim]*(num_vectors-1)+1e-15);
}
}

Expand Down Expand Up @@ -226,7 +226,7 @@ bool CPCA::init(CFeatures* features)
if (m_whitening)
{
for (int32_t i=0; i<num_dim; i++)
transformMatrix.col(i) /= sqrt(eigenValues[i]);
transformMatrix.col(i) /= sqrt(eigenValues[i]*(num_vectors-1)+1e-15);
}
}

Expand Down Expand Up @@ -274,7 +274,7 @@ SGMatrix<float64_t> CPCA::apply_to_feature_matrix(CFeatures* features)
for (int32_t col=0; col<num_vectors; col++)
{
for (int32_t row=0; row<num_dim; row++)
m.matrix[row*num_dim+col] = feature_matrix(row,col);
m.matrix[col*num_dim+row] = feature_matrix(row,col);
}
m.num_rows = num_dim;
m.num_cols = num_vectors;
Expand Down
6 changes: 3 additions & 3 deletions src/shogun/preprocessor/PCA.h
Expand Up @@ -31,13 +31,13 @@ enum EPCAMethod
/** if N>D then EVD is chosen automatically else SVD is chosen
* (D-dimensions N-number of vectors)
*/
AUTO,
AUTO = 10,
/** SVD based PCA. Time complexity ~14dn^2 (d-dimensions n-number of vectors) */
SVD,
SVD = 20,
/** Eigenvalue decomposition of covariance matrix.
* Time complexity ~10d^3 (d-dimensions n-number of vectors)
*/
EVD
EVD = 30
};

/** mode of pca */
Expand Down

0 comments on commit e20e711

Please sign in to comment.