Skip to content

Commit

Permalink
fix the broken GMM
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeLing committed Jun 25, 2017
1 parent 9029307 commit 03ab5e9
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions src/shogun/distributions/Gaussian.cpp
Expand Up @@ -13,6 +13,7 @@
#include <shogun/base/Parameter.h>
#include <shogun/distributions/Gaussian.h>
#include <shogun/mathematics/Math.h>
#include <shogun/mathematics/eigen3.h>
#include <shogun/mathematics/lapack.h>
#include <shogun/mathematics/linalg/LinalgNamespace.h>

Expand Down Expand Up @@ -348,19 +349,28 @@ void CGaussian::register_params()

void CGaussian::decompose_cov(SGMatrix<float64_t> cov)
{
SG_PRINT("decompose_cov been called");
switch (m_cov_type)
{
case FULL:
{
m_u = SGMatrix<float64_t>(cov.num_rows, cov.num_rows);
sg_memcpy(
m_u.matrix, cov.matrix,
sizeof(float64_t) * cov.num_rows * cov.num_rows);

m_d.vector = cov.get_diagonal_vector();
m_d.vlen = cov.num_rows;
m_u.num_rows = cov.num_rows;
m_u.num_cols = cov.num_rows;
m_u = cov.clone();
m_d = SGVector<float64_t>(cov.num_rows);
#ifdef HAVE_LAPACK
m_d.vector = SGMatrix<float64_t>::compute_eigenvectors(
m_u.matrix, cov.num_rows, cov.num_rows);
#else
// TODO add eigenvectors computeation
typename SGMatrix<float64_t>::EigenMatrixXtMap eig = m_u;
typename SGVector<float64_t>::EigenVectorXtMap eigenvalues_eig = m_d;

Eigen::EigenSolver<typename SGMatrix<float64_t>::EigenMatrixXt> solver(
eig);
eigenvalues_eig = solver.eigenvalues().real();
#endif
break;
}
case DIAG:
m_d = SGVector<float64_t>(cov.num_rows);
for (int32_t i = 0; i < cov.num_rows; i++)
Expand Down

0 comments on commit 03ab5e9

Please sign in to comment.