85static int pcamat(
const mat
vectors,
const int numOfIC,
int firstEig,
int lastEig, mat &
Es, vec &
Ds);
87static void whitenv(
const mat
vectors,
const mat E,
const mat D, mat &
newVectors, mat & whiteningMatrix, mat & dewhiteningMatrix);
88static mat
orth(
const mat A);
89static mat
mpower(
const mat A,
const double y);
91static vec
sumcol(
const mat A);
92static bool fpica(
const mat
X,
const mat whiteningMatrix,
const mat dewhiteningMatrix,
const int approach,
const int numOfIC,
const int g,
const int finetune,
const double a1,
const double a2,
double myy,
const int stabilization,
const double epsilon,
const int maxNumIterations,
const int maxFinetune,
const int initState, mat
guess,
double sampleSize, mat & A, mat & W);
111 stabilization =
false;
112 maxNumIterations = 100000;
118 lastEig = mixedSig.rows();
119 numOfIC = mixedSig.rows();
138 guess = mat(initGuess);
140 VecPr =
zeros(mixedSig.rows(), numOfIC);
142 icasig =
zeros(numOfIC, mixedSig.cols());
154 Dim = whitesig.rows();
155 if (numOfIC > Dim) numOfIC = Dim;
163 VecPr.set_col(
i, dewhiteningMatrix.get_col(
i));
168 if (PCAonly ==
false) {
170 result =
fpica(whitesig, whiteningMatrix, dewhiteningMatrix, approach, numOfIC, g, finetune, a1, a2, mu, stabilization, epsilon, maxNumIterations, maxFineTune, initState,
guess, sampleSize, A, W);
172 icasig = W * mixedSig;
262static int pcamat(
const mat
vectors,
const int numOfIC,
int firstEig,
int lastEig, mat &
Es, vec &
Ds)
354 whiteningMatrix =
zeros(E.cols(), E.rows());
355 dewhiteningMatrix =
zeros(E.rows(), E.cols());
357 for (
int i = 0;
i < D.cols();
i++) {
358 whiteningMatrix.set_row(
i, std::pow(std::sqrt(D(
i,
i)), -1)*E.get_col(
i));
359 dewhiteningMatrix.set_col(
i, std::sqrt(D(
i,
i))*E.get_col(
i));
374 double eps = 2.2e-16;
380 if (A.rows() > A.cols()) {
382 U =
U(0,
U.rows() - 1, 0, A.cols() - 1);
383 S =
S(0, A.cols() - 1);
386 mmax = (A.rows() > A.cols()) ? A.rows() : A.cols();
392 Q =
U(0,
U.rows() - 1, 0, r - 1);
397static mat
mpower(
const mat A,
const double y)
400 mat T =
zeros(A.rows(), A.cols());
401 mat
dd =
zeros(A.rows(), A.cols());
402 vec d =
zeros(A.rows());
411 for (
int i = 0;
i < T.cols();
i++) T.set_col(
i, T.get_col(
i) /
norm(T.get_col(
i)));
438 for (
int i = 0;
i < A.cols();
i++) {
out(
i) =
sum(A.get_col(
i)); }
444static bool fpica(
const mat
X,
const mat whiteningMatrix,
const mat dewhiteningMatrix,
const int approach,
const int numOfIC,
const int g,
const int finetune,
const double a1,
const double a2,
double myy,
const int stabilization,
const double epsilon,
const int maxNumIterations,
const int maxFinetune,
const int initState, mat
guess,
double sampleSize, mat & A, mat & W)
450 int gFine = finetune + 1;
463 if (sampleSize != 1.0)
gOrig += 2;
484 else if (
guess.cols() < numOfIC) {
502 else B = whiteningMatrix *
guess;
509 if (
round == maxNumIterations - 1) {
515 A = dewhiteningMatrix * B;
540 A = dewhiteningMatrix * B;
562 else if (!
loong && (
round > maxNumIterations / 2)) {
717 A =
zeros(whiteningMatrix.cols(), numOfIC);
724 while (
round <= numOfIC) {
741 else w = whiteningMatrix *
guess.get_col(
round);
753 while (
i <= maxNumIterations +
gabba) {
761 if (
i == maxNumIterations + 1) {
771 A = dewhiteningMatrix * B;
806 B.set_col(
round - 1, w);
808 A.set_col(
round - 1, dewhiteningMatrix*w);
int size() const
Returns the number of data elements in the array object.
int length() const
Returns the number of data elements in the array object.
mat get_white_sig()
Get whitened signals.
Fast_ICA(mat ma_mixed_sig)
Constructor.
void set_init_guess(mat ma_initGuess)
Set initial guess matrix instead of random (default)
mat get_dewhitening_matrix()
Get the de-whitening matrix.
void set_mu(double fl_mu)
Set parameter.
void set_a1(double fl_a1)
Set parameter.
void set_approach(int in_approach)
Set approach : FICA_APPROACH_DEFL or FICA_APPROACH_SYMM (default)
void set_max_fine_tune(int in_maxFineTune)
Set maximum number of iterations for fine tuning.
void set_pca_only(bool in_PCAonly)
If true, only perform Principal Component Analysis (default = false)
void set_a2(double fl_a2)
Set parameter.
bool separate(void)
Explicit launch of main FastICA function.
mat get_independent_components()
Get separated signals.
void set_first_eig(int in_firstEig)
Set first eigenvalue index to take into account.
void set_sample_size(double fl_sampleSize)
Set sample size.
void set_non_linearity(int in_g)
Set non-linearity.
mat get_mixing_matrix()
Get mixing matrix.
void set_epsilon(double fl_epsilon)
Set convergence parameter .
mat get_whitening_matrix()
Get the whitening matrix.
void set_max_num_iterations(int in_maxNumIterations)
Set maximum number of iterations.
void set_last_eig(int in_lastEig)
Set last eigenvalue index to take into account.
void set_stabilization(bool in_stabilization)
Set stabilization mode true or off.
mat get_separating_matrix()
Get separating matrix.
mat get_principal_eigenvectors()
Get nrIC first columns of the de-whitening matrix.
void set_fine_tune(bool in_finetune)
Set fine tuning.
int get_nrof_independent_components()
Get number of independent components.
void set_nrof_independent_components(int in_nrIC)
Set number of independent components to separate.
Definitions of eigenvalue decomposition functions.
static bool fpica(const mat X, const mat whiteningMatrix, const mat dewhiteningMatrix, const int approach, const int numOfIC, const int g, const int finetune, const double a1, const double a2, double myy, const int stabilization, const double epsilon, const int maxNumIterations, const int maxFinetune, const int initState, mat guess, double sampleSize, mat &A, mat &W)
Local functions for FastICA.
static mat mpower(const mat A, const double y)
Local functions for FastICA.
static vec sumcol(const mat A)
Local functions for FastICA.
static int pcamat(const mat vectors, const int numOfIC, int firstEig, int lastEig, mat &Es, vec &Ds)
Local functions for FastICA.
static void whitenv(const mat vectors, const mat E, const mat D, mat &newVectors, mat &whiteningMatrix, mat &dewhiteningMatrix)
Local functions for FastICA.
static void selcol(const mat oldMatrix, const vec maskVector, mat &newMatrix)
Local functions for FastICA.
static void remmean(mat inVectors, mat &outVectors, vec &meanValue)
Local functions for FastICA.
static mat orth(const mat A)
Local functions for FastICA.
static ivec getSamples(const int max, const double percentage)
Local functions for FastICA.
Definition of FastICA (Independent Component Analysis) for IT++.
#define FICA_INIT_GUESS
Set predefined start for Fast_ICA.
#define FICA_NONLIN_POW3
Use x^3 non-linearity.
#define FICA_INIT_RAND
Set random start for Fast_ICA.
#define FICA_NONLIN_GAUSS
Use Gaussian non-linearity.
#define FICA_APPROACH_SYMM
Use symmetric approach : compute all ICs at a time.
#define FICA_APPROACH_DEFL
Use deflation approach : compute IC one-by-one in a Gram-Schmidt-like fashion.
#define FICA_TOL
Eigenvalues of the covariance matrix lower than FICA_TOL are discarded for analysis.
#define FICA_NONLIN_SKEW
Use skew non-linearity.
#define FICA_NONLIN_TANH
Use tanh(x) non-linearity.
Mat< T > diag(const Vec< T > &v, const int K=0)
Create a diagonal matrix using vector v as its diagonal.
#define it_warning(s)
Display a warning message.
vec tanh(const vec &x)
Tan hyperbolic function.
vec pow(const double x, const vec &y)
Calculates x to the power of y (x^y)
vec exp(const vec &x)
Exp of the elements of a vector x.
int size(const Vec< T > &v)
Length of vector.
T sum(const Vec< T > &v)
Sum of all elements in the vector.
void transpose(const Mat< T > &m, Mat< T > &out)
Transposition of the matrix m returning the transposed matrix in out.
bool svd(const mat &A, vec &S)
Get singular values s of a real matrix A using SVD.
bool eig_sym(const mat &A, vec &d, mat &V)
Calculates the eigenvalues and eigenvectors of a symmetric real matrix.
int mod(int k, int n)
Calculates the modulus, i.e. the signed reminder after division.
T min(const Vec< T > &in)
Minimum value of vector.
T max(const Vec< T > &v)
Maximum value of vector.
int max_index(const Vec< T > &in)
Return the postion of the maximum element in the vector.
double randu(void)
Generates a random uniform (0,1) number.
Mat< T > reshape(const Mat< T > &m, int rows, int cols)
Reshape the matrix into an rows*cols matrix.
mat cov(const mat &X, bool is_zero_mean)
Covariance matrix calculation.
ITPP_EXPORT vec zeros(int size)
A Double vector of zeros.
double norm(const cvec &v)
Calculate the 2-norm: norm(v)=sqrt(sum(abs(v).^2))
double mean(const vec &v)
The mean value.
Various functions on vectors and matrices - header file.
Minimum and maximum functions on vectors and matrices.
Miscellaneous statistics functions and classes - header file.
Mat< T > full(const Sparse_Mat< T > &s)
Convert a sparse matrix s into its dense representation.
Mat< Num_T > concat_horizontal(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Horizontal concatenation of two matrices.
ITPP_EXPORT double round(double x)
Round to nearest integer, return result in double.
Num_T dot(const Vec< Num_T > &v1, const Vec< Num_T > &v2)
Inner (dot) product of two vectors v1 and v2.
const double eps
Constant eps.
ivec to_ivec(const Vec< T > &v)
Converts a Vec<T> to ivec.
Mat< Num_T > elem_mult(const Mat< Num_T > &m1, const Mat< Num_T > &m2)
Element wise multiplication of two matrices.
bin abs(const bin &inbin)
absolute value of bin
Definition of classes for random number generators.
Resampling functions - header file.
Definitions of signal processing functions.
Definitions of special vectors and matrices.
Definitions of Singular Value Decompositions.
Sparse Vector Class definitions.
Trigonometric and hyperbolic functions - header file.