root/library/bdm/base/itpp/signal/fastica.h @ 1407

Revision 1407, 9.4 kB (checked in by sindj, 12 years ago)

Pridany soucasti IT++. signal pro signal processing a stat pro statistiku. JS

Line 
1/*!
2 * \file
3 * \brief Definition of FastICA (Independent Component Analysis) for IT++
4 * \author Francois Cayre and Teddy Furon
5 *
6 * -------------------------------------------------------------------------
7 *
8 * Copyright (C) 1995-2010  (see AUTHORS file for a list of contributors)
9 *
10 * This file is part of IT++ - a C++ library of mathematical, signal
11 * processing, speech processing, and communications classes and functions.
12 *
13 * IT++ is free software: you can redistribute it and/or modify it under the
14 * terms of the GNU General Public License as published by the Free Software
15 * Foundation, either version 3 of the License, or (at your option) any
16 * later version.
17 *
18 * IT++ is distributed in the hope that it will be useful, but WITHOUT ANY
19 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
21 * details.
22 *
23 * You should have received a copy of the GNU General Public License along
24 * with IT++.  If not, see <http://www.gnu.org/licenses/>.
25 *
26 * -------------------------------------------------------------------------
27 *
28 * This is IT++ implementation of the original Matlab package FastICA.
29 *
30 * This code is Copyright (C) 2004 by:
31 *   Francois CAYRE and Teddy FURON
32 *   TEMICS Project
33 *   INRIA/Rennes (IRISA)
34 *   Campus Universitaire de Beaulieu
35 *   35042 RENNES cedex FRANCE
36 *
37 * Email: firstname.lastname@irisa.fr
38 *
39 * Matlab package is Copyright (C) 1998 by:
40 *   Jarmo HURRI, Hugo GAVERT, Jaakko SARELA and Aapo HYVARINEN
41 *   Laboratory of Information and Computer Science
42 *   Helsinki University of Technology
43 *
44 * URL: http://www.cis.hut.fi/projects/ica/fastica/about.shtml
45 *
46 * If you use results given by this FastICA software in an article for
47 * a scientific journal, conference proceedings or similar, please
48 * include the following original reference in the bibliography:
49 *
50 *   A. Hyvarinen, Fast and Robust Fixed-Point Algorithms for
51 *   Independent Component Analysis, IEEE Transactions on Neural
52 *   Networks 10(3):626-634, 1999
53 *
54 * Differences with the original Matlab implementation:
55 * - no GUI
56 * - return something even in the case of a convergence problem
57 * - optimization of SVD decomposition (performed 2 times in Matlab,
58 *   only 1 time in IT++)
59 * - default approach is SYMM with non-linearity POW3
60 */
61
62#ifndef FASTICA_H
63#define FASTICA_H
64
65#include <itpp/base/mat.h>
66
67
68//! Use deflation approach : compute IC one-by-one in a Gram-Schmidt-like fashion
69#define FICA_APPROACH_DEFL 2
70//! Use symmetric approach : compute all ICs at a time
71#define FICA_APPROACH_SYMM 1
72
73//! Use x^3 non-linearity
74#define FICA_NONLIN_POW3 10
75//! Use tanh(x) non-linearity
76#define FICA_NONLIN_TANH 20
77//! Use Gaussian non-linearity
78#define FICA_NONLIN_GAUSS 30
79//! Use skew non-linearity
80#define FICA_NONLIN_SKEW 40
81
82//! Set random start for Fast_ICA
83#define FICA_INIT_RAND  0
84//! Set predefined start for Fast_ICA
85#define FICA_INIT_GUESS 1
86
87//! Eigenvalues of the covariance matrix lower than FICA_TOL are discarded for analysis
88#define FICA_TOL 1e-9
89
90namespace itpp
91{
92
93/*!
94  \addtogroup fastica
95*/
96
97//---------------------- FastICA --------------------------------------
98
99/*!
100\brief Fast_ICA Fast Independent Component Analysis (Fast ICA)
101\ingroup fastica
102
103The software is based upon original FastICA for Matlab from
104A. Hyvarinen. Fast and Robust Fixed-Point Algorithms for
105Independent Component Analysis.  IEEE Transactions on Neural
106Networks, 10(3), pp. 626-634, 1999.
107
108Example:
109\code
110FastICA fastica(sources);
111fastica.set_nrof_independent_components(sources.rows());
112fastica.set_non_linearity(  FICA_NONLIN_TANH );
113fastica.set_approach( FICA_APPROACH_DEFL );
114fastica.separate();
115mat ICs = fastica.get_independent_components();
116\endcode
117*/
118class Fast_ICA
119{
120
121public:
122
123  /*!
124    \brief Constructor
125
126    Construct a Fast_ICA object with mixed signals to separate.
127
128    \param ma_mixed_sig (Input) Mixed signals to separate
129  */
130  Fast_ICA(mat ma_mixed_sig);
131
132  /*!
133    \brief Explicit launch of main FastICA function
134
135    Explicit launch of the Fast_ICA algorithm.
136  */
137  void separate(void);
138
139  /*!
140    \brief Set approach : FICA_APPROACH_DEFL or FICA_APPROACH_SYMM (default)
141
142    Set approach to use : FICA_APPROACH_SYMM (symmetric) or FICA_APPROACH_DEFL (deflation). The symmetric approach computes all ICs at a time, whereas the deflation approach computes them one by one.
143
144    \param in_approach (Input) Type of approach to use
145  */
146  void set_approach(int in_approach);
147
148  /*!
149    \brief Set number of independent components to separate
150
151    Set the number of ICs to compute.
152
153    \param in_nrIC (Input) Number of ICs to compute
154  */
155  void set_nrof_independent_components(int in_nrIC);
156
157  /*!
158    \brief Set non-linearity
159
160    Set non-linearity to use : FICA_NONLIN_POW3 (default),  FICA_NONLIN_TANH, FICA_NONLIN_GAUSS, FICA_NONLIN_SKEW
161
162    \param in_g (Input) Non-linearity. Can be selected from FICA_NONLIN_POW3, FICA_NONLIN_TANH, FICA_NONLIN_GAUSS or FICA_NONLIN_SKEW
163  */
164  void set_non_linearity(int in_g);
165
166  /*!
167    \brief Set fine tuning
168
169    Set fine tuning true or false.
170
171    \param in_finetune (Input) Boolean (true or false)
172  */
173  void set_fine_tune(bool in_finetune);
174
175  /*!
176    \brief Set \f$a_1\f$ parameter
177
178    Set internal parameter \f$a_1\f$ of Fast_ICA (See reference paper).
179
180    \param fl_a1 (Input) Parameter \f$a_1\f$ from reference paper
181  */
182  void set_a1(double fl_a1);
183
184  /*!
185    \brief Set \f$a_2\f$ parameter
186
187    Set internal parameter \f$a_2\f$ of Fast_ICA (See reference paper).
188
189    \param fl_a2 (Input) Parameter \f$a_2\f$ from reference paper
190  */
191  void set_a2(double fl_a2);
192
193  /*!
194    \brief Set \f$\mu\f$ parameter
195
196    Set internal parameter \f$\mu\f$ of Fast_ICA (See reference paper).
197
198    \param fl_mu (Input) Parameter \f$\mu\f$ from reference paper
199  */
200  void set_mu(double fl_mu);
201
202  /*!
203    \brief Set convergence parameter \f$\epsilon\f$
204
205    Set \f$\epsilon\f$ parameter for convergence precision.
206
207    \param fl_epsilon (Input) \f$\epsilon\f$ is convergence precision
208  */
209  void set_epsilon(double fl_epsilon);
210
211  /*!
212    \brief Set sample size
213
214    Set the percentage of samples to take into account at every iteration.
215
216    \param fl_sampleSize (Input) Percentage of data to take into account at every iteration
217  */
218  void set_sample_size(double fl_sampleSize);
219
220  /*!
221    \brief Set stabilization mode true or off
222
223    Set stabilization mode.
224
225    \param in_stabilization (Input) Set stabilization true or false
226  */
227  void set_stabilization(bool in_stabilization);
228
229  /*!
230    \brief Set maximum number of iterations
231
232    Set maximum number of iterations for Fast_ICA.
233
234    \param in_maxNumIterations (Input) Maximum number of iterations to go through
235  */
236  void set_max_num_iterations(int in_maxNumIterations);
237
238  /*!
239    \brief Set maximum number of iterations for fine tuning
240
241    Set maximum numberr of iterations for fine tuning.
242
243    \param in_maxFineTune (Input) Maximum number of iterations for fine tuning stage
244  */
245  void set_max_fine_tune(int in_maxFineTune);
246
247  /*!
248    \brief Set first eigenvalue index to take into account
249
250    Set first eigenvalue index to take into account.
251
252    \param in_firstEig (Input) First eigenvalue index to take into account
253  */
254  void set_first_eig(int in_firstEig);
255
256  /*!
257    \brief Set last eigenvalue index to take into account
258
259    Set last eigenvalue index to take into account.
260
261    \param in_lastEig (Input) Last eigenvalue index to take into account
262  */
263  void set_last_eig(int in_lastEig);
264
265  /*!
266    \brief If true, only perform Principal Component Analysis (default = false)
267
268    Wether to perform PCA only or PCA+ICA.
269
270    \param in_PCAonly (Input) True = PCA only, false = PCA+ICA (default)
271  */
272  void set_pca_only(bool in_PCAonly);
273
274  /*!
275    \brief Set initial guess matrix instead of random (default)
276
277    Set initial matrix instead of random matrix.
278
279    \param ma_initGuess (Input) Initial guess matrix
280  */
281  void set_init_guess(mat ma_initGuess);
282
283
284  /*!
285    \brief Get mixing matrix
286
287    Return mixing matrix.
288
289    \return Mixing matrix
290  */
291  mat get_mixing_matrix();
292
293  /*!
294    \brief Get separating matrix
295
296    Return separating matrix.
297
298    \return Separating matrix
299  */
300  mat get_separating_matrix();
301
302  /*!
303    \brief Get separated signals
304
305    Return separated signals (Independent Components).
306
307    \return ICs
308  */
309  mat get_independent_components();
310
311  /*!
312    \brief Get number of independent components
313
314    Return number of ICs.
315
316    \return Number of ICs
317  */
318  int get_nrof_independent_components();
319
320  /*!
321    \brief Get nrIC first columns of the de-whitening matrix
322
323    Return principal eigenvectors.
324
325    \return Principal eigenvectors
326  */
327  mat get_principal_eigenvectors();
328
329  /*!
330    \brief Get the whitening matrix
331
332    Return whitening matrix.
333
334    \return Whitening matrix
335  */
336  mat get_whitening_matrix();
337
338  /*!
339    \brief Get the de-whitening matrix
340
341    Return dewhitening matrix.
342
343    \return Dewhitening matrix
344  */
345  mat get_dewhitening_matrix();
346
347  /*!
348    \brief Get whitened signals
349
350    Return whitened signals.
351
352    \return Whitened signals
353  */
354  mat get_white_sig();
355
356private:
357
358  int approach, numOfIC, g, initState;
359  bool finetune, stabilization, PCAonly;
360  double a1, a2, mu, epsilon, sampleSize;
361  int maxNumIterations, maxFineTune;
362
363  int firstEig, lastEig;
364
365  mat initGuess;
366
367  mat mixedSig, A, W, icasig;
368
369  mat whiteningMatrix;
370  mat dewhiteningMatrix;
371  mat whitesig;
372
373  mat E, VecPr;
374  vec D;
375
376}; // class Fast_ICA
377
378} // namespace itpp
379
380
381#endif // #ifndef FASTICA_H
Note: See TracBrowser for help on using the browser.