Skip to content

Commit

Permalink
Add ICA meta examples and cookbook page for fastICA
Browse files Browse the repository at this point in the history
-Also turn UWdge convergence error into warning
-Excluded UWedgeSep for now
  • Loading branch information
karlnapf committed Jul 4, 2017
1 parent e55a014 commit d9c6988
Show file tree
Hide file tree
Showing 10 changed files with 179 additions and 6 deletions.
38 changes: 38 additions & 0 deletions doc/cookbook/source/examples/converter/ica_fast.rst
@@ -0,0 +1,38 @@
==============================
Independent Component Analysis
==============================

Independent component analysis (ICA) separates a multivariate signal into additive subcomponents that are maximally independent.
It is typically used for separating superimposed signals.

The ICA algorithm presented here is fastICA, see :cite:`hyvarinen2000independent` for details.
There are many other ICA implementations, all based on :sgclass:`CICAConverter`

-------
Example
-------

Given a dataset which we assume consists of linearly mixed signals, we create CDenseFeatures
(RealFeatures, here 64 bit float values).

.. sgexample:: ica_fast.sg:create_features

We create the :sgclass:`CFastICA` instance, and set its parameter for the iterative optimization.

.. sgexample:: ica_fast.sg:set_parameters

Then we apply ICA, which gives the unmixed signals.

.. sgexample:: ica_fast.sg:apply_convert

We can also extract the estimated mixing matrix.

.. sgexample:: ica_fast.sg:extract

----------
References
----------
:wiki:`Independent_component_analysis`

.. bibliography:: ../../references.bib
:filter: docname in docnames
8 changes: 4 additions & 4 deletions doc/cookbook/source/index.rst
Expand Up @@ -56,15 +56,15 @@ Statistical Testing

examples/statistical_testing/**

Kernels
-------
Converter
---------

.. toctree::
:maxdepth: 1
:glob:
:caption: Kernels
:caption: Converter

examples/kernel/**
examples/converter/**

Gaussian Processes
------------------
Expand Down
10 changes: 10 additions & 0 deletions doc/cookbook/source/references.bib
Expand Up @@ -153,3 +153,13 @@ @article{Quinonero-Candela2005
year = {2005},
pages = {1939--1959},
}

@article{hyvarinen2000independent,
title={Independent component analysis: algorithms and applications},
author={Hyv{\"a}rinen, A. and Oja, E.},
journal={Neural networks},
volume={13},
number={4},
pages={411--430},
year={2000}
}
24 changes: 24 additions & 0 deletions examples/meta/src/converter/ica_fast.sg
@@ -0,0 +1,24 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)

#![create_features]
RealFeatures features(f_feats)
#![create_features]

#![set_parameters]
FastICA ica()
ica.set_max_iter(200)
ica.set_tol(0.00001)
#![set_parameters]

#![apply_convert]
Features converted = ica.apply(features)
#![apply_convert]

#![extract]
RealMatrix mixing_matrix = ica.get_mixing_matrix()
RealFeatures casted = RealFeatures:obtain_from_generic(converted)
RealMatrix unmixed_signal = casted.get_feature_matrix()
#![extract]

24 changes: 24 additions & 0 deletions examples/meta/src/converter/ica_ff_sep.sg
@@ -0,0 +1,24 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)

#![create_features]
RealFeatures features(f_feats)
#![create_features]

#![set_parameters]
FFSep ica()
ica.set_max_iter(200)
ica.set_tol(0.00001)
#![set_parameters]

#![apply_convert]
Features converted = ica.apply(features)
#![apply_convert]

#![extract]
RealMatrix mixing_matrix = ica.get_mixing_matrix()
RealFeatures casted = RealFeatures:obtain_from_generic(converted)
RealMatrix unmixed_signal = casted.get_feature_matrix()
#![extract]

24 changes: 24 additions & 0 deletions examples/meta/src/converter/ica_jade.sg
@@ -0,0 +1,24 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)

#![create_features]
RealFeatures features(f_feats)
#![create_features]

#![set_parameters]
Jade ica()
ica.set_max_iter(200)
ica.set_tol(0.00001)
#![set_parameters]

#![apply_convert]
Features converted = ica.apply(features)
#![apply_convert]

#![extract]
RealMatrix mixing_matrix = ica.get_mixing_matrix()
RealFeatures casted = RealFeatures:obtain_from_generic(converted)
RealMatrix unmixed_signal = casted.get_feature_matrix()
#![extract]

24 changes: 24 additions & 0 deletions examples/meta/src/converter/ica_jedi_sep.sg
@@ -0,0 +1,24 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)

#![create_features]
RealFeatures features(f_feats)
#![create_features]

#![set_parameters]
JediSep ica()
ica.set_max_iter(200)
ica.set_tol(0.00001)
#![set_parameters]

#![apply_convert]
Features converted = ica.apply(features)
#![apply_convert]

#![extract]
RealMatrix mixing_matrix = ica.get_mixing_matrix()
RealFeatures casted = RealFeatures:obtain_from_generic(converted)
RealMatrix unmixed_signal = casted.get_feature_matrix()
#![extract]

24 changes: 24 additions & 0 deletions examples/meta/src/converter/ica_sobi.sg
@@ -0,0 +1,24 @@
CSVFile f_feats("../../data/ica_2_sources.dat")

Math:init_random(1)

#![create_features]
RealFeatures features(f_feats)
#![create_features]

#![set_parameters]
SOBI ica()
ica.set_max_iter(200)
ica.set_tol(0.00001)
#![set_parameters]

#![apply_convert]
Features converted = ica.apply(features)
#![apply_convert]

#![extract]
RealMatrix mixing_matrix = ica.get_mixing_matrix()
RealFeatures casted = RealFeatures:obtain_from_generic(converted)
RealMatrix unmixed_signal = casted.get_feature_matrix()
#![extract]

7 changes: 6 additions & 1 deletion src/shogun/mathematics/ajd/UWedge.cpp
Expand Up @@ -113,7 +113,12 @@ SGMatrix<float64_t> CUWedge::diagonalize(SGNDArray<float64_t> C, SGMatrix<float6
}

if (iter == itermax)
SG_SERROR("Convergence not reached\n")
{
SG_SWARNING(
"Convergence delta (%f) not below tolerance (%f) after %d "
"iterations.\n",
improve, eps, itermax);
}

return V;

Expand Down

0 comments on commit d9c6988

Please sign in to comment.