Skip to content

Commit

Permalink
Implement inverse transform in ica converters
Browse files Browse the repository at this point in the history
  • Loading branch information
vinx13 authored and vigsterkr committed Jun 4, 2018
1 parent 41659b8 commit b45c31e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/shogun/converter/ica/ICAConverter.cpp
Expand Up @@ -7,6 +7,7 @@
#include <shogun/converter/ica/ICAConverter.h>
#include <shogun/features/DenseFeatures.h>
#include <shogun/mathematics/eigen3.h>
#include <shogun/mathematics/linalg/LinalgNamespace.h>

using namespace shogun;
using namespace Eigen;
Expand Down Expand Up @@ -101,3 +102,21 @@ CFeatures* CICAConverter::transform(CFeatures* features, bool inplace)

return processed;
}

CFeatures* CICAConverter::inverse_transform(CFeatures* features, bool inplace)
{
REQUIRE(m_mixing_matrix.matrix, "ICAConverter has not been fitted.\n");

SG_REF(features);

auto X = features->as<CDenseFeatures<float64_t>>()->get_feature_matrix();
if (!inplace)
X = X.clone();

linalg::matrix_prod(m_mixing_matrix, X, X);

auto processed = new CDenseFeatures<float64_t>(X);
SG_UNREF(features);

return processed;
}
12 changes: 12 additions & 0 deletions src/shogun/converter/ica/ICAConverter.h
Expand Up @@ -48,6 +48,18 @@ namespace shogun
*/
virtual CFeatures* transform(CFeatures* features, bool inplace = true);

/** Inverse apply the ICA converter to features by multiplying the
* feature
* matrix by the mixing matirx.
* @param features the features to transformed, should be an instance of
* CDenseFeatures<float64_t>
* @param inplace transform in place
* @return the result feature object after inverse applying the ICA
* converter
*/
virtual CFeatures*
inverse_transform(CFeatures* features, bool inplace = true);

/** setter for mixing matrix, if the mixing matrix is set it will be
* used as an initial guess if supported by the algorithm
* @param mixing_matrix the initial estimate for the mixing matrix
Expand Down

0 comments on commit b45c31e

Please sign in to comment.