I have FastICA (INDEPENDENT COMPONENT ANALYSIS) Version 2.5 but i don't understand the code given in it can any one please help me to make Understandaeble I know what is ICA but i didn't understand the code in it pls explain it?

132 views (last 30 days)
This function gives me Mixed signals
function [sig,mixedsig]=demosig();
%
% function [sig,mixedsig]=demosig();
%
% Returns artificially generated test signals, sig, and mixed
% signals, mixedsig. Signals are row vectors of
% matrices. Input mixedsig to FastICA to see how it works.
% @(#)$Id: demosig.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $
%create source signals (independent components)
N=500; %data size
v=[0:N-1];
sig=[];
sig(1,:)=sin(v/2); %sinusoid
sig(2,:)=((rem(v,23)-11)/9).^5; %funny curve
sig(3,:)=((rem(v,27)-13)/9); %saw-tooth
sig(4,:)=((rand(1,N)<.5)*2-1).*log(rand(1,N)); %impulsive noise
for t=1:4
sig(t,:)=sig(t,:)/std(sig(t,:));
end
%remove mean (not really necessary)
[sig mean]=remmean(sig);
%create mixtures
Aorig=rand(size(sig,1));
mixedsig=(Aorig*sig);
2) Fast ICA function i want what's behind this code
function [Out1, Out2, Out3] = fastica(mixedsig, varargin)
%FASTICA - Fast Independent Component Analysis
%
% FastICA for Matlab 7.x and 6.x
% Version 2.5, October 19 2005
% Copyright (c) Hugo Gävert, Jarmo Hurri, Jaakko Särelä, and Aapo Hyvärinen.
%
% FASTICA(mixedsig) estimates the independent components from given
% multidimensional signals. Each row of matrix mixedsig is one
% observed signal. FASTICA uses Hyvarinen's fixed-point algorithm,
% see http://www.cis.hut.fi/projects/ica/fastica/. Output from the
% function depends on the number output arguments:
%
% [icasig] = FASTICA (mixedsig); the rows of icasig contain the
% estimated independent components.
%
% [icasig, A, W] = FASTICA (mixedsig); outputs the estimated separating
% matrix W and the corresponding mixing matrix A.
%
% [A, W] = FASTICA (mixedsig); gives only the estimated mixing matrix
% A and the separating matrix W.
%
% Some optional arguments induce other output formats, see below.
%
% A graphical user interface for FASTICA can be launched by the
% command FASTICAG
%
% FASTICA can be called with numerous optional arguments. Optional
% arguments are given in parameter pairs, so that first argument is
% the name of the parameter and the next argument is the value for
% that parameter. Optional parameter pairs can be given in any order.
%
% OPTIONAL PARAMETERS:
%
% Parameter name Values and description
%
%======================================================================
% --Basic parameters in fixed-point algorithm:
%
% 'approach' (string) The decorrelation approach used. Can be
% symmetric ('symm'), i.e. estimate all the
% independent component in parallel, or
% deflation ('defl'), i.e. estimate independent
% component one-by-one like in projection pursuit.
% Default is 'defl'.
%
% 'numOfIC' (integer) Number of independent components to
% be estimated. Default equals the dimension of data.
%
%======================================================================
% --Choosing the nonlinearity:
%
% 'g' (string) Chooses the nonlinearity g used in
% the fixed-point algorithm. Possible values:
%
% Value of 'g': Nonlinearity used:
% 'pow3' (default) g(u)=u^3
% 'tanh' g(u)=tanh(a1*u)
% 'gauss g(u)=u*exp(-a2*u^2/2)
% 'skew' g(u)=u^2
%
% 'finetune' (string) Chooses the nonlinearity g used when
% fine-tuning. In addition to same values
% as for 'g', the possible value 'finetune' is:
% 'off' fine-tuning is disabled.
%
% 'a1' (number) Parameter a1 used when g='tanh'.
% Default is 1.
% 'a2' (number) Parameter a2 used when g='gaus'.
% Default is 1.
%
% 'mu' (number) Step size. Default is 1.
% If the value of mu is other than 1, then the
% program will use the stabilized version of the
% algorithm (see also parameter 'stabilization').
%
%
% 'stabilization' (string) Values 'on' or 'off'. Default 'off'.
% This parameter controls wether the program uses
% the stabilized version of the algorithm or
% not. If the stabilization is on, then the value
% of mu can momentarily be halved if the program
% senses that the algorithm is stuck between two
% points (this is called a stroke). Also if there
% is no convergence before half of the maximum
% number of iterations has been reached then mu
% will be halved for the rest of the rounds.
%
%======================================================================
% --Controlling convergence:
%
% 'epsilon' (number) Stopping criterion. Default is 0.0001.
%
% 'maxNumIterations' (integer) Maximum number of iterations.
% Default is 1000.
%
% 'maxFinetune' (integer) Maximum number of iterations in
% fine-tuning. Default 100.
%
% 'sampleSize' (number) [0 - 1] Percentage of samples used in
% one iteration. Samples are chosen in random.
% Default is 1 (all samples).
%
% 'initGuess' (matrix) Initial guess for A. Default is random.
% You can now do a "one more" like this:
% [ica, A, W] = fastica(mix, 'numOfIC',3);
% [ica2, A2, W2] = fastica(mix, 'initGuess', A, 'numOfIC', 4);
%
%======================================================================
% --Graphics and text output:
%
% 'verbose' (string) Either 'on' or 'off'. Default is
% 'on': report progress of algorithm in text format.
%
% 'displayMode' (string) Plot running estimates of independent
% components: 'signals', 'basis', 'filters' or
% 'off'. Default is 'off'.
%
% 'displayInterval' Number of iterations between plots.
% Default is 1 (plot after every iteration).
%
%======================================================================
% --Controlling reduction of dimension and whitening:
%
% Reduction of dimension is controlled by 'firstEig' and 'lastEig', or
% alternatively by 'interactivePCA'.
%
% 'firstEig' (integer) This and 'lastEig' specify the range for
% eigenvalues that are retained, 'firstEig' is
% the index of largest eigenvalue to be
% retained. Default is 1.
%
% 'lastEig' (integer) This is the index of the last (smallest)
% eigenvalue to be retained. Default equals the
% dimension of data.
%
% 'interactivePCA' (string) Either 'on' or 'off'. When set 'on', the
% eigenvalues are shown to the user and the
% range can be specified interactively. Default
% is 'off'. Can also be set to 'gui'. Then the user
% can use the same GUI that's in FASTICAG.
%
% If you already know the eigenvalue decomposition of the covariance
% matrix, you can avoid computing it again by giving it with the
% following options:
%
% 'pcaE' (matrix) Eigenvectors
% 'pcaD' (matrix) Eigenvalues
%
% If you already know the whitened data, you can give it directly to
% the algorithm using the following options:
%
% 'whiteSig' (matrix) Whitened signal
% 'whiteMat' (matrix) Whitening matrix
% 'dewhiteMat' (matrix) dewhitening matrix
%
% If values for all the 'whiteSig', 'whiteSig' and 'dewhiteMat' are
% supplied, they will be used in computing the ICA. PCA and whitening
% are not performed. Though 'mixedsig' is not used in the main
% algorithm it still must be entered - some values are still
% calculated from it.
%
% Performing preprocessing only is possible by the option:
%
% 'only' (string) Compute only PCA i.e. reduction of
% dimension ('pca') or only PCA plus whitening
% ('white'). Default is 'all': do ICA estimation
% as well. This option changes the output
% format accordingly. For example:
%
% [whitesig, WM, DWM] = FASTICA(mixedsig,
% 'only', 'white')
% returns the whitened signals, the whitening matrix
% (WM) and the dewhitening matrix (DWM). (See also
% WHITENV.) In FastICA the whitening matrix performs
% whitening and the reduction of dimension. Dewhitening
% matrix is the pseudoinverse of whitening matrix.
%
% [E, D] = FASTICA(mixedsig, 'only', 'pca')
% returns the eigenvector (E) and diagonal
% eigenvalue (D) matrices containing the
% selected subspaces.
%
%======================================================================
% EXAMPLES
%
% [icasig] = FASTICA (mixedsig, 'approach', 'symm', 'g', 'tanh');
% Do ICA with tanh nonlinearity and in parallel (like
% maximum likelihood estimation for supergaussian data).
%
% [icasig] = FASTICA (mixedsig, 'lastEig', 10, 'numOfIC', 3);
% Reduce dimension to 10, and estimate only 3
% independent components.
%
% [icasig] = FASTICA (mixedsig, 'verbose', 'off', 'displayMode', 'off');
% Don't output convergence reports and don't plot
% independent components.
%
%
% A graphical user interface for FASTICA can be launched by the
% command FASTICAG
%
% See also FASTICAG
% @(#)$Id: fastica.m,v 1.14 2005/10/19 13:05:34 jarmo Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Check some basic requirements of the data
if nargin == 0,
error ('You must supply the mixed data as input argument.');
end
if length (size (mixedsig)) > 2,
error ('Input data can not have more than two dimensions.');
end
if any (any (isnan (mixedsig))),
error ('Input data contains NaN''s.');
end
if ~isa (mixedsig, 'double')
fprintf ('Warning: converting input data into regular (double) precision.\n');
mixedsig = double (mixedsig);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Remove the mean and check the data
[mixedsig, mixedmean] = remmean(mixedsig);
[Dim, NumOfSampl] = size(mixedsig);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Default values for optional parameters
% All
verbose = 'on';
% Default values for 'pcamat' parameters
firstEig = 1;
lastEig = Dim;
interactivePCA = 'off';
% Default values for 'fpica' parameters
approach = 'defl';
numOfIC = Dim;
g = 'pow3';
finetune = 'off';
a1 = 1;
a2 = 1;
myy = 1;
stabilization = 'off';
epsilon = 0.0001;
maxNumIterations = 1000;
maxFinetune = 5;
initState = 'rand';
guess = 0;
sampleSize = 1;
displayMode = 'off';
displayInterval = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Parameters for fastICA - i.e. this file
b_verbose = 1;
jumpPCA = 0;
jumpWhitening = 0;
only = 3;
userNumOfIC = 0;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Read the optional parameters
if (rem(length(varargin),2)==1)
error('Optional parameters should always go by pairs');
else
for i=1:2:(length(varargin)-1)
if ~ischar (varargin{i}),
error (['Unknown type of optional parameter name (parameter' ...
' names must be strings).']);
end
% change the value of parameter
switch lower (varargin{i})
case 'stabilization'
stabilization = lower (varargin{i+1});
case 'maxfinetune'
maxFinetune = varargin{i+1};
case 'samplesize'
sampleSize = varargin{i+1};
case 'verbose'
verbose = lower (varargin{i+1});
% silence this program also
if strcmp (verbose, 'off'), b_verbose = 0; end
case 'firsteig'
firstEig = varargin{i+1};
case 'lasteig'
lastEig = varargin{i+1};
case 'interactivepca'
interactivePCA = lower (varargin{i+1});
case 'approach'
approach = lower (varargin{i+1});
case 'numofic'
numOfIC = varargin{i+1};
% User has supplied new value for numOfIC.
% We'll use this information later on...
userNumOfIC = 1;
case 'g'
g = lower (varargin{i+1});
case 'finetune'
finetune = lower (varargin{i+1});
case 'a1'
a1 = varargin{i+1};
case 'a2'
a2 = varargin{i+1};
case {'mu', 'myy'}
myy = varargin{i+1};
case 'epsilon'
epsilon = varargin{i+1};
case 'maxnumiterations'
maxNumIterations = varargin{i+1};
case 'initguess'
% no use setting 'guess' if the 'initState' is not set
initState = 'guess';
guess = varargin{i+1};
case 'displaymode'
displayMode = lower (varargin{i+1});
case 'displayinterval'
displayInterval = varargin{i+1};
case 'pcae'
% calculate if there are enought parameters to skip PCA
jumpPCA = jumpPCA + 1;
E = varargin{i+1};
case 'pcad'
% calculate if there are enought parameters to skip PCA
jumpPCA = jumpPCA + 1;
D = varargin{i+1};
case 'whitesig'
% calculate if there are enought parameters to skip PCA and whitening
jumpWhitening = jumpWhitening + 1;
whitesig = varargin{i+1};
case 'whitemat'
% calculate if there are enought parameters to skip PCA and whitening
jumpWhitening = jumpWhitening + 1;
whiteningMatrix = varargin{i+1};
case 'dewhitemat'
% calculate if there are enought parameters to skip PCA and whitening
jumpWhitening = jumpWhitening + 1;
dewhiteningMatrix = varargin{i+1};
case 'only'
% if the user only wants to calculate PCA or...
switch lower (varargin{i+1})
case 'pca'
only = 1;
case 'white'
only = 2;
case 'all'
only = 3;
end
otherwise
% Hmmm, something wrong with the parameter string
error(['Unrecognized parameter: ''' varargin{i} '''']);
end;
end;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% print information about data
if b_verbose
fprintf('Number of signals: %d\n', Dim);
fprintf('Number of samples: %d\n', NumOfSampl);
end
% Check if the data has been entered the wrong way,
% but warn only... it may be on purpose
if Dim > NumOfSampl
if b_verbose
fprintf('Warning: ');
fprintf('The signal matrix may be oriented in the wrong way.\n');
fprintf('In that case transpose the matrix.\n\n');
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculating PCA
% We need the results of PCA for whitening, but if we don't
% need to do whitening... then we dont need PCA...
if jumpWhitening == 3
if b_verbose,
fprintf ('Whitened signal and corresponding matrises supplied.\n');
fprintf ('PCA calculations not needed.\n');
end;
else
% OK, so first we need to calculate PCA
% Check to see if we already have the PCA data
if jumpPCA == 2,
if b_verbose,
fprintf ('Values for PCA calculations supplied.\n');
fprintf ('PCA calculations not needed.\n');
end;
else
% display notice if the user entered one, but not both, of E and D.
if (jumpPCA > 0) & (b_verbose),
fprintf ('You must suply all of these in order to jump PCA:\n');
fprintf ('''pcaE'', ''pcaD''.\n');
end;
% Calculate PCA
[E, D]=pcamat(mixedsig, firstEig, lastEig, interactivePCA, verbose);
end
end
% skip the rest if user only wanted PCA
if only > 1
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Whitening the data
% Check to see if the whitening is needed...
if jumpWhitening == 3,
if b_verbose,
fprintf ('Whitening not needed.\n');
end;
else
% Whitening is needed
% display notice if the user entered some of the whitening info, but not all.
if (jumpWhitening > 0) & (b_verbose),
fprintf ('You must suply all of these in order to jump whitening:\n');
fprintf ('''whiteSig'', ''whiteMat'', ''dewhiteMat''.\n');
end;
% Calculate the whitening
[whitesig, whiteningMatrix, dewhiteningMatrix] = whitenv ...
(mixedsig, E, D, verbose);
end
end % if only > 1
% skip the rest if user only wanted PCA and whitening
if only > 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Calculating the ICA
% Check some parameters
% The dimension of the data may have been reduced during PCA calculations.
% The original dimension is calculated from the data by default, and the
% number of IC is by default set to equal that dimension.
Dim = size(whitesig, 1);
% The number of IC's must be less or equal to the dimension of data
if numOfIC > Dim
numOfIC = Dim;
% Show warning only if verbose = 'on' and user supplied a value for 'numOfIC'
if (b_verbose & userNumOfIC)
fprintf('Warning: estimating only %d independent components\n', numOfIC);
fprintf('(Can''t estimate more independent components than dimension of data)\n');
end
end
% Calculate the ICA with fixed point algorithm.
[A, W] = fpica (whitesig, whiteningMatrix, dewhiteningMatrix, approach, ...
numOfIC, g, finetune, a1, a2, myy, stabilization, epsilon, ...
maxNumIterations, maxFinetune, initState, guess, sampleSize, ...
displayMode, displayInterval, verbose);
% Check for valid return
if ~isempty(W)
% Add the mean back in.
if b_verbose
fprintf('Adding the mean back to the data.\n');
end
icasig = W * mixedsig + (W * mixedmean) * ones(1, NumOfSampl);
%icasig = W * mixedsig;
if b_verbose & ...
(max(abs(W * mixedmean)) > 1e-9) & ...
(strcmp(displayMode,'signals') | strcmp(displayMode,'on'))
fprintf('Note that the plots don''t have the mean added.\n');
end
else
icasig = [];
end
end % if only > 2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% The output depends on the number of output parameters
% and the 'only' parameter.
if only == 1 % only PCA
Out1 = E;
Out2 = D;
elseif only == 2 % only PCA & whitening
if nargout == 2
Out1 = whiteningMatrix;
Out2 = dewhiteningMatrix;
else
Out1 = whitesig;
Out2 = whiteningMatrix;
Out3 = dewhiteningMatrix;
end
else % ICA
if nargout == 2
Out1 = A;
Out2 = W;
else
Out1 = icasig;
Out2 = A;
Out3 = W;
end
end
3) function
function fasticag(mixedsig, InitialGuess)
%FASTICAG - Fast Independent Component Analysis, the Graphical User Interface
%
% FASTICAG gives a graphical user interface for performing independent
% component analysis by the FastICA package. No arguments are
% necessary in the function call.
%
% Optional arguments can be given in the form:
% FASTICAG(mixedsig, initialGuess) where the matrix mixedsig contains the
% multidimensional signals as row vectors, and initialGuess gives the
% initial value for the mixing matrix used in the algorithm.
%
% FASTICA uses the fixed-point algorithm developed by Aapo Hyvarinen,
% see http://www.cis.hut.fi/projects/ica/fastica/. The Matlab package
% was programmed by Hugo Gavert, Jarmo Hurri, Jaakko Sarela, and Aapo
% Hyvarinen.
%
%
% See also FASTICA
% @(#)$Id: fasticag.m,v 1.5 2005/10/19 13:05:34 jarmo Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Global values
% Handle to this main figure
global hf_FastICA_MAIN;
% Check to see if GUI is already running
% Can't have more than one copy - otherwise the global
% variables and handles can get mixed up.
if ~isempty(hf_FastICA_MAIN)
error('FastICA GUI already running!');
end
% Handles to other controls in this main window
global ht_FastICA_mixedStatus;
global ht_FastICA_dim;
global ht_FastICA_numOfSamp;
global ht_FastICA_newDim;
global ht_FastICA_whiteStatus;
global ht_FastICA_icaStatus;
global hpm_FastICA_approach;
global he_FastICA_numOfIC;
global hpm_FastICA_g;
global hpm_FastICA_stabilization;
% These global variables are used to store all the values
% I used to use the 'UserData' field of components, but
% that got too complex, so I decided to put everything
% in global variables
global g_FastICA_mixedsig;
global g_FastICA_pca_D;
global g_FastICA_pca_E;
global g_FastICA_white_sig;
global g_FastICA_white_wm;
global g_FastICA_white_dwm;
global g_FastICA_ica_sig;
global g_FastICA_ica_A;
global g_FastICA_ica_W;
global g_FastICA_initGuess;
global g_FastICA_approach;
global g_FastICA_numOfIC;
global g_FastICA_g;
global g_FastICA_finetune;
global g_FastICA_a1;
global g_FastICA_a2;
global g_FastICA_myy;
global g_FastICA_stabilization;
global g_FastICA_epsilon;
global g_FastICA_maxNumIte;
global g_FastICA_maxFinetune;
global g_FastICA_sampleSize;
global g_FastICA_initState;
global g_FastICA_displayMo;
global g_FastICA_displayIn;
global g_FastICA_verbose;
% initial values for them:
% All the initial values are set here - even for
% variables that are not used in this file
if nargin < 2
g_FastICA_initGuess = 1;
% The user didn't enter initial guess so we default
% back to random initial state.
g_FastICA_initState = 1; % see below for string values
else
g_FastICA_initGuess = InitialGuess;
% If initial guess was entered, then the user probably
% wan't to use it, eh?
g_FastICA_initState = 2; % see below for string values
end
if nargin < 1
g_FastICA_mixedsig = [];
else
g_FastICA_mixedsig = mixedsig; % We'll remove mean
end % the first time we
% use this.
% Global variable for stopping the ICA calculations
global g_FastICA_interrupt;
g_FastICA_pca_D = [];
g_FastICA_pca_E = [];
g_FastICA_white_sig = [];
g_FastICA_white_wm = [];
g_FastICA_white_dwm = [];
g_FastICA_ica_sig = [];
g_FastICA_ica_A = [];
g_FastICA_ica_W = [];
g_FastICA_approach = 1; % see below for string values
g_FastICA_numOfIC = 0;
g_FastICA_g = 1; % see below for string values
g_FastICA_finetune = 5; % see below for string values
g_FastICA_a1 = 1;
g_FastICA_a2 = 1;
g_FastICA_myy = 1;
g_FastICA_stabilization = 2; % see below for string values
g_FastICA_epsilon = 0.0001;
g_FastICA_maxNumIte = 1000;
g_FastICA_maxFinetune = 100;
g_FastICA_sampleSize = 1;
g_FastICA_displayMo = 1; % see below for string values
g_FastICA_displayIn = 1;
g_FastICA_verbose = 1; % see below for string values
% These are regarded as constants and are used to store
% the strings for the popup menus the current value is
% seen in the variables above
% D - refers to strings that are displayed
% V - refers to string values that are used in FPICA
global c_FastICA_appr_strD;
global c_FastICA_appr_strV;
global c_FastICA_g1_strD;
global c_FastICA_g1_strV;
global c_FastICA_g2_strD;
global c_FastICA_g2_strV;
global c_FastICA_finetune_strD;
global c_FastICA_finetune_strV;
global c_FastICA_stabili_strD;
global c_FastICA_stabili_strV;
global c_FastICA_iSta_strD;
global c_FastICA_iSta_strV;
global c_FastICA_dMod_strD;
global c_FastICA_dMod_strV;
global c_FastICA_verb_strD;
global c_FastICA_verb_strV;
% All the values for these are set here - even for
% variables that are not used in this file
c_FastICA_appr_strD = 'deflation|symmetric';
c_FastICA_appr_strV = ['defl';'symm'];
% The 'g1' and 'g2' below correspond to the values of approach (1 or 2)
% Deflation and Symmetric used to have a bit different selection
% of available nonlinearities.
c_FastICA_g1_strD = 'pow3|tanh|gauss|skew';
c_FastICA_g1_strV = ['pow3';'tanh';'gaus';'skew'];
c_FastICA_g2_strD = 'pow3|tanh|gauss|skew';
c_FastICA_g2_strV = ['pow3';'tanh';'gaus';'skew'];
c_FastICA_finetune_strD = 'pow3|tanh|gauss|skew|off';
c_FastICA_finetune_strV = ['pow3';'tanh';'gaus';'skew';'off '];
c_FastICA_stabili_strD = 'on|off';
c_FastICA_stabili_strV = ['on ';'off'];
c_FastICA_iSta_strD = 'random|guess';
c_FastICA_iSta_strV = ['rand ';'guess'];
c_FastICA_dMod_strD = 'signals|basis|filters|off';
c_FastICA_dMod_strV = ['signals';'basis ';'filters';'off '];
c_FastICA_verb_strD = 'on|off';
c_FastICA_verb_strV = ['on ';'off'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Configuration options
FIGURENAME = 'FastICA';
FIGURETAG = 'f_FastICA';
SCREENSIZE = get(0,'ScreenSize');
FIGURESIZE = [round(0.1*SCREENSIZE(3)) (SCREENSIZE(4)-round(0.1*SCREENSIZE(4))-370) 530 370];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create the figure
a = figure('Color',[0.8 0.8 0.8], ...
'PaperType','a4letter', ...
'Name', FIGURENAME, ...
'NumberTitle', 'off', ...
'Tag', FIGURETAG, ...
'Position', FIGURESIZE, ...
'MenuBar', 'none');
% Resizing has to be denied after the window has been created -
% otherwise the window shows only as a tiny window in Windows XP.
set (a, 'Resize', 'off');
hf_FastICA_MAIN = a;
set(hf_FastICA_MAIN, 'HandleVisibility', 'callback');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% From here on it get's ugly as I have not had time to clean it up
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Create the frames
pos_l=2;
pos_w=FIGURESIZE(3)-4;
pos_h=FIGURESIZE(4)-4;
pos_t=FIGURESIZE(4)-2-pos_h;
h_f_background = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Position',[pos_l pos_t pos_w pos_h], ...
'Style','frame', ...
'Tag','f_background');
pos_l=4;
pos_w=400;
pos_h=106;
pos_t=FIGURESIZE(4)-4-pos_h;
h_f_mixed = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Position',[pos_l pos_t pos_w pos_h], ...
'Style','frame', ...
'Tag','f_mixed');
pos_h=90;
pos_t=FIGURESIZE(4)-(106+4+2)-pos_h;
h_f_white = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Position',[pos_l pos_t pos_w pos_h], ...
'Style','frame', ...
'Tag','f_white');
pos_h=pos_t - 4 - 2;
pos_t=4;
h_f_ica = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Position',[pos_l pos_t pos_w pos_h], ...
'Style','frame', ...
'Tag','f_ica');
pos_w=120;
pos_l=FIGURESIZE(3)-(pos_w+2+2);
pos_h=FIGURESIZE(4)-2*4;
pos_t=FIGURESIZE(4)-(4)-pos_h;
h_f_side = uicontrol('Parent',a, ...
'BackgroundColor',[0.5 0.5 0.5], ...
'Position',[pos_l pos_t pos_w pos_h], ...
'Style','frame', ...
'Tag','f_side');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Controls in f_mixed
bgc = get(h_f_mixed, 'BackgroundColor');
pos_vspace = 6;
pos_hspace = 6;
pos_frame=get(h_f_mixed, 'Position');
pos_l = pos_frame(1) + 6;
pos_h = 16;
pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Mixed signals:', ...
'FontWeight', 'bold', ...
'Style','text', ...
'Tag','t_mixed');
pos_l = pos_l + pos_w;
pos_w = 120;
ht_FastICA_mixedStatus = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Not loaded yet', ...
'Style','text', ...
'Tag','t_mixedstatus');
% Vähän väliä
pos_t = pos_t - 8;
pos_l = pos_frame(1) + 6;
pos_t = pos_t - pos_h;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Number of signals:', ...
'Style','text', ...
'Tag','t_2');
pos_l = pos_l + pos_w;
pos_w = 50;
ht_FastICA_dim = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','', ...
'Style','text', ...
'Tag','t_dim');
pos_l = pos_frame(1) + 6;
pos_t = pos_t - pos_h;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Number of samples:', ...
'Style','text', ...
'Tag','t_3');
pos_l = pos_l + pos_w;
pos_w = 50;
ht_FastICA_numOfSamp = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','', ...
'Style','text', ...
'Tag','t_numOfSamp');
% Buttons
pos_l = pos_frame(1) + pos_hspace;
pos_w = 110;
pos_h = 30;
pos_t = pos_frame(2) + pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb Transpose', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Transpose', ...
'Tag','b_Transpose');
pos_w = 130;
pos_l = pos_frame(1) + pos_frame(3) - pos_hspace - pos_w;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb ShowMixed', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Plot data', ...
'Tag','b_ShowMixed');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Controls in f_white
pos_frame=get(h_f_white, 'Position');
pos_l = pos_frame(1) + 6;
pos_h = 16;
pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Dimension control:', ...
'FontWeight', 'bold', ...
'Style','text', ...
'Tag','t_white');
pos_l = pos_l + pos_w;
pos_w = 120;
ht_FastICA_whiteStatus = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','', ...
'Style','text', ...
'Tag','t_whiteStatus');
% Vähän väliä
pos_t = pos_t - 8;
pos_l = pos_frame(1) + 6;
pos_t = pos_t - pos_h;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Reduced dimension:', ...
'Style','text', ...
'Tag','t_4');
pos_l = pos_l + pos_w;
pos_w = 50;
ht_FastICA_newDim = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','', ...
'Style','text', ...
'Tag','t_newDim');
% buttons
pos_l = pos_frame(1) + pos_hspace;
pos_w = 110;
pos_h = 30;
pos_t = pos_frame(2) + pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb DoPCA', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Reduce dim.', ...
'Tag','b_DoPCA');
pos_l = pos_l + pos_w + pos_hspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb OrigDim', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Original dim.', ...
'Tag','b_OrigDim');
pos_w = 130;
pos_h = 30;
pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
pos_t = pos_frame(2) + 6;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb ShowWhite', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Plot whitened', ...
'Tag','b_ShowWhite');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Controls in f_ica
pos_frame=get(h_f_ica, 'Position');
pos_l = pos_frame(1) + 6;
pos_h = 20;
pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
pos_w = 150;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Fixed point ICA:', ...
'FontWeight', 'bold', ...
'Style','text', ...
'Tag','t_white');
pos_l = pos_l + pos_w;
pos_w = 120;
ht_FastICA_icaStatus = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Not yet done', ...
'Style','text', ...
'Tag','t_icaStatus');
% Vähän väliä
pos_t = pos_t - 8;
%pos_l = pos_frame(1) + 6;
pos_l = pos_frame(1) + 6 + 150;
pos_t = pos_t - pos_h;
%pos_w = 260;
pos_w = 120;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Approach:', ...
'Style','text', ...
'Tag','t_5');
pos_w = 100;
%pos_t = pos_t - 4;
pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
hpm_FastICA_approach = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'Callback','gui_cb ChangeApproach', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String',c_FastICA_appr_strD, ...
'Style','popupmenu', ...
'Tag','pm_approach', ...
'Value',g_FastICA_approach);
%pos_t = pos_t - 4;
%pos_l = pos_frame(1) + 6;
pos_l = pos_frame(1) + 6 + 150;
pos_t = pos_t - pos_h;
%pos_w = 260;
pos_w = 120;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Number of ICs:', ...
'Style','text', ...
'Tag','t_6');
pos_w = 100;
pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
he_FastICA_numOfIC = uicontrol('Parent',a, ...
'BackgroundColor',[1 1 1], ...
'Callback','gui_cb ChangeNumOfIC', ...
'HorizontalAlignment','right', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','0', ...
'Style','edit', ...
'Tag','e_numOfIC');
%pos_t = pos_t - 4;
%pos_l = pos_frame(1) + 6;
pos_l = pos_frame(1) + 6 + 150;
pos_t = pos_t - pos_h;
%pos_w = 260;
pos_w = 120;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Nonlinearity (g):', ...
'Style','text', ...
'Tag','t_71');
%pos_t = pos_t - 4;
pos_w = 100;
pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
hpm_FastICA_g = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'Callback','gui_cb ChangeG', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String',c_FastICA_g1_strD, ...
'Style','popupmenu', ...
'Tag','pm_g', ...
'Value',g_FastICA_g);
%pos_t = pos_t - 4;
%pos_l = pos_frame(1) + 6;
pos_l = pos_frame(1) + 6 + 150;
pos_t = pos_t - pos_h;
%pos_w = 260;
pos_w = 120;
b = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'HorizontalAlignment','left', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Stabilization:', ...
'Style','text', ...
'Tag','t_71a');
%pos_t = pos_t - 4;
pos_w = 100;
pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
hpm_FastICA_stabilization = uicontrol('Parent',a, ...
'BackgroundColor',bgc, ...
'Callback','gui_cb ChangeStab', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String',c_FastICA_stabili_strD, ...
'Style','popupmenu', ...
'Tag','pm_stab', ...
'Value',g_FastICA_stabilization);
pos_l = pos_frame(1) + pos_vspace;
pos_w = 110;
pos_h = 30;
pos_t = pos_frame(2) + pos_hspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb AdvOpt', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Adv. options >>', ...
'Tag','b_advOpt');
pos_w = 130;
pos_h = 30;
pos_l = pos_frame(1) + pos_frame(3) - pos_vspace - pos_w;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb ShowICASig', ...
'Interruptible', 'on', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Plot ICs', ...
'Tag','b_ShowICASig');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Controls in f_side
pos_vspace = 6;
pos_hspace = 10;
pos_temp=get(h_f_side, 'Position');
pos_l=pos_temp(1)+pos_hspace;
pos_w=100;
pos_h=30;
pos_t=pos_temp(2)+pos_temp(4)-pos_vspace-pos_h;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb LoadData', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Load data', ...
'Tag','b_LoadData');
pos_t=pos_t-pos_h-pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb DoFPICA', ...
'Interruptible', 'on', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Do ICA', ...
'Tag','b_DoFPICA');
pos_t=pos_t-pos_h-pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb SaveData', ...
'Interruptible', 'off', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Save results', ...
'Tag','b_SaveData');
pos_t=pos_t-pos_h-pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb Quit', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Quit', ...
'Tag','b_Quit');
pos_t=pos_t-pos_h-pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb Interrupt', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Interrupt', ...
'Visible','off', ...
'Tag','b_Interrupt');
pos_t = pos_frame(2) + pos_vspace + pos_h + pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb About', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','About...', ...
'Tag','b_About');
pos_t = pos_frame(2) + pos_vspace;
b = uicontrol('Parent',a, ...
'BackgroundColor',[0.701961 0.701961 0.701961], ...
'Callback','gui_cb Help', ...
'Position',[pos_l pos_t pos_w pos_h], ...
'String','Help', ...
'Tag','b_Help');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Do rest of the initialization...
gui_cb InitAll;
function [newVectors, meanValue] = remmean(vectors);
%REMMEAN - remove the mean from vectors
%
% [newVectors, meanValue] = remmean(vectors);
%
% Removes the mean of row vectors.
% Returns the new vectors and the mean.
%
% This function is needed by FASTICA and FASTICAG
% @(#)$Id: remmean.m,v 1.2 2003/04/05 14:23:58 jarmo Exp $
newVectors = zeros (size (vectors));
meanValue = mean (vectors')';
newVectors = vectors - meanValue * ones (1,size (vectors, 2));

Accepted Answer

Image Analyst
Image Analyst on 2 Jan 2013
For me at least, the FAQ applies here.
  8 Comments
Walter Roberson
Walter Roberson on 28 Mar 2016
I do not have time to research the technique and then go through and debug over 200 lines of source code. But perhaps someone might. You should open a Question about it rather than having the discussion here, as your question does not have to do with the original Question of this topic.
Image Analyst
Image Analyst on 28 Mar 2016
Here is somebody who does have time click here. Usually I'll spend only a few minutes on a question and it looks like you might need more assistance than that.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!