jalauer commited on
Commit
89c3739
·
verified ·
1 Parent(s): 6654bb7

Add files using upload-large-folder tool

Browse files
This view is limited to 50 files because it contains too many changes.   See raw diff
Files changed (50) hide show
  1. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/display.m +16 -0
  2. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/eegobj.m +14 -0
  3. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/fieldnames.m +3 -0
  4. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/horzcat2.m +5 -0
  5. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isfield.m +3 -0
  6. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isstruct.m +3 -0
  7. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/length.m +14 -0
  8. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/orderfields.m +5 -0
  9. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/rmfield.m +4 -0
  10. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/simpletest.m +4 -0
  11. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsasgn.m +68 -0
  12. scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsref.m +45 -0
  13. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/display.m +36 -0
  14. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/double.m +3 -0
  15. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/end.m +23 -0
  16. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/isnumeric.m +23 -0
  17. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/length.m +23 -0
  18. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/msize.m +3 -0
  19. scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/ndims.m +31 -0
  20. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Entries +20 -0
  21. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Repository +1 -0
  22. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Root +1 -0
  23. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/Contents.m +40 -0
  24. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/demosig.m +32 -0
  25. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/dispsig.m +15 -0
  26. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fastica.m +519 -0
  27. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fasticag.m +667 -0
  28. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fpica.m +905 -0
  29. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_adv.m +441 -0
  30. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_advc.m +256 -0
  31. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cb.m +581 -0
  32. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cg.m +84 -0
  33. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_help.m +224 -0
  34. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_l.m +180 -0
  35. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_lc.m +112 -0
  36. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_s.m +177 -0
  37. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_sc.m +74 -0
  38. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/icaplot.m +397 -0
  39. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/pcamat.m +358 -0
  40. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/remmean.m +15 -0
  41. scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/whitenv.m +82 -0
  42. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/eegplugin_bva_io.m +77 -0
  43. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/loadbvef.m +71 -0
  44. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/parsebvmrk.m +48 -0
  45. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbv.m +423 -0
  46. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbva.m +140 -0
  47. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_writebva.m +204 -0
  48. scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/readbvconf.m +93 -0
  49. scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/README.txt +2 -0
  50. scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/adjustcylinder2.m +60 -0
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/display.m ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function display(this);
2
+
3
+ disp(inputname(1));
4
+ if length(this) == 1
5
+ struct(this.EEG)
6
+ else
7
+ TMP = struct(this);
8
+
9
+ TMP2 = TMP(1).EEG;
10
+ fieldorder = fieldnames(TMP2);
11
+ for index = 2:length(TMP)
12
+ TMP2(index) = orderfields(TMP(index).EEG, fieldorder);
13
+ end;
14
+ TMP2
15
+ end;
16
+
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/eegobj.m ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function this = eegobj(EEG);
2
+
3
+ if nargin == 1
4
+ if isa(EEG, 'eegobj')
5
+ this = EEG;
6
+ return;
7
+ end;
8
+ for index = 1:length(EEG)
9
+ TMP(index).EEG = EEG(index);
10
+ end;
11
+ else
12
+ TMP.EEG = eeg_emptyset;
13
+ end;
14
+ this = class(TMP, 'eegobj');
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/fieldnames.m ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ function res = fieldnames(this);
2
+
3
+ res = fieldnames(this(1).EEG);
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/horzcat2.m ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ function this = horzcat(varargin);
2
+ this = varargin{1};
3
+ for index = 2:length(varargin)
4
+ this.EEG(index) = varargin{index}.EEG;
5
+ end;
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isfield.m ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ function res = isfield(this, vals);
2
+
3
+ res = isfield(struct(this(1).EEG), vals);
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/isstruct.m ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ function res = isstruct(this);
2
+
3
+ res = 1;
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/length.m ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function res = length(this);
2
+
3
+ tmp = struct(this);
4
+ %if any(cellfun(@length, { tmp.EEG }) > 1)
5
+ % error('EEG structure in object with more than 1 element')
6
+ %end;
7
+ try
8
+ res = length(tmp.EEG);
9
+ catch
10
+ res = length(tmp);
11
+ return;
12
+ end;
13
+ if res > 1, error('EEG structure in object with more than 1 element'); end;
14
+ res = length(tmp);
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/orderfields.m ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ function this = orderfields(this, vals);
2
+
3
+ for index = 1:length(this)
4
+ this(index).EEG = orderfields(this(index).EEG, vals);
5
+ end;
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/rmfield.m ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ function this = rmfield(this, vals);
2
+
3
+ this.EEG = rmfield(this.EEG, vals);
4
+
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/simpletest.m ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ % simple dataset tests
2
+ p = fileparts(which('eeglab'));
3
+ EEG = pop_loadset('filename','eeglab_data_epochs_ica.set','filepath',fullfile(p, 'sample_data'));
4
+
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsasgn.m ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function this = subsasgn(this,index,c)
2
+
3
+ if isempty(this)
4
+ this = eegobj;
5
+ end;
6
+
7
+ % mulitple dataset
8
+ if strcmpi(index(1).type, '()') && length(index) == 1 % dataset assignement
9
+ if isempty(c) % suppression
10
+ this(index.subs{1}) = [];
11
+ else
12
+ % create empty structures if necessary
13
+ % not optimized for speed but compatible Octave 3.4 and Matlab
14
+ allfieldsori = fieldnames( this );
15
+ allSetIndices = [ [(length(this)+1):(min(index.subs{1})-1)] index.subs{1} ];
16
+ this(max(index.subs{1})) = this(1);
17
+ for j = 1:length(allfieldsori)
18
+ for i = allSetIndices
19
+ this(i).EEG.(allfieldsori{j}) = [];
20
+ end;
21
+ end;
22
+
23
+ % create empty structure, replaces the code above but
24
+ % only compatible under Matlab
25
+ %allfieldsori = fieldnames( this );
26
+ %tmpfields = allfieldsori;
27
+ %tmpfields(:,2) = cell(size(tmpfields));
28
+ %tmpfields = tmpfields';
29
+ %tmp = struct(tmpfields{:})
30
+ %this(index.subs{1}) = tmp;
31
+
32
+ % dealing with input object and making it a compatible
33
+ % structure
34
+ if isa(c, 'eegobj')
35
+ c2 = struct(c);
36
+ c = c2(1).EEG;
37
+ fieldorder = fieldnames(c);
38
+ for cIndexe = 2:length(c2)
39
+ c(cIndexe) = orderfields(c2(cIndexe).EEG, fieldorder);
40
+ end;
41
+ end;
42
+
43
+ allfields = fieldnames( c );
44
+ for i=1:length( allfields )
45
+ for j = 1:length(index.subs{1})
46
+ this(index.subs{1}(j)).EEG.(allfields{i}) = c(min(j, length(c))).(allfields{i});
47
+ end;
48
+ %this(index.subs(1)).EEG = setfield(this(index.subs(1)).EEG, getfield(c, allfields{i}), allfields{i});
49
+ %eval( ['this(' int2str(index.subs{1}) ').' allfields{i} ' = c.' allfields{i} ';' ]);
50
+ end;
51
+ %if ~isfield(c, 'datfile') & isfield(this, 'datfile')
52
+ % this(index.subs{1}).datfile = '';
53
+ %end;
54
+ end;
55
+ elseif strcmpi(index(1).type, '()')
56
+ if length(index(1).subs{1}) > 1
57
+ error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
58
+ elseif length(this) < index(1).subs{1}
59
+ this(index(1).subs{1}) = eegobj;
60
+ end;
61
+ this(index(1).subs{1}).EEG = builtin('subsasgn', this(index(1).subs{1}).EEG, index(2:end), c);
62
+ elseif strcmpi(index(1).type, '.')
63
+ if length(this) > 1
64
+ error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
65
+ else
66
+ this.EEG = builtin('subsasgn', this.EEG, index, c);
67
+ end;
68
+ end;
scripts/eeglab_current/eeglab14_1_1b/functions/@eegobj/subsref.m ADDED
@@ -0,0 +1,45 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function varargout = subsref(this,s)
2
+
3
+ if strcmpi(s(1).type, '()') && length(this) > 1
4
+ %if length(s(1).subs{1})
5
+ % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
6
+ %end;
7
+
8
+ % if length(s) == 1
9
+ % b = this(s(1).subs{1});
10
+ % else
11
+ % b = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end));
12
+ % end;
13
+
14
+ if length(s) == 1
15
+ varargout{1} = this(s(1).subs{1});
16
+ elseif length(s(1).subs{1}) > 1
17
+ for index = 1:length(s(1).subs{1})
18
+ varargout{1}{index} = builtin('subsref', this(s(1).subs{1}(index)).EEG, s(2:end));
19
+ end;
20
+ else
21
+ varargout{1} = builtin('subsref', this(s(1).subs{1}).EEG, s(2:end));
22
+ end;
23
+ elseif strcmpi(s(1).type, '.') && length(this) > 1
24
+ for index = 1:length(this)
25
+ varargout{index} = builtin('subsref', this(index).EEG, s);
26
+ end;
27
+ %if length(s) > 1 && iscell(s(2).subs) && length(s(2).subs{1})
28
+ % error('Unsuported object feature - a.field or a([x y]).field is not supported for object arrays');
29
+ %end;
30
+ else
31
+ varargout{1} = builtin('subsref', this.EEG, s);
32
+ end;
33
+
34
+
35
+ % return;
36
+ %
37
+ % % SUBSREF
38
+ % switch s.type
39
+ % case '()'
40
+ % b = getfield(a.rawbit, s.subs);
41
+ % case '.'
42
+ % b = getfield(struct(a), s.subs);
43
+ % otherwise
44
+ % error('Wrong class argument')
45
+ % end
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/display.m ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % display() - display an EEG data class underlying structure
2
+ %
3
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008
4
+
5
+ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD
6
+ %
7
+ % This program is free software; you can redistribute it and/or modify
8
+ % it under the terms of the GNU General Public License as published by
9
+ % the Free Software Foundation; either version 2 of the License, or
10
+ % (at your option) any later version.
11
+ %
12
+ % This program is distributed in the hope that it will be useful,
13
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ % GNU General Public License for more details.
16
+ %
17
+ % You should have received a copy of the GNU General Public License
18
+ % along with this program; if not, write to the Free Software
19
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+
21
+ function b = display(a)
22
+
23
+ i.type = '()';
24
+ i.subs = { ':' ':' ':' };
25
+ b = subsref(a, i); % note that subsref cannot be called directly
26
+ return;
27
+
28
+
29
+ %struct(a)
30
+ %return;
31
+
32
+ if ~strcmpi(a.fileformat, 'transposed')
33
+ a.data.data.x;
34
+ else
35
+ permute(a, [3 1 2]);
36
+ end;
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/double.m ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ function res = double(a);
2
+
3
+ res = double(a.data.data.x);
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/end.m ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % end() - last index to memmapdata array
2
+ %
3
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008
4
+
5
+ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD
6
+ %
7
+ % This program is free software; you can redistribute it and/or modify
8
+ % it under the terms of the GNU General Public License as published by
9
+ % the Free Software Foundation; either version 2 of the License, or
10
+ % (at your option) any later version.
11
+ %
12
+ % This program is distributed in the hope that it will be useful,
13
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ % GNU General Public License for more details.
16
+ %
17
+ % You should have received a copy of the GNU General Public License
18
+ % along with this program; if not, write to the Free Software
19
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+
21
+ function s = end(a, k, n);
22
+
23
+ s = size(a, k);
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/isnumeric.m ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % isnumeric() - returns 1
2
+ %
3
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008
4
+
5
+ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD
6
+ %
7
+ % This program is free software; you can redistribute it and/or modify
8
+ % it under the terms of the GNU General Public License as published by
9
+ % the Free Software Foundation; either version 2 of the License, or
10
+ % (at your option) any later version.
11
+ %
12
+ % This program is distributed in the hope that it will be useful,
13
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ % GNU General Public License for more details.
16
+ %
17
+ % You should have received a copy of the GNU General Public License
18
+ % along with this program; if not, write to the Free Software
19
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+
21
+ function r = isnumeric(a)
22
+
23
+ r = 1;
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/length.m ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % length() - length of memory mapped underlying array
2
+ %
3
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008
4
+
5
+ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD
6
+ %
7
+ % This program is free software; you can redistribute it and/or modify
8
+ % it under the terms of the GNU General Public License as published by
9
+ % the Free Software Foundation; either version 2 of the License, or
10
+ % (at your option) any later version.
11
+ %
12
+ % This program is distributed in the hope that it will be useful,
13
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ % GNU General Public License for more details.
16
+ %
17
+ % You should have received a copy of the GNU General Public License
18
+ % along with this program; if not, write to the Free Software
19
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+
21
+ function s = length(a)
22
+
23
+ s = size(a,1);
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/msize.m ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ function s = msize(a);
2
+
3
+ asdfdsa;
scripts/eeglab_current/eeglab14_1_1b/functions/@memmapdata/ndims.m ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % ndims() - number of dimension of memory mapped underlying array
2
+ %
3
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, Nov. 2008
4
+
5
+ % Copyright (C) 2008 Arnaud Delorme, SCCN, INC, UCSD
6
+ %
7
+ % This program is free software; you can redistribute it and/or modify
8
+ % it under the terms of the GNU General Public License as published by
9
+ % the Free Software Foundation; either version 2 of the License, or
10
+ % (at your option) any later version.
11
+ %
12
+ % This program is distributed in the hope that it will be useful,
13
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ % GNU General Public License for more details.
16
+ %
17
+ % You should have received a copy of the GNU General Public License
18
+ % along with this program; if not, write to the Free Software
19
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20
+
21
+ function s = ndims(a)
22
+
23
+ if ~strcmpi(a.fileformat, 'transposed')
24
+ if a.data.Format{2}(3) == 1, s = 2;
25
+ else s = 3;
26
+ end;
27
+ else
28
+ if a.data.Format{2}(2) == 1, s = 2;
29
+ else s = 3;
30
+ end;
31
+ end;
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Entries ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /Contents.m/1.7/Wed Oct 19 13:05:33 2005//
2
+ /demosig.m/1.2/Sat Apr 5 14:23:57 2003//
3
+ /dispsig.m/1.2/Sat Apr 5 14:23:57 2003//
4
+ /fastica.m/1.14/Wed Oct 19 13:05:34 2005//
5
+ /fasticag.m/1.5/Wed Oct 19 13:05:34 2005//
6
+ /fpica.m/1.7/Thu Jun 16 12:52:55 2005//
7
+ /gui_adv.m/1.4/Tue Jul 27 13:09:26 2004//
8
+ /gui_advc.m/1.3/Mon Sep 8 11:28:58 2003//
9
+ /gui_cb.m/1.5/Wed Sep 10 10:33:41 2003//
10
+ /gui_cg.m/1.2/Sat Apr 5 14:23:57 2003//
11
+ /gui_help.m/1.6/Wed Oct 19 13:05:34 2005//
12
+ /gui_l.m/1.4/Tue Jul 27 13:09:26 2004//
13
+ /gui_lc.m/1.4/Thu Sep 11 12:01:19 2003//
14
+ /gui_s.m/1.4/Tue Jul 27 13:09:26 2004//
15
+ /gui_sc.m/1.3/Mon Sep 8 11:28:59 2003//
16
+ /icaplot.m/1.2/Sat Apr 5 14:23:58 2003//
17
+ /pcamat.m/1.5/Mon Dec 15 18:24:32 2003//
18
+ /remmean.m/1.2/Sat Apr 5 14:23:58 2003//
19
+ /whitenv.m/1.3/Sun Oct 12 09:04:43 2003//
20
+ D
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Repository ADDED
@@ -0,0 +1 @@
 
 
1
+ FastICA
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/CVS/Root ADDED
@@ -0,0 +1 @@
 
 
1
+ /share/video/cvsroot
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/Contents.m ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % FastICA for Matlab 7.x and 6.x
2
+ % Version 2.5, October 19 2005
3
+ % Copyright (c) Hugo G�vert, Jarmo Hurri, Jaakko S�rel�, and Aapo Hyv�rinen.
4
+ %
5
+ % Type fasticag to launch the graphical user interface
6
+ %
7
+ % Please refer to your Matlab documentation on how to add FastICA to your
8
+ % Matlab search path. (One place to start is the path-command)
9
+ %
10
+ % FastICA programs:
11
+ % FASTICAG - Graphical user interface for FastICA
12
+ % FASTICA - command line version of FastICA
13
+ %
14
+ % Separate functions used by FastICA programs.
15
+ % FPICA - main algorithm for calculating ICA
16
+ % WHITENV - function for whitening data
17
+ % PCAMAT - calculates the PCA for data
18
+ % REMMEAN - function for removing mean
19
+ %
20
+ % GUI_CB - needed by fasticag
21
+ % GUI_ADV - needed by fasticag
22
+ % GUI_ADVC - needed by fasticag
23
+ % GUI_L - needed by fasticag
24
+ % GUI_LC - needed by fasticag
25
+ % GUI_S - needed by fasticag
26
+ % GUI_SC - needed by fasticag
27
+ % GUI_CG - needed by fasticag
28
+ % GUI_HELP - needed by fasticag
29
+ %
30
+ % ICAPLOT - for plotting the signals
31
+ % (also used by fastica and fasticag)
32
+ %
33
+ % Misc.
34
+ % DEMOSIG - generates some test signals
35
+ %
36
+ % Deprecated
37
+ % dispsig - plots the data vectors
38
+ % replaced by icaplot
39
+
40
+ % @(#)$Id: Contents.m,v 1.7 2005/10/19 13:05:33 jarmo Exp $
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/demosig.m ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [sig,mixedsig]=demosig();
2
+ %
3
+ % function [sig,mixedsig]=demosig();
4
+ %
5
+ % Returns artificially generated test signals, sig, and mixed
6
+ % signals, mixedsig. Signals are row vectors of
7
+ % matrices. Input mixedsig to FastICA to see how it works.
8
+
9
+ % @(#)$Id: demosig.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $
10
+
11
+ %create source signals (independent components)
12
+ N=500; %data size
13
+
14
+ v=[0:N-1];
15
+ sig=[];
16
+ sig(1,:)=sin(v/2); %sinusoid
17
+ sig(2,:)=((rem(v,23)-11)/9).^5; %funny curve
18
+ sig(3,:)=((rem(v,27)-13)/9); %saw-tooth
19
+ sig(4,:)=((rand(1,N)<.5)*2-1).*log(rand(1,N)); %impulsive noise
20
+
21
+ for t=1:4
22
+ sig(t,:)=sig(t,:)/std(sig(t,:));
23
+ end
24
+
25
+ %remove mean (not really necessary)
26
+
27
+ [sig mean]=remmean(sig);
28
+
29
+ %create mixtures
30
+
31
+ Aorig=rand(size(sig,1));
32
+ mixedsig=(Aorig*sig);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/dispsig.m ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function dispsig(signalMatrix, range, titlestr);
2
+ %DISPSIG - deprecated!
3
+ %
4
+ % Please use icaplot instead.
5
+ %
6
+ % See also ICAPLOT
7
+
8
+ % @(#)$Id: dispsig.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $
9
+
10
+ fprintf('\nNote: DISPSIG is now deprecated! Please use ICAPLOT.\n');
11
+
12
+ if nargin < 3, titlestr = ''; end
13
+ if nargin < 2, range = 1:size(signalMatrix, 1); end
14
+
15
+ icaplot('dispsig',signalMatrix',0,range,range,titlestr);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fastica.m ADDED
@@ -0,0 +1,519 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [Out1, Out2, Out3] = fastica(mixedsig, varargin)
2
+ %FASTICA - Fast Independent Component Analysis
3
+ %
4
+ % FastICA for Matlab 7.x and 6.x
5
+ % Version 2.5, October 19 2005
6
+ % Copyright (c) Hugo G�vert, Jarmo Hurri, Jaakko S�rel�, and Aapo Hyv�rinen.
7
+ %
8
+ % FASTICA(mixedsig) estimates the independent components from given
9
+ % multidimensional signals. Each row of matrix mixedsig is one
10
+ % observed signal. FASTICA uses Hyvarinen's fixed-point algorithm,
11
+ % see http://www.cis.hut.fi/projects/ica/fastica/. Output from the
12
+ % function depends on the number output arguments:
13
+ %
14
+ % [icasig] = FASTICA (mixedsig); the rows of icasig contain the
15
+ % estimated independent components.
16
+ %
17
+ % [icasig, A, W] = FASTICA (mixedsig); outputs the estimated separating
18
+ % matrix W and the corresponding mixing matrix A.
19
+ %
20
+ % [A, W] = FASTICA (mixedsig); gives only the estimated mixing matrix
21
+ % A and the separating matrix W.
22
+ %
23
+ % Some optional arguments induce other output formats, see below.
24
+ %
25
+ % A graphical user interface for FASTICA can be launched by the
26
+ % command FASTICAG
27
+ %
28
+ % FASTICA can be called with numerous optional arguments. Optional
29
+ % arguments are given in parameter pairs, so that first argument is
30
+ % the name of the parameter and the next argument is the value for
31
+ % that parameter. Optional parameter pairs can be given in any order.
32
+ %
33
+ % OPTIONAL PARAMETERS:
34
+ %
35
+ % Parameter name Values and description
36
+ %
37
+ %======================================================================
38
+ % --Basic parameters in fixed-point algorithm:
39
+ %
40
+ % 'approach' (string) The decorrelation approach used. Can be
41
+ % symmetric ('symm'), i.e. estimate all the
42
+ % independent component in parallel, or
43
+ % deflation ('defl'), i.e. estimate independent
44
+ % component one-by-one like in projection pursuit.
45
+ % Default is 'defl'.
46
+ %
47
+ % 'numOfIC' (integer) Number of independent components to
48
+ % be estimated. Default equals the dimension of data.
49
+ %
50
+ %======================================================================
51
+ % --Choosing the nonlinearity:
52
+ %
53
+ % 'g' (string) Chooses the nonlinearity g used in
54
+ % the fixed-point algorithm. Possible values:
55
+ %
56
+ % Value of 'g': Nonlinearity used:
57
+ % 'pow3' (default) g(u)=u^3
58
+ % 'tanh' g(u)=tanh(a1*u)
59
+ % 'gauss g(u)=u*exp(-a2*u^2/2)
60
+ % 'skew' g(u)=u^2
61
+ %
62
+ % 'finetune' (string) Chooses the nonlinearity g used when
63
+ % fine-tuning. In addition to same values
64
+ % as for 'g', the possible value 'finetune' is:
65
+ % 'off' fine-tuning is disabled.
66
+ %
67
+ % 'a1' (number) Parameter a1 used when g='tanh'.
68
+ % Default is 1.
69
+ % 'a2' (number) Parameter a2 used when g='gaus'.
70
+ % Default is 1.
71
+ %
72
+ % 'mu' (number) Step size. Default is 1.
73
+ % If the value of mu is other than 1, then the
74
+ % program will use the stabilized version of the
75
+ % algorithm (see also parameter 'stabilization').
76
+ %
77
+ %
78
+ % 'stabilization' (string) Values 'on' or 'off'. Default 'off'.
79
+ % This parameter controls wether the program uses
80
+ % the stabilized version of the algorithm or
81
+ % not. If the stabilization is on, then the value
82
+ % of mu can momentarily be halved if the program
83
+ % senses that the algorithm is stuck between two
84
+ % points (this is called a stroke). Also if there
85
+ % is no convergence before half of the maximum
86
+ % number of iterations has been reached then mu
87
+ % will be halved for the rest of the rounds.
88
+ %
89
+ %======================================================================
90
+ % --Controlling convergence:
91
+ %
92
+ % 'epsilon' (number) Stopping criterion. Default is 0.0001.
93
+ %
94
+ % 'maxNumIterations' (integer) Maximum number of iterations.
95
+ % Default is 1000.
96
+ %
97
+ % 'maxFinetune' (integer) Maximum number of iterations in
98
+ % fine-tuning. Default 100.
99
+ %
100
+ % 'sampleSize' (number) [0 - 1] Percentage of samples used in
101
+ % one iteration. Samples are chosen in random.
102
+ % Default is 1 (all samples).
103
+ %
104
+ % 'initGuess' (matrix) Initial guess for A. Default is random.
105
+ % You can now do a "one more" like this:
106
+ % [ica, A, W] = fastica(mix, 'numOfIC',3);
107
+ % [ica2, A2, W2] = fastica(mix, 'initGuess', A, 'numOfIC', 4);
108
+ %
109
+ %======================================================================
110
+ % --Graphics and text output:
111
+ %
112
+ % 'verbose' (string) Either 'on' or 'off'. Default is
113
+ % 'on': report progress of algorithm in text format.
114
+ %
115
+ % 'displayMode' (string) Plot running estimates of independent
116
+ % components: 'signals', 'basis', 'filters' or
117
+ % 'off'. Default is 'off'.
118
+ %
119
+ % 'displayInterval' Number of iterations between plots.
120
+ % Default is 1 (plot after every iteration).
121
+ %
122
+ %======================================================================
123
+ % --Controlling reduction of dimension and whitening:
124
+ %
125
+ % Reduction of dimension is controlled by 'firstEig' and 'lastEig', or
126
+ % alternatively by 'interactivePCA'.
127
+ %
128
+ % 'firstEig' (integer) This and 'lastEig' specify the range for
129
+ % eigenvalues that are retained, 'firstEig' is
130
+ % the index of largest eigenvalue to be
131
+ % retained. Default is 1.
132
+ %
133
+ % 'lastEig' (integer) This is the index of the last (smallest)
134
+ % eigenvalue to be retained. Default equals the
135
+ % dimension of data.
136
+ %
137
+ % 'interactivePCA' (string) Either 'on' or 'off'. When set 'on', the
138
+ % eigenvalues are shown to the user and the
139
+ % range can be specified interactively. Default
140
+ % is 'off'. Can also be set to 'gui'. Then the user
141
+ % can use the same GUI that's in FASTICAG.
142
+ %
143
+ % If you already know the eigenvalue decomposition of the covariance
144
+ % matrix, you can avoid computing it again by giving it with the
145
+ % following options:
146
+ %
147
+ % 'pcaE' (matrix) Eigenvectors
148
+ % 'pcaD' (matrix) Eigenvalues
149
+ %
150
+ % If you already know the whitened data, you can give it directly to
151
+ % the algorithm using the following options:
152
+ %
153
+ % 'whiteSig' (matrix) Whitened signal
154
+ % 'whiteMat' (matrix) Whitening matrix
155
+ % 'dewhiteMat' (matrix) dewhitening matrix
156
+ %
157
+ % If values for all the 'whiteSig', 'whiteSig' and 'dewhiteMat' are
158
+ % supplied, they will be used in computing the ICA. PCA and whitening
159
+ % are not performed. Though 'mixedsig' is not used in the main
160
+ % algorithm it still must be entered - some values are still
161
+ % calculated from it.
162
+ %
163
+ % Performing preprocessing only is possible by the option:
164
+ %
165
+ % 'only' (string) Compute only PCA i.e. reduction of
166
+ % dimension ('pca') or only PCA plus whitening
167
+ % ('white'). Default is 'all': do ICA estimation
168
+ % as well. This option changes the output
169
+ % format accordingly. For example:
170
+ %
171
+ % [whitesig, WM, DWM] = FASTICA(mixedsig,
172
+ % 'only', 'white')
173
+ % returns the whitened signals, the whitening matrix
174
+ % (WM) and the dewhitening matrix (DWM). (See also
175
+ % WHITENV.) In FastICA the whitening matrix performs
176
+ % whitening and the reduction of dimension. Dewhitening
177
+ % matrix is the pseudoinverse of whitening matrix.
178
+ %
179
+ % [E, D] = FASTICA(mixedsig, 'only', 'pca')
180
+ % returns the eigenvector (E) and diagonal
181
+ % eigenvalue (D) matrices containing the
182
+ % selected subspaces.
183
+ %
184
+ %======================================================================
185
+ % EXAMPLES
186
+ %
187
+ % [icasig] = FASTICA (mixedsig, 'approach', 'symm', 'g', 'tanh');
188
+ % Do ICA with tanh nonlinearity and in parallel (like
189
+ % maximum likelihood estimation for supergaussian data).
190
+ %
191
+ % [icasig] = FASTICA (mixedsig, 'lastEig', 10, 'numOfIC', 3);
192
+ % Reduce dimension to 10, and estimate only 3
193
+ % independent components.
194
+ %
195
+ % [icasig] = FASTICA (mixedsig, 'verbose', 'off', 'displayMode', 'off');
196
+ % Don't output convergence reports and don't plot
197
+ % independent components.
198
+ %
199
+ %
200
+ % A graphical user interface for FASTICA can be launched by the
201
+ % command FASTICAG
202
+ %
203
+ % See also FASTICAG
204
+
205
+ % @(#)$Id: fastica.m,v 1.14 2005/10/19 13:05:34 jarmo Exp $
206
+
207
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
+ % Check some basic requirements of the data
209
+ if nargin == 0,
210
+ error ('You must supply the mixed data as input argument.');
211
+ end
212
+
213
+ if length (size (mixedsig)) > 2,
214
+ error ('Input data can not have more than two dimensions.');
215
+ end
216
+
217
+ if any (any (isnan (mixedsig))),
218
+ error ('Input data contains NaN''s.');
219
+ end
220
+
221
+ if ~isa (mixedsig, 'double')
222
+ fprintf ('Warning: converting input data into regular (double) precision.\n');
223
+ mixedsig = double (mixedsig);
224
+ end
225
+
226
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
227
+ % Remove the mean and check the data
228
+
229
+ [mixedsig, mixedmean] = remmean(mixedsig);
230
+
231
+ [Dim, NumOfSampl] = size(mixedsig);
232
+
233
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
234
+ % Default values for optional parameters
235
+
236
+ % All
237
+ verbose = 'on';
238
+
239
+ % Default values for 'pcamat' parameters
240
+ firstEig = 1;
241
+ lastEig = Dim;
242
+ interactivePCA = 'off';
243
+
244
+ % Default values for 'fpica' parameters
245
+ approach = 'defl';
246
+ numOfIC = Dim;
247
+ g = 'pow3';
248
+ finetune = 'off';
249
+ a1 = 1;
250
+ a2 = 1;
251
+ myy = 1;
252
+ stabilization = 'off';
253
+ epsilon = 0.0001;
254
+ maxNumIterations = 1000;
255
+ maxFinetune = 5;
256
+ initState = 'rand';
257
+ guess = 0;
258
+ sampleSize = 1;
259
+ displayMode = 'off';
260
+ displayInterval = 1;
261
+
262
+
263
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
264
+ % Parameters for fastICA - i.e. this file
265
+
266
+ b_verbose = 1;
267
+ jumpPCA = 0;
268
+ jumpWhitening = 0;
269
+ only = 3;
270
+ userNumOfIC = 0;
271
+
272
+
273
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274
+ % Read the optional parameters
275
+
276
+ if (rem(length(varargin),2)==1)
277
+ error('Optional parameters should always go by pairs');
278
+ else
279
+ for i=1:2:(length(varargin)-1)
280
+ if ~ischar (varargin{i}),
281
+ error (['Unknown type of optional parameter name (parameter' ...
282
+ ' names must be strings).']);
283
+ end
284
+ % change the value of parameter
285
+ switch lower (varargin{i})
286
+ case 'stabilization'
287
+ stabilization = lower (varargin{i+1});
288
+ case 'maxfinetune'
289
+ maxFinetune = varargin{i+1};
290
+ case 'samplesize'
291
+ sampleSize = varargin{i+1};
292
+ case 'verbose'
293
+ verbose = lower (varargin{i+1});
294
+ % silence this program also
295
+ if strcmp (verbose, 'off'), b_verbose = 0; end
296
+ case 'firsteig'
297
+ firstEig = varargin{i+1};
298
+ case 'lasteig'
299
+ lastEig = varargin{i+1};
300
+ case 'interactivepca'
301
+ interactivePCA = lower (varargin{i+1});
302
+ case 'approach'
303
+ approach = lower (varargin{i+1});
304
+ case 'numofic'
305
+ numOfIC = varargin{i+1};
306
+ % User has supplied new value for numOfIC.
307
+ % We'll use this information later on...
308
+ userNumOfIC = 1;
309
+ case 'g'
310
+ g = lower (varargin{i+1});
311
+ case 'finetune'
312
+ finetune = lower (varargin{i+1});
313
+ case 'a1'
314
+ a1 = varargin{i+1};
315
+ case 'a2'
316
+ a2 = varargin{i+1};
317
+ case {'mu', 'myy'}
318
+ myy = varargin{i+1};
319
+ case 'epsilon'
320
+ epsilon = varargin{i+1};
321
+ case 'maxnumiterations'
322
+ maxNumIterations = varargin{i+1};
323
+ case 'initguess'
324
+ % no use setting 'guess' if the 'initState' is not set
325
+ initState = 'guess';
326
+ guess = varargin{i+1};
327
+ case 'displaymode'
328
+ displayMode = lower (varargin{i+1});
329
+ case 'displayinterval'
330
+ displayInterval = varargin{i+1};
331
+ case 'pcae'
332
+ % calculate if there are enought parameters to skip PCA
333
+ jumpPCA = jumpPCA + 1;
334
+ E = varargin{i+1};
335
+ case 'pcad'
336
+ % calculate if there are enought parameters to skip PCA
337
+ jumpPCA = jumpPCA + 1;
338
+ D = varargin{i+1};
339
+ case 'whitesig'
340
+ % calculate if there are enought parameters to skip PCA and whitening
341
+ jumpWhitening = jumpWhitening + 1;
342
+ whitesig = varargin{i+1};
343
+ case 'whitemat'
344
+ % calculate if there are enought parameters to skip PCA and whitening
345
+ jumpWhitening = jumpWhitening + 1;
346
+ whiteningMatrix = varargin{i+1};
347
+ case 'dewhitemat'
348
+ % calculate if there are enought parameters to skip PCA and whitening
349
+ jumpWhitening = jumpWhitening + 1;
350
+ dewhiteningMatrix = varargin{i+1};
351
+ case 'only'
352
+ % if the user only wants to calculate PCA or...
353
+ switch lower (varargin{i+1})
354
+ case 'pca'
355
+ only = 1;
356
+ case 'white'
357
+ only = 2;
358
+ case 'all'
359
+ only = 3;
360
+ end
361
+
362
+ otherwise
363
+ % Hmmm, something wrong with the parameter string
364
+ error(['Unrecognized parameter: ''' varargin{i} '''']);
365
+ end;
366
+ end;
367
+ end
368
+
369
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
370
+ % print information about data
371
+ if b_verbose
372
+ fprintf('Number of signals: %d\n', Dim);
373
+ fprintf('Number of samples: %d\n', NumOfSampl);
374
+ end
375
+
376
+ % Check if the data has been entered the wrong way,
377
+ % but warn only... it may be on purpose
378
+
379
+ if Dim > NumOfSampl
380
+ if b_verbose
381
+ fprintf('Warning: ');
382
+ fprintf('The signal matrix may be oriented in the wrong way.\n');
383
+ fprintf('In that case transpose the matrix.\n\n');
384
+ end
385
+ end
386
+
387
+
388
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
389
+ % Calculating PCA
390
+
391
+ % We need the results of PCA for whitening, but if we don't
392
+ % need to do whitening... then we dont need PCA...
393
+ if jumpWhitening == 3
394
+ if b_verbose,
395
+ fprintf ('Whitened signal and corresponding matrises supplied.\n');
396
+ fprintf ('PCA calculations not needed.\n');
397
+ end;
398
+ else
399
+
400
+ % OK, so first we need to calculate PCA
401
+ % Check to see if we already have the PCA data
402
+ if jumpPCA == 2,
403
+ if b_verbose,
404
+ fprintf ('Values for PCA calculations supplied.\n');
405
+ fprintf ('PCA calculations not needed.\n');
406
+ end;
407
+ else
408
+ % display notice if the user entered one, but not both, of E and D.
409
+ if (jumpPCA > 0) & (b_verbose),
410
+ fprintf ('You must suply all of these in order to jump PCA:\n');
411
+ fprintf ('''pcaE'', ''pcaD''.\n');
412
+ end;
413
+
414
+ % Calculate PCA
415
+ [E, D]=pcamat(mixedsig, firstEig, lastEig, interactivePCA, verbose);
416
+ end
417
+ end
418
+
419
+ % skip the rest if user only wanted PCA
420
+ if only > 1
421
+
422
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
423
+ % Whitening the data
424
+
425
+ % Check to see if the whitening is needed...
426
+ if jumpWhitening == 3,
427
+ if b_verbose,
428
+ fprintf ('Whitening not needed.\n');
429
+ end;
430
+ else
431
+
432
+ % Whitening is needed
433
+ % display notice if the user entered some of the whitening info, but not all.
434
+ if (jumpWhitening > 0) & (b_verbose),
435
+ fprintf ('You must suply all of these in order to jump whitening:\n');
436
+ fprintf ('''whiteSig'', ''whiteMat'', ''dewhiteMat''.\n');
437
+ end;
438
+
439
+ % Calculate the whitening
440
+ [whitesig, whiteningMatrix, dewhiteningMatrix] = whitenv ...
441
+ (mixedsig, E, D, verbose);
442
+ end
443
+
444
+ end % if only > 1
445
+
446
+ % skip the rest if user only wanted PCA and whitening
447
+ if only > 2
448
+
449
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
450
+ % Calculating the ICA
451
+
452
+ % Check some parameters
453
+ % The dimension of the data may have been reduced during PCA calculations.
454
+ % The original dimension is calculated from the data by default, and the
455
+ % number of IC is by default set to equal that dimension.
456
+
457
+ Dim = size(whitesig, 1);
458
+
459
+ % The number of IC's must be less or equal to the dimension of data
460
+ if numOfIC > Dim
461
+ numOfIC = Dim;
462
+ % Show warning only if verbose = 'on' and user supplied a value for 'numOfIC'
463
+ if (b_verbose & userNumOfIC)
464
+ fprintf('Warning: estimating only %d independent components\n', numOfIC);
465
+ fprintf('(Can''t estimate more independent components than dimension of data)\n');
466
+ end
467
+ end
468
+
469
+ % Calculate the ICA with fixed point algorithm.
470
+ [A, W] = fpica (whitesig, whiteningMatrix, dewhiteningMatrix, approach, ...
471
+ numOfIC, g, finetune, a1, a2, myy, stabilization, epsilon, ...
472
+ maxNumIterations, maxFinetune, initState, guess, sampleSize, ...
473
+ displayMode, displayInterval, verbose);
474
+
475
+ % Check for valid return
476
+ if ~isempty(W)
477
+ % Add the mean back in.
478
+ if b_verbose
479
+ fprintf('Adding the mean back to the data.\n');
480
+ end
481
+ icasig = W * mixedsig + (W * mixedmean) * ones(1, NumOfSampl);
482
+ %icasig = W * mixedsig;
483
+ if b_verbose & ...
484
+ (max(abs(W * mixedmean)) > 1e-9) & ...
485
+ (strcmp(displayMode,'signals') | strcmp(displayMode,'on'))
486
+ fprintf('Note that the plots don''t have the mean added.\n');
487
+ end
488
+ else
489
+ icasig = [];
490
+ end
491
+
492
+ end % if only > 2
493
+
494
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
495
+ % The output depends on the number of output parameters
496
+ % and the 'only' parameter.
497
+
498
+ if only == 1 % only PCA
499
+ Out1 = E;
500
+ Out2 = D;
501
+ elseif only == 2 % only PCA & whitening
502
+ if nargout == 2
503
+ Out1 = whiteningMatrix;
504
+ Out2 = dewhiteningMatrix;
505
+ else
506
+ Out1 = whitesig;
507
+ Out2 = whiteningMatrix;
508
+ Out3 = dewhiteningMatrix;
509
+ end
510
+ else % ICA
511
+ if nargout == 2
512
+ Out1 = A;
513
+ Out2 = W;
514
+ else
515
+ Out1 = icasig;
516
+ Out2 = A;
517
+ Out3 = W;
518
+ end
519
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fasticag.m ADDED
@@ -0,0 +1,667 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function fasticag(mixedsig, InitialGuess)
2
+ %FASTICAG - Fast Independent Component Analysis, the Graphical User Interface
3
+ %
4
+ % FASTICAG gives a graphical user interface for performing independent
5
+ % component analysis by the FastICA package. No arguments are
6
+ % necessary in the function call.
7
+ %
8
+ % Optional arguments can be given in the form:
9
+ % FASTICAG(mixedsig, initialGuess) where the matrix mixedsig contains the
10
+ % multidimensional signals as row vectors, and initialGuess gives the
11
+ % initial value for the mixing matrix used in the algorithm.
12
+ %
13
+ % FASTICA uses the fixed-point algorithm developed by Aapo Hyvarinen,
14
+ % see http://www.cis.hut.fi/projects/ica/fastica/. The Matlab package
15
+ % was programmed by Hugo Gavert, Jarmo Hurri, Jaakko Sarela, and Aapo
16
+ % Hyvarinen.
17
+ %
18
+ %
19
+ % See also FASTICA
20
+
21
+ % @(#)$Id: fasticag.m,v 1.5 2005/10/19 13:05:34 jarmo Exp $
22
+
23
+
24
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
+ % Global values
26
+
27
+ % Handle to this main figure
28
+ global hf_FastICA_MAIN;
29
+
30
+ % Check to see if GUI is already running
31
+ % Can't have more than one copy - otherwise the global
32
+ % variables and handles can get mixed up.
33
+ if ~isempty(hf_FastICA_MAIN)
34
+ error('FastICA GUI already running!');
35
+ end
36
+
37
+
38
+ % Handles to other controls in this main window
39
+ global ht_FastICA_mixedStatus;
40
+ global ht_FastICA_dim;
41
+ global ht_FastICA_numOfSamp;
42
+ global ht_FastICA_newDim;
43
+ global ht_FastICA_whiteStatus;
44
+ global ht_FastICA_icaStatus;
45
+ global hpm_FastICA_approach;
46
+ global he_FastICA_numOfIC;
47
+ global hpm_FastICA_g;
48
+ global hpm_FastICA_stabilization;
49
+
50
+ % These global variables are used to store all the values
51
+ % I used to use the 'UserData' field of components, but
52
+ % that got too complex, so I decided to put everything
53
+ % in global variables
54
+ global g_FastICA_mixedsig;
55
+ global g_FastICA_pca_D;
56
+ global g_FastICA_pca_E;
57
+ global g_FastICA_white_sig;
58
+ global g_FastICA_white_wm;
59
+ global g_FastICA_white_dwm;
60
+ global g_FastICA_ica_sig;
61
+ global g_FastICA_ica_A;
62
+ global g_FastICA_ica_W;
63
+ global g_FastICA_initGuess;
64
+ global g_FastICA_approach;
65
+ global g_FastICA_numOfIC;
66
+ global g_FastICA_g;
67
+ global g_FastICA_finetune;
68
+ global g_FastICA_a1;
69
+ global g_FastICA_a2;
70
+ global g_FastICA_myy;
71
+ global g_FastICA_stabilization;
72
+ global g_FastICA_epsilon;
73
+ global g_FastICA_maxNumIte;
74
+ global g_FastICA_maxFinetune;
75
+ global g_FastICA_sampleSize;
76
+ global g_FastICA_initState;
77
+ global g_FastICA_displayMo;
78
+ global g_FastICA_displayIn;
79
+ global g_FastICA_verbose;
80
+
81
+ % initial values for them:
82
+ % All the initial values are set here - even for
83
+ % variables that are not used in this file
84
+
85
+ if nargin < 2
86
+ g_FastICA_initGuess = 1;
87
+ % The user didn't enter initial guess so we default
88
+ % back to random initial state.
89
+ g_FastICA_initState = 1; % see below for string values
90
+ else
91
+ g_FastICA_initGuess = InitialGuess;
92
+ % If initial guess was entered, then the user probably
93
+ % wan't to use it, eh?
94
+ g_FastICA_initState = 2; % see below for string values
95
+ end
96
+
97
+ if nargin < 1
98
+ g_FastICA_mixedsig = [];
99
+ else
100
+ g_FastICA_mixedsig = mixedsig; % We'll remove mean
101
+ end % the first time we
102
+ % use this.
103
+
104
+ % Global variable for stopping the ICA calculations
105
+ global g_FastICA_interrupt;
106
+
107
+ g_FastICA_pca_D = [];
108
+ g_FastICA_pca_E = [];
109
+ g_FastICA_white_sig = [];
110
+ g_FastICA_white_wm = [];
111
+ g_FastICA_white_dwm = [];
112
+ g_FastICA_ica_sig = [];
113
+ g_FastICA_ica_A = [];
114
+ g_FastICA_ica_W = [];
115
+ g_FastICA_approach = 1; % see below for string values
116
+ g_FastICA_numOfIC = 0;
117
+ g_FastICA_g = 1; % see below for string values
118
+ g_FastICA_finetune = 5; % see below for string values
119
+ g_FastICA_a1 = 1;
120
+ g_FastICA_a2 = 1;
121
+ g_FastICA_myy = 1;
122
+ g_FastICA_stabilization = 2; % see below for string values
123
+ g_FastICA_epsilon = 0.0001;
124
+ g_FastICA_maxNumIte = 1000;
125
+ g_FastICA_maxFinetune = 100;
126
+ g_FastICA_sampleSize = 1;
127
+ g_FastICA_displayMo = 1; % see below for string values
128
+ g_FastICA_displayIn = 1;
129
+ g_FastICA_verbose = 1; % see below for string values
130
+
131
+ % These are regarded as constants and are used to store
132
+ % the strings for the popup menus the current value is
133
+ % seen in the variables above
134
+ % D - refers to strings that are displayed
135
+ % V - refers to string values that are used in FPICA
136
+ global c_FastICA_appr_strD;
137
+ global c_FastICA_appr_strV;
138
+ global c_FastICA_g1_strD;
139
+ global c_FastICA_g1_strV;
140
+ global c_FastICA_g2_strD;
141
+ global c_FastICA_g2_strV;
142
+ global c_FastICA_finetune_strD;
143
+ global c_FastICA_finetune_strV;
144
+ global c_FastICA_stabili_strD;
145
+ global c_FastICA_stabili_strV;
146
+ global c_FastICA_iSta_strD;
147
+ global c_FastICA_iSta_strV;
148
+ global c_FastICA_dMod_strD;
149
+ global c_FastICA_dMod_strV;
150
+ global c_FastICA_verb_strD;
151
+ global c_FastICA_verb_strV;
152
+
153
+ % All the values for these are set here - even for
154
+ % variables that are not used in this file
155
+
156
+ c_FastICA_appr_strD = 'deflation|symmetric';
157
+ c_FastICA_appr_strV = ['defl';'symm'];
158
+ % The 'g1' and 'g2' below correspond to the values of approach (1 or 2)
159
+ % Deflation and Symmetric used to have a bit different selection
160
+ % of available nonlinearities.
161
+ c_FastICA_g1_strD = 'pow3|tanh|gauss|skew';
162
+ c_FastICA_g1_strV = ['pow3';'tanh';'gaus';'skew'];
163
+ c_FastICA_g2_strD = 'pow3|tanh|gauss|skew';
164
+ c_FastICA_g2_strV = ['pow3';'tanh';'gaus';'skew'];
165
+ c_FastICA_finetune_strD = 'pow3|tanh|gauss|skew|off';
166
+ c_FastICA_finetune_strV = ['pow3';'tanh';'gaus';'skew';'off '];
167
+ c_FastICA_stabili_strD = 'on|off';
168
+ c_FastICA_stabili_strV = ['on ';'off'];
169
+ c_FastICA_iSta_strD = 'random|guess';
170
+ c_FastICA_iSta_strV = ['rand ';'guess'];
171
+ c_FastICA_dMod_strD = 'signals|basis|filters|off';
172
+ c_FastICA_dMod_strV = ['signals';'basis ';'filters';'off '];
173
+ c_FastICA_verb_strD = 'on|off';
174
+ c_FastICA_verb_strV = ['on ';'off'];
175
+
176
+
177
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
178
+ % Configuration options
179
+ FIGURENAME = 'FastICA';
180
+ FIGURETAG = 'f_FastICA';
181
+ SCREENSIZE = get(0,'ScreenSize');
182
+ FIGURESIZE = [round(0.1*SCREENSIZE(3)) (SCREENSIZE(4)-round(0.1*SCREENSIZE(4))-370) 530 370];
183
+
184
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
+ % Create the figure
186
+ a = figure('Color',[0.8 0.8 0.8], ...
187
+ 'PaperType','a4letter', ...
188
+ 'Name', FIGURENAME, ...
189
+ 'NumberTitle', 'off', ...
190
+ 'Tag', FIGURETAG, ...
191
+ 'Position', FIGURESIZE, ...
192
+ 'MenuBar', 'none');
193
+ % Resizing has to be denied after the window has been created -
194
+ % otherwise the window shows only as a tiny window in Windows XP.
195
+ set (a, 'Resize', 'off');
196
+
197
+ hf_FastICA_MAIN = a;
198
+
199
+ set(hf_FastICA_MAIN, 'HandleVisibility', 'callback');
200
+
201
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202
+ % From here on it get's ugly as I have not had time to clean it up
203
+
204
+
205
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
206
+ % Create the frames
207
+ pos_l=2;
208
+ pos_w=FIGURESIZE(3)-4;
209
+ pos_h=FIGURESIZE(4)-4;
210
+ pos_t=FIGURESIZE(4)-2-pos_h;
211
+ h_f_background = uicontrol('Parent',a, ...
212
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
213
+ 'Position',[pos_l pos_t pos_w pos_h], ...
214
+ 'Style','frame', ...
215
+ 'Tag','f_background');
216
+
217
+ pos_l=4;
218
+ pos_w=400;
219
+ pos_h=106;
220
+ pos_t=FIGURESIZE(4)-4-pos_h;
221
+ h_f_mixed = uicontrol('Parent',a, ...
222
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
223
+ 'Position',[pos_l pos_t pos_w pos_h], ...
224
+ 'Style','frame', ...
225
+ 'Tag','f_mixed');
226
+
227
+ pos_h=90;
228
+ pos_t=FIGURESIZE(4)-(106+4+2)-pos_h;
229
+ h_f_white = uicontrol('Parent',a, ...
230
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
231
+ 'Position',[pos_l pos_t pos_w pos_h], ...
232
+ 'Style','frame', ...
233
+ 'Tag','f_white');
234
+
235
+ pos_h=pos_t - 4 - 2;
236
+ pos_t=4;
237
+ h_f_ica = uicontrol('Parent',a, ...
238
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
239
+ 'Position',[pos_l pos_t pos_w pos_h], ...
240
+ 'Style','frame', ...
241
+ 'Tag','f_ica');
242
+
243
+ pos_w=120;
244
+ pos_l=FIGURESIZE(3)-(pos_w+2+2);
245
+ pos_h=FIGURESIZE(4)-2*4;
246
+ pos_t=FIGURESIZE(4)-(4)-pos_h;
247
+ h_f_side = uicontrol('Parent',a, ...
248
+ 'BackgroundColor',[0.5 0.5 0.5], ...
249
+ 'Position',[pos_l pos_t pos_w pos_h], ...
250
+ 'Style','frame', ...
251
+ 'Tag','f_side');
252
+
253
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254
+ % Controls in f_mixed
255
+ bgc = get(h_f_mixed, 'BackgroundColor');
256
+
257
+ pos_vspace = 6;
258
+ pos_hspace = 6;
259
+
260
+ pos_frame=get(h_f_mixed, 'Position');
261
+ pos_l = pos_frame(1) + 6;
262
+ pos_h = 16;
263
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
264
+ pos_w = 150;
265
+ b = uicontrol('Parent',a, ...
266
+ 'BackgroundColor',bgc, ...
267
+ 'HorizontalAlignment','left', ...
268
+ 'Position',[pos_l pos_t pos_w pos_h], ...
269
+ 'String','Mixed signals:', ...
270
+ 'FontWeight', 'bold', ...
271
+ 'Style','text', ...
272
+ 'Tag','t_mixed');
273
+
274
+ pos_l = pos_l + pos_w;
275
+ pos_w = 120;
276
+ ht_FastICA_mixedStatus = uicontrol('Parent',a, ...
277
+ 'BackgroundColor',bgc, ...
278
+ 'HorizontalAlignment','left', ...
279
+ 'Position',[pos_l pos_t pos_w pos_h], ...
280
+ 'String','Not loaded yet', ...
281
+ 'Style','text', ...
282
+ 'Tag','t_mixedstatus');
283
+
284
+ % V�h�n v�li�
285
+ pos_t = pos_t - 8;
286
+
287
+ pos_l = pos_frame(1) + 6;
288
+ pos_t = pos_t - pos_h;
289
+ pos_w = 150;
290
+ b = uicontrol('Parent',a, ...
291
+ 'BackgroundColor',bgc, ...
292
+ 'HorizontalAlignment','left', ...
293
+ 'Position',[pos_l pos_t pos_w pos_h], ...
294
+ 'String','Number of signals:', ...
295
+ 'Style','text', ...
296
+ 'Tag','t_2');
297
+
298
+ pos_l = pos_l + pos_w;
299
+ pos_w = 50;
300
+ ht_FastICA_dim = uicontrol('Parent',a, ...
301
+ 'BackgroundColor',bgc, ...
302
+ 'HorizontalAlignment','left', ...
303
+ 'Position',[pos_l pos_t pos_w pos_h], ...
304
+ 'String','', ...
305
+ 'Style','text', ...
306
+ 'Tag','t_dim');
307
+
308
+ pos_l = pos_frame(1) + 6;
309
+ pos_t = pos_t - pos_h;
310
+ pos_w = 150;
311
+ b = uicontrol('Parent',a, ...
312
+ 'BackgroundColor',bgc, ...
313
+ 'HorizontalAlignment','left', ...
314
+ 'Position',[pos_l pos_t pos_w pos_h], ...
315
+ 'String','Number of samples:', ...
316
+ 'Style','text', ...
317
+ 'Tag','t_3');
318
+
319
+ pos_l = pos_l + pos_w;
320
+ pos_w = 50;
321
+ ht_FastICA_numOfSamp = uicontrol('Parent',a, ...
322
+ 'BackgroundColor',bgc, ...
323
+ 'HorizontalAlignment','left', ...
324
+ 'Position',[pos_l pos_t pos_w pos_h], ...
325
+ 'String','', ...
326
+ 'Style','text', ...
327
+ 'Tag','t_numOfSamp');
328
+
329
+
330
+ % Buttons
331
+ pos_l = pos_frame(1) + pos_hspace;
332
+ pos_w = 110;
333
+ pos_h = 30;
334
+ pos_t = pos_frame(2) + pos_vspace;
335
+ b = uicontrol('Parent',a, ...
336
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
337
+ 'Callback','gui_cb Transpose', ...
338
+ 'Interruptible', 'off', ...
339
+ 'Position',[pos_l pos_t pos_w pos_h], ...
340
+ 'String','Transpose', ...
341
+ 'Tag','b_Transpose');
342
+
343
+ pos_w = 130;
344
+ pos_l = pos_frame(1) + pos_frame(3) - pos_hspace - pos_w;
345
+ b = uicontrol('Parent',a, ...
346
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
347
+ 'Callback','gui_cb ShowMixed', ...
348
+ 'Interruptible', 'off', ...
349
+ 'Position',[pos_l pos_t pos_w pos_h], ...
350
+ 'String','Plot data', ...
351
+ 'Tag','b_ShowMixed');
352
+
353
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354
+ % Controls in f_white
355
+ pos_frame=get(h_f_white, 'Position');
356
+ pos_l = pos_frame(1) + 6;
357
+ pos_h = 16;
358
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
359
+ pos_w = 150;
360
+ b = uicontrol('Parent',a, ...
361
+ 'BackgroundColor',bgc, ...
362
+ 'HorizontalAlignment','left', ...
363
+ 'Position',[pos_l pos_t pos_w pos_h], ...
364
+ 'String','Dimension control:', ...
365
+ 'FontWeight', 'bold', ...
366
+ 'Style','text', ...
367
+ 'Tag','t_white');
368
+
369
+ pos_l = pos_l + pos_w;
370
+ pos_w = 120;
371
+ ht_FastICA_whiteStatus = uicontrol('Parent',a, ...
372
+ 'BackgroundColor',bgc, ...
373
+ 'HorizontalAlignment','left', ...
374
+ 'Position',[pos_l pos_t pos_w pos_h], ...
375
+ 'String','', ...
376
+ 'Style','text', ...
377
+ 'Tag','t_whiteStatus');
378
+
379
+ % V�h�n v�li�
380
+ pos_t = pos_t - 8;
381
+
382
+ pos_l = pos_frame(1) + 6;
383
+ pos_t = pos_t - pos_h;
384
+ pos_w = 150;
385
+ b = uicontrol('Parent',a, ...
386
+ 'BackgroundColor',bgc, ...
387
+ 'HorizontalAlignment','left', ...
388
+ 'Position',[pos_l pos_t pos_w pos_h], ...
389
+ 'String','Reduced dimension:', ...
390
+ 'Style','text', ...
391
+ 'Tag','t_4');
392
+
393
+ pos_l = pos_l + pos_w;
394
+ pos_w = 50;
395
+ ht_FastICA_newDim = uicontrol('Parent',a, ...
396
+ 'BackgroundColor',bgc, ...
397
+ 'HorizontalAlignment','left', ...
398
+ 'Position',[pos_l pos_t pos_w pos_h], ...
399
+ 'String','', ...
400
+ 'Style','text', ...
401
+ 'Tag','t_newDim');
402
+
403
+
404
+ % buttons
405
+
406
+ pos_l = pos_frame(1) + pos_hspace;
407
+ pos_w = 110;
408
+ pos_h = 30;
409
+ pos_t = pos_frame(2) + pos_vspace;
410
+ b = uicontrol('Parent',a, ...
411
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
412
+ 'Callback','gui_cb DoPCA', ...
413
+ 'Interruptible', 'off', ...
414
+ 'Position',[pos_l pos_t pos_w pos_h], ...
415
+ 'String','Reduce dim.', ...
416
+ 'Tag','b_DoPCA');
417
+
418
+ pos_l = pos_l + pos_w + pos_hspace;
419
+ b = uicontrol('Parent',a, ...
420
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
421
+ 'Callback','gui_cb OrigDim', ...
422
+ 'Interruptible', 'off', ...
423
+ 'Position',[pos_l pos_t pos_w pos_h], ...
424
+ 'String','Original dim.', ...
425
+ 'Tag','b_OrigDim');
426
+
427
+ pos_w = 130;
428
+ pos_h = 30;
429
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
430
+ pos_t = pos_frame(2) + 6;
431
+ b = uicontrol('Parent',a, ...
432
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
433
+ 'Callback','gui_cb ShowWhite', ...
434
+ 'Interruptible', 'off', ...
435
+ 'Position',[pos_l pos_t pos_w pos_h], ...
436
+ 'String','Plot whitened', ...
437
+ 'Tag','b_ShowWhite');
438
+
439
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
440
+ % Controls in f_ica
441
+ pos_frame=get(h_f_ica, 'Position');
442
+ pos_l = pos_frame(1) + 6;
443
+ pos_h = 20;
444
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
445
+ pos_w = 150;
446
+ b = uicontrol('Parent',a, ...
447
+ 'BackgroundColor',bgc, ...
448
+ 'HorizontalAlignment','left', ...
449
+ 'Position',[pos_l pos_t pos_w pos_h], ...
450
+ 'String','Fixed point ICA:', ...
451
+ 'FontWeight', 'bold', ...
452
+ 'Style','text', ...
453
+ 'Tag','t_white');
454
+
455
+ pos_l = pos_l + pos_w;
456
+ pos_w = 120;
457
+ ht_FastICA_icaStatus = uicontrol('Parent',a, ...
458
+ 'BackgroundColor',bgc, ...
459
+ 'HorizontalAlignment','left', ...
460
+ 'Position',[pos_l pos_t pos_w pos_h], ...
461
+ 'String','Not yet done', ...
462
+ 'Style','text', ...
463
+ 'Tag','t_icaStatus');
464
+
465
+ % V�h�n v�li�
466
+ pos_t = pos_t - 8;
467
+
468
+ %pos_l = pos_frame(1) + 6;
469
+ pos_l = pos_frame(1) + 6 + 150;
470
+ pos_t = pos_t - pos_h;
471
+ %pos_w = 260;
472
+ pos_w = 120;
473
+ b = uicontrol('Parent',a, ...
474
+ 'BackgroundColor',bgc, ...
475
+ 'HorizontalAlignment','left', ...
476
+ 'Position',[pos_l pos_t pos_w pos_h], ...
477
+ 'String','Approach:', ...
478
+ 'Style','text', ...
479
+ 'Tag','t_5');
480
+
481
+ pos_w = 100;
482
+ %pos_t = pos_t - 4;
483
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
484
+ hpm_FastICA_approach = uicontrol('Parent',a, ...
485
+ 'BackgroundColor',bgc, ...
486
+ 'Callback','gui_cb ChangeApproach', ...
487
+ 'Position',[pos_l pos_t pos_w pos_h], ...
488
+ 'String',c_FastICA_appr_strD, ...
489
+ 'Style','popupmenu', ...
490
+ 'Tag','pm_approach', ...
491
+ 'Value',g_FastICA_approach);
492
+
493
+ %pos_t = pos_t - 4;
494
+ %pos_l = pos_frame(1) + 6;
495
+ pos_l = pos_frame(1) + 6 + 150;
496
+ pos_t = pos_t - pos_h;
497
+ %pos_w = 260;
498
+ pos_w = 120;
499
+ b = uicontrol('Parent',a, ...
500
+ 'BackgroundColor',bgc, ...
501
+ 'HorizontalAlignment','left', ...
502
+ 'Position',[pos_l pos_t pos_w pos_h], ...
503
+ 'String','Number of ICs:', ...
504
+ 'Style','text', ...
505
+ 'Tag','t_6');
506
+
507
+ pos_w = 100;
508
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
509
+ he_FastICA_numOfIC = uicontrol('Parent',a, ...
510
+ 'BackgroundColor',[1 1 1], ...
511
+ 'Callback','gui_cb ChangeNumOfIC', ...
512
+ 'HorizontalAlignment','right', ...
513
+ 'Position',[pos_l pos_t pos_w pos_h], ...
514
+ 'String','0', ...
515
+ 'Style','edit', ...
516
+ 'Tag','e_numOfIC');
517
+
518
+ %pos_t = pos_t - 4;
519
+ %pos_l = pos_frame(1) + 6;
520
+ pos_l = pos_frame(1) + 6 + 150;
521
+ pos_t = pos_t - pos_h;
522
+ %pos_w = 260;
523
+ pos_w = 120;
524
+ b = uicontrol('Parent',a, ...
525
+ 'BackgroundColor',bgc, ...
526
+ 'HorizontalAlignment','left', ...
527
+ 'Position',[pos_l pos_t pos_w pos_h], ...
528
+ 'String','Nonlinearity (g):', ...
529
+ 'Style','text', ...
530
+ 'Tag','t_71');
531
+
532
+ %pos_t = pos_t - 4;
533
+ pos_w = 100;
534
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
535
+ hpm_FastICA_g = uicontrol('Parent',a, ...
536
+ 'BackgroundColor',bgc, ...
537
+ 'Callback','gui_cb ChangeG', ...
538
+ 'Position',[pos_l pos_t pos_w pos_h], ...
539
+ 'String',c_FastICA_g1_strD, ...
540
+ 'Style','popupmenu', ...
541
+ 'Tag','pm_g', ...
542
+ 'Value',g_FastICA_g);
543
+
544
+ %pos_t = pos_t - 4;
545
+ %pos_l = pos_frame(1) + 6;
546
+ pos_l = pos_frame(1) + 6 + 150;
547
+ pos_t = pos_t - pos_h;
548
+ %pos_w = 260;
549
+ pos_w = 120;
550
+ b = uicontrol('Parent',a, ...
551
+ 'BackgroundColor',bgc, ...
552
+ 'HorizontalAlignment','left', ...
553
+ 'Position',[pos_l pos_t pos_w pos_h], ...
554
+ 'String','Stabilization:', ...
555
+ 'Style','text', ...
556
+ 'Tag','t_71a');
557
+
558
+ %pos_t = pos_t - 4;
559
+ pos_w = 100;
560
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w;
561
+ hpm_FastICA_stabilization = uicontrol('Parent',a, ...
562
+ 'BackgroundColor',bgc, ...
563
+ 'Callback','gui_cb ChangeStab', ...
564
+ 'Position',[pos_l pos_t pos_w pos_h], ...
565
+ 'String',c_FastICA_stabili_strD, ...
566
+ 'Style','popupmenu', ...
567
+ 'Tag','pm_stab', ...
568
+ 'Value',g_FastICA_stabilization);
569
+
570
+
571
+
572
+ pos_l = pos_frame(1) + pos_vspace;
573
+ pos_w = 110;
574
+ pos_h = 30;
575
+ pos_t = pos_frame(2) + pos_hspace;
576
+ b = uicontrol('Parent',a, ...
577
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
578
+ 'Callback','gui_cb AdvOpt', ...
579
+ 'Position',[pos_l pos_t pos_w pos_h], ...
580
+ 'String','Adv. options >>', ...
581
+ 'Tag','b_advOpt');
582
+
583
+ pos_w = 130;
584
+ pos_h = 30;
585
+ pos_l = pos_frame(1) + pos_frame(3) - pos_vspace - pos_w;
586
+ b = uicontrol('Parent',a, ...
587
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
588
+ 'Callback','gui_cb ShowICASig', ...
589
+ 'Interruptible', 'on', ...
590
+ 'Position',[pos_l pos_t pos_w pos_h], ...
591
+ 'String','Plot ICs', ...
592
+ 'Tag','b_ShowICASig');
593
+
594
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
595
+ % Controls in f_side
596
+ pos_vspace = 6;
597
+ pos_hspace = 10;
598
+ pos_temp=get(h_f_side, 'Position');
599
+ pos_l=pos_temp(1)+pos_hspace;
600
+ pos_w=100;
601
+ pos_h=30;
602
+ pos_t=pos_temp(2)+pos_temp(4)-pos_vspace-pos_h;
603
+
604
+ b = uicontrol('Parent',a, ...
605
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
606
+ 'Callback','gui_cb LoadData', ...
607
+ 'Interruptible', 'off', ...
608
+ 'Position',[pos_l pos_t pos_w pos_h], ...
609
+ 'String','Load data', ...
610
+ 'Tag','b_LoadData');
611
+
612
+
613
+ pos_t=pos_t-pos_h-pos_vspace;
614
+ b = uicontrol('Parent',a, ...
615
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
616
+ 'Callback','gui_cb DoFPICA', ...
617
+ 'Interruptible', 'on', ...
618
+ 'Position',[pos_l pos_t pos_w pos_h], ...
619
+ 'String','Do ICA', ...
620
+ 'Tag','b_DoFPICA');
621
+
622
+ pos_t=pos_t-pos_h-pos_vspace;
623
+ b = uicontrol('Parent',a, ...
624
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
625
+ 'Callback','gui_cb SaveData', ...
626
+ 'Interruptible', 'off', ...
627
+ 'Position',[pos_l pos_t pos_w pos_h], ...
628
+ 'String','Save results', ...
629
+ 'Tag','b_SaveData');
630
+
631
+ pos_t=pos_t-pos_h-pos_vspace;
632
+ b = uicontrol('Parent',a, ...
633
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
634
+ 'Callback','gui_cb Quit', ...
635
+ 'Position',[pos_l pos_t pos_w pos_h], ...
636
+ 'String','Quit', ...
637
+ 'Tag','b_Quit');
638
+
639
+ pos_t=pos_t-pos_h-pos_vspace;
640
+ b = uicontrol('Parent',a, ...
641
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
642
+ 'Callback','gui_cb Interrupt', ...
643
+ 'Position',[pos_l pos_t pos_w pos_h], ...
644
+ 'String','Interrupt', ...
645
+ 'Visible','off', ...
646
+ 'Tag','b_Interrupt');
647
+
648
+ pos_t = pos_frame(2) + pos_vspace + pos_h + pos_vspace;
649
+ b = uicontrol('Parent',a, ...
650
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
651
+ 'Callback','gui_cb About', ...
652
+ 'Position',[pos_l pos_t pos_w pos_h], ...
653
+ 'String','About...', ...
654
+ 'Tag','b_About');
655
+
656
+ pos_t = pos_frame(2) + pos_vspace;
657
+ b = uicontrol('Parent',a, ...
658
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
659
+ 'Callback','gui_cb Help', ...
660
+ 'Position',[pos_l pos_t pos_w pos_h], ...
661
+ 'String','Help', ...
662
+ 'Tag','b_Help');
663
+
664
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
665
+ % Do rest of the initialization...
666
+ gui_cb InitAll;
667
+
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/fpica.m ADDED
@@ -0,0 +1,905 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [A, W] = fpica(X, whiteningMatrix, dewhiteningMatrix, approach, ...
2
+ numOfIC, g, finetune, a1, a2, myy, stabilization, ...
3
+ epsilon, maxNumIterations, maxFinetune, initState, ...
4
+ guess, sampleSize, displayMode, displayInterval, ...
5
+ s_verbose);
6
+ %FPICA - Fixed point ICA. Main algorithm of FASTICA.
7
+ %
8
+ % [A, W] = fpica(whitesig, whiteningMatrix, dewhiteningMatrix, approach,
9
+ % numOfIC, g, finetune, a1, a2, mu, stabilization, epsilon,
10
+ % maxNumIterations, maxFinetune, initState, guess, sampleSize,
11
+ % displayMode, displayInterval, verbose);
12
+ %
13
+ % Perform independent component analysis using Hyvarinen's fixed point
14
+ % algorithm. Outputs an estimate of the mixing matrix A and its inverse W.
15
+ %
16
+ % whitesig :the whitened data as row vectors
17
+ % whiteningMatrix :can be obtained with function whitenv
18
+ % dewhiteningMatrix :can be obtained with function whitenv
19
+ % approach [ 'symm' | 'defl' ] :the approach used (deflation or symmetric)
20
+ % numOfIC [ 0 - Dim of whitesig ] :number of independent components estimated
21
+ % g [ 'pow3' | 'tanh' | :the nonlinearity used
22
+ % 'gaus' | 'skew' ]
23
+ % finetune [same as g + 'off'] :the nonlinearity used in finetuning.
24
+ % a1 :parameter for tuning 'tanh'
25
+ % a2 :parameter for tuning 'gaus'
26
+ % mu :step size in stabilized algorithm
27
+ % stabilization [ 'on' | 'off' ] :if mu < 1 then automatically on
28
+ % epsilon :stopping criterion
29
+ % maxNumIterations :maximum number of iterations
30
+ % maxFinetune :maximum number of iteretions for finetuning
31
+ % initState [ 'rand' | 'guess' ] :initial guess or random initial state. See below
32
+ % guess :initial guess for A. Ignored if initState = 'rand'
33
+ % sampleSize [ 0 - 1 ] :percentage of the samples used in one iteration
34
+ % displayMode [ 'signals' | 'basis' | :plot running estimate
35
+ % 'filters' | 'off' ]
36
+ % displayInterval :number of iterations we take between plots
37
+ % verbose [ 'on' | 'off' ] :report progress in text format
38
+ %
39
+ % EXAMPLE
40
+ % [E, D] = pcamat(vectors);
41
+ % [nv, wm, dwm] = whitenv(vectors, E, D);
42
+ % [A, W] = fpica(nv, wm, dwm);
43
+ %
44
+ %
45
+ % This function is needed by FASTICA and FASTICAG
46
+ %
47
+ % See also FASTICA, FASTICAG, WHITENV, PCAMAT
48
+
49
+ % @(#)$Id: fpica.m,v 1.7 2005/06/16 12:52:55 jarmo Exp $
50
+
51
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
52
+ % Global variable for stopping the ICA calculations from the GUI
53
+ global g_FastICA_interrupt;
54
+ if isempty(g_FastICA_interrupt)
55
+ clear global g_FastICA_interrupt;
56
+ interruptible = 0;
57
+ else
58
+ interruptible = 1;
59
+ end
60
+
61
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
62
+ % Default values
63
+
64
+ if nargin < 3, error('Not enough arguments!'); end
65
+ [vectorSize, numSamples] = size(X);
66
+ if nargin < 20, s_verbose = 'on'; end
67
+ if nargin < 19, displayInterval = 1; end
68
+ if nargin < 18, displayMode = 'on'; end
69
+ if nargin < 17, sampleSize = 1; end
70
+ if nargin < 16, guess = 1; end
71
+ if nargin < 15, initState = 'rand'; end
72
+ if nargin < 14, maxFinetune = 100; end
73
+ if nargin < 13, maxNumIterations = 1000; end
74
+ if nargin < 12, epsilon = 0.0001; end
75
+ if nargin < 11, stabilization = 'on'; end
76
+ if nargin < 10, myy = 1; end
77
+ if nargin < 9, a2 = 1; end
78
+ if nargin < 8, a1 = 1; end
79
+ if nargin < 7, finetune = 'off'; end
80
+ if nargin < 6, g = 'pow3'; end
81
+ if nargin < 5, numOfIC = vectorSize; end % vectorSize = Dim
82
+ if nargin < 4, approach = 'defl'; end
83
+
84
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
85
+ % Checking the data
86
+
87
+ if ~isreal(X)
88
+ error('Input has an imaginary part.');
89
+ end
90
+
91
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
+ % Checking the value for verbose
93
+
94
+ switch lower(s_verbose)
95
+ case 'on'
96
+ b_verbose = 1;
97
+ case 'off'
98
+ b_verbose = 0;
99
+ otherwise
100
+ error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose));
101
+ end
102
+
103
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104
+ % Checking the value for approach
105
+
106
+ switch lower(approach)
107
+ case 'symm'
108
+ approachMode = 1;
109
+ case 'defl'
110
+ approachMode = 2;
111
+ otherwise
112
+ error(sprintf('Illegal value [ %s ] for parameter: ''approach''\n', approach));
113
+ end
114
+ if b_verbose, fprintf('Used approach [ %s ].\n', approach); end
115
+
116
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
+ % Checking the value for numOfIC
118
+
119
+ if vectorSize < numOfIC
120
+ error('Must have numOfIC <= Dimension!');
121
+ end
122
+
123
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
124
+ % Checking the sampleSize
125
+ if sampleSize > 1
126
+ sampleSize = 1;
127
+ if b_verbose
128
+ fprintf('Warning: Setting ''sampleSize'' to 1.\n');
129
+ end
130
+ elseif sampleSize < 1
131
+ if (sampleSize * numSamples) < 1000
132
+ sampleSize = min(1000/numSamples, 1);
133
+ if b_verbose
134
+ fprintf('Warning: Setting ''sampleSize'' to %0.3f (%d samples).\n', ...
135
+ sampleSize, floor(sampleSize * numSamples));
136
+ end
137
+ end
138
+ end
139
+ if b_verbose
140
+ if b_verbose & (sampleSize < 1)
141
+ fprintf('Using about %0.0f%% of the samples in random order in every step.\n',sampleSize*100);
142
+ end
143
+ end
144
+
145
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
+ % Checking the value for nonlinearity.
147
+
148
+ switch lower(g)
149
+ case 'pow3'
150
+ gOrig = 10;
151
+ case 'tanh'
152
+ gOrig = 20;
153
+ case {'gaus', 'gauss'}
154
+ gOrig = 30;
155
+ case 'skew'
156
+ gOrig = 40;
157
+ otherwise
158
+ error(sprintf('Illegal value [ %s ] for parameter: ''g''\n', g));
159
+ end
160
+ if sampleSize ~= 1
161
+ gOrig = gOrig + 2;
162
+ end
163
+ if myy ~= 1
164
+ gOrig = gOrig + 1;
165
+ end
166
+
167
+ if b_verbose,
168
+ fprintf('Used nonlinearity [ %s ].\n', g);
169
+ end
170
+
171
+ finetuningEnabled = 1;
172
+ switch lower(finetune)
173
+ case 'pow3'
174
+ gFine = 10 + 1;
175
+ case 'tanh'
176
+ gFine = 20 + 1;
177
+ case {'gaus', 'gauss'}
178
+ gFine = 30 + 1;
179
+ case 'skew'
180
+ gFine = 40 + 1;
181
+ case 'off'
182
+ if myy ~= 1
183
+ gFine = gOrig;
184
+ else
185
+ gFine = gOrig + 1;
186
+ end
187
+ finetuningEnabled = 0;
188
+ otherwise
189
+ error(sprintf('Illegal value [ %s ] for parameter: ''finetune''\n', ...
190
+ finetune));
191
+ end
192
+
193
+ if b_verbose & finetuningEnabled
194
+ fprintf('Finetuning enabled (nonlinearity: [ %s ]).\n', finetune);
195
+ end
196
+
197
+ switch lower(stabilization)
198
+ case 'on'
199
+ stabilizationEnabled = 1;
200
+ case 'off'
201
+ if myy ~= 1
202
+ stabilizationEnabled = 1;
203
+ else
204
+ stabilizationEnabled = 0;
205
+ end
206
+ otherwise
207
+ error(sprintf('Illegal value [ %s ] for parameter: ''stabilization''\n', ...
208
+ stabilization));
209
+ end
210
+
211
+ if b_verbose & stabilizationEnabled
212
+ fprintf('Using stabilized algorithm.\n');
213
+ end
214
+
215
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
216
+ % Some other parameters
217
+ myyOrig = myy;
218
+ % When we start fine-tuning we'll set myy = myyK * myy
219
+ myyK = 0.01;
220
+ % How many times do we try for convergence until we give up.
221
+ failureLimit = 5;
222
+
223
+
224
+ usedNlinearity = gOrig;
225
+ stroke = 0;
226
+ notFine = 1;
227
+ long = 0;
228
+
229
+
230
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231
+ % Checking the value for initial state.
232
+
233
+ switch lower(initState)
234
+ case 'rand'
235
+ initialStateMode = 0;
236
+ case 'guess'
237
+ if size(guess,1) ~= size(whiteningMatrix,2)
238
+ initialStateMode = 0;
239
+ if b_verbose
240
+ fprintf('Warning: size of initial guess is incorrect. Using random initial guess.\n');
241
+ end
242
+ else
243
+ initialStateMode = 1;
244
+ if size(guess,2) < numOfIC
245
+ if b_verbose
246
+ fprintf('Warning: initial guess only for first %d components. Using random initial guess for others.\n', size(guess,2));
247
+ end
248
+ guess(:, size(guess, 2) + 1:numOfIC) = ...
249
+ rand(vectorSize,numOfIC-size(guess,2))-.5;
250
+ elseif size(guess,2)>numOfIC
251
+ guess=guess(:,1:numOfIC);
252
+ fprintf('Warning: Initial guess too large. The excess column are dropped.\n');
253
+ end
254
+ if b_verbose, fprintf('Using initial guess.\n'); end
255
+ end
256
+ otherwise
257
+ error(sprintf('Illegal value [ %s ] for parameter: ''initState''\n', initState));
258
+ end
259
+
260
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261
+ % Checking the value for display mode.
262
+
263
+ switch lower(displayMode)
264
+ case {'off', 'none'}
265
+ usedDisplay = 0;
266
+ case {'on', 'signals'}
267
+ usedDisplay = 1;
268
+ if (b_verbose & (numSamples > 10000))
269
+ fprintf('Warning: Data vectors are very long. Plotting may take long time.\n');
270
+ end
271
+ if (b_verbose & (numOfIC > 25))
272
+ fprintf('Warning: There are too many signals to plot. Plot may not look good.\n');
273
+ end
274
+ case 'basis'
275
+ usedDisplay = 2;
276
+ if (b_verbose & (numOfIC > 25))
277
+ fprintf('Warning: There are too many signals to plot. Plot may not look good.\n');
278
+ end
279
+ case 'filters'
280
+ usedDisplay = 3;
281
+ if (b_verbose & (vectorSize > 25))
282
+ fprintf('Warning: There are too many signals to plot. Plot may not look good.\n');
283
+ end
284
+ otherwise
285
+ error(sprintf('Illegal value [ %s ] for parameter: ''displayMode''\n', displayMode));
286
+ end
287
+
288
+ % The displayInterval can't be less than 1...
289
+ if displayInterval < 1
290
+ displayInterval = 1;
291
+ end
292
+
293
+
294
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
295
+ if b_verbose, fprintf('Starting ICA calculation...\n'); end
296
+
297
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
298
+ % SYMMETRIC APPROACH
299
+ if approachMode == 1,
300
+
301
+ % set some parameters more...
302
+ usedNlinearity = gOrig;
303
+ stroke = 0;
304
+ notFine = 1;
305
+ long = 0;
306
+
307
+ A = zeros(vectorSize, numOfIC); % Dewhitened basis vectors.
308
+ if initialStateMode == 0
309
+ % Take random orthonormal initial vectors.
310
+ B = orth (randn (vectorSize, numOfIC));
311
+ elseif initialStateMode == 1
312
+ % Use the given initial vector as the initial state
313
+ B = whiteningMatrix * guess;
314
+ end
315
+
316
+ BOld = zeros(size(B));
317
+ BOld2 = zeros(size(B));
318
+
319
+ % This is the actual fixed-point iteration loop.
320
+ for round = 1:maxNumIterations + 1,
321
+ if round == maxNumIterations + 1,
322
+ fprintf('No convergence after %d steps\n', maxNumIterations);
323
+ fprintf('Note that the plots are probably wrong.\n');
324
+ if ~isempty(B)
325
+ % Symmetric orthogonalization.
326
+ B = B * real(inv(B' * B)^(1/2));
327
+
328
+ W = B' * whiteningMatrix;
329
+ A = dewhiteningMatrix * B;
330
+ else
331
+ W = [];
332
+ A = [];
333
+ end
334
+ return;
335
+ end
336
+
337
+ if (interruptible & g_FastICA_interrupt)
338
+ if b_verbose
339
+ fprintf('\n\nCalculation interrupted by the user\n');
340
+ end
341
+ if ~isempty(B)
342
+ W = B' * whiteningMatrix;
343
+ A = dewhiteningMatrix * B;
344
+ else
345
+ W = [];
346
+ A = [];
347
+ end
348
+ return;
349
+ end
350
+
351
+
352
+ % Symmetric orthogonalization.
353
+ B = B * real(inv(B' * B)^(1/2));
354
+
355
+ % Test for termination condition. Note that we consider opposite
356
+ % directions here as well.
357
+ minAbsCos = min(abs(diag(B' * BOld)));
358
+ minAbsCos2 = min(abs(diag(B' * BOld2)));
359
+
360
+ if (1 - minAbsCos < epsilon)
361
+ if finetuningEnabled & notFine
362
+ if b_verbose, fprintf('Initial convergence, fine-tuning: \n'); end;
363
+ notFine = 0;
364
+ usedNlinearity = gFine;
365
+ myy = myyK * myyOrig;
366
+ BOld = zeros(size(B));
367
+ BOld2 = zeros(size(B));
368
+
369
+ else
370
+ if b_verbose, fprintf('Convergence after %d steps\n', round); end
371
+
372
+ % Calculate the de-whitened vectors.
373
+ A = dewhiteningMatrix * B;
374
+ break;
375
+ end
376
+ elseif stabilizationEnabled
377
+ if (~stroke) & (1 - minAbsCos2 < epsilon)
378
+ if b_verbose, fprintf('Stroke!\n'); end;
379
+ stroke = myy;
380
+ myy = .5*myy;
381
+ if mod(usedNlinearity,2) == 0
382
+ usedNlinearity = usedNlinearity + 1;
383
+ end
384
+ elseif stroke
385
+ myy = stroke;
386
+ stroke = 0;
387
+ if (myy == 1) & (mod(usedNlinearity,2) ~= 0)
388
+ usedNlinearity = usedNlinearity - 1;
389
+ end
390
+ elseif (~long) & (round>maxNumIterations/2)
391
+ if b_verbose, fprintf('Taking long (reducing step size)\n'); end;
392
+ long = 1;
393
+ myy = .5*myy;
394
+ if mod(usedNlinearity,2) == 0
395
+ usedNlinearity = usedNlinearity + 1;
396
+ end
397
+ end
398
+ end
399
+
400
+ BOld2 = BOld;
401
+ BOld = B;
402
+
403
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404
+ % Show the progress...
405
+ if b_verbose
406
+ if round == 1
407
+ fprintf('Step no. %d\n', round);
408
+ else
409
+ fprintf('Step no. %d, change in value of estimate: %.3g \n', round, 1 - minAbsCos);
410
+ end
411
+ end
412
+
413
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
414
+ % Also plot the current state...
415
+ switch usedDisplay
416
+ case 1
417
+ if rem(round, displayInterval) == 0,
418
+ % There was and may still be other displaymodes...
419
+ % 1D signals
420
+ icaplot('dispsig',(X'*B)');
421
+ drawnow;
422
+ end
423
+ case 2
424
+ if rem(round, displayInterval) == 0,
425
+ % ... and now there are :-)
426
+ % 1D basis
427
+ A = dewhiteningMatrix * B;
428
+ icaplot('dispsig',A');
429
+ drawnow;
430
+ end
431
+ case 3
432
+ if rem(round, displayInterval) == 0,
433
+ % ... and now there are :-)
434
+ % 1D filters
435
+ W = B' * whiteningMatrix;
436
+ icaplot('dispsig',W);
437
+ drawnow;
438
+ end
439
+ otherwise
440
+ end
441
+
442
+ switch usedNlinearity
443
+ % pow3
444
+ case 10
445
+ B = (X * (( X' * B) .^ 3)) / numSamples - 3 * B;
446
+ case 11
447
+ % optimoitu - epsilonin kokoisia eroja
448
+ % t�m� on optimoitu koodi, katso vanha koodi esim.
449
+ % aikaisemmista versioista kuten 2.0 beta3
450
+ Y = X' * B;
451
+ Gpow3 = Y .^ 3;
452
+ Beta = sum(Y .* Gpow3);
453
+ D = diag(1 ./ (Beta - 3 * numSamples));
454
+ B = B + myy * B * (Y' * Gpow3 - diag(Beta)) * D;
455
+ case 12
456
+ Xsub=X(:, getSamples(numSamples, sampleSize));
457
+ B = (Xsub * (( Xsub' * B) .^ 3)) / size(Xsub,2) - 3 * B;
458
+ case 13
459
+ % Optimoitu
460
+ Ysub=X(:, getSamples(numSamples, sampleSize))' * B;
461
+ Gpow3 = Ysub .^ 3;
462
+ Beta = sum(Ysub .* Gpow3);
463
+ D = diag(1 ./ (Beta - 3 * size(Ysub', 2)));
464
+ B = B + myy * B * (Ysub' * Gpow3 - diag(Beta)) * D;
465
+
466
+ % tanh
467
+ case 20
468
+ hypTan = tanh(a1 * X' * B);
469
+ B = X * hypTan / numSamples - ...
470
+ ones(size(B,1),1) * sum(1 - hypTan .^ 2) .* B / numSamples * ...
471
+ a1;
472
+ case 21
473
+ % optimoitu - epsilonin kokoisia
474
+ Y = X' * B;
475
+ hypTan = tanh(a1 * Y);
476
+ Beta = sum(Y .* hypTan);
477
+ D = diag(1 ./ (Beta - a1 * sum(1 - hypTan .^ 2)));
478
+ B = B + myy * B * (Y' * hypTan - diag(Beta)) * D;
479
+ case 22
480
+ Xsub=X(:, getSamples(numSamples, sampleSize));
481
+ hypTan = tanh(a1 * Xsub' * B);
482
+ B = Xsub * hypTan / size(Xsub, 2) - ...
483
+ ones(size(B,1),1) * sum(1 - hypTan .^ 2) .* B / size(Xsub, 2) * a1;
484
+ case 23
485
+ % Optimoitu
486
+ Y = X(:, getSamples(numSamples, sampleSize))' * B;
487
+ hypTan = tanh(a1 * Y);
488
+ Beta = sum(Y .* hypTan);
489
+ D = diag(1 ./ (Beta - a1 * sum(1 - hypTan .^ 2)));
490
+ B = B + myy * B * (Y' * hypTan - diag(Beta)) * D;
491
+
492
+ % gauss
493
+ case 30
494
+ U = X' * B;
495
+ Usquared=U .^ 2;
496
+ ex = exp(-a2 * Usquared / 2);
497
+ gauss = U .* ex;
498
+ dGauss = (1 - a2 * Usquared) .*ex;
499
+ B = X * gauss / numSamples - ...
500
+ ones(size(B,1),1) * sum(dGauss)...
501
+ .* B / numSamples ;
502
+ case 31
503
+ % optimoitu
504
+ Y = X' * B;
505
+ ex = exp(-a2 * (Y .^ 2) / 2);
506
+ gauss = Y .* ex;
507
+ Beta = sum(Y .* gauss);
508
+ D = diag(1 ./ (Beta - sum((1 - a2 * (Y .^ 2)) .* ex)));
509
+ B = B + myy * B * (Y' * gauss - diag(Beta)) * D;
510
+ case 32
511
+ Xsub=X(:, getSamples(numSamples, sampleSize));
512
+ U = Xsub' * B;
513
+ Usquared=U .^ 2;
514
+ ex = exp(-a2 * Usquared / 2);
515
+ gauss = U .* ex;
516
+ dGauss = (1 - a2 * Usquared) .*ex;
517
+ B = Xsub * gauss / size(Xsub,2) - ...
518
+ ones(size(B,1),1) * sum(dGauss)...
519
+ .* B / size(Xsub,2) ;
520
+ case 33
521
+ % Optimoitu
522
+ Y = X(:, getSamples(numSamples, sampleSize))' * B;
523
+ ex = exp(-a2 * (Y .^ 2) / 2);
524
+ gauss = Y .* ex;
525
+ Beta = sum(Y .* gauss);
526
+ D = diag(1 ./ (Beta - sum((1 - a2 * (Y .^ 2)) .* ex)));
527
+ B = B + myy * B * (Y' * gauss - diag(Beta)) * D;
528
+
529
+ % skew
530
+ case 40
531
+ B = (X * ((X' * B) .^ 2)) / numSamples;
532
+ case 41
533
+ % Optimoitu
534
+ Y = X' * B;
535
+ Gskew = Y .^ 2;
536
+ Beta = sum(Y .* Gskew);
537
+ D = diag(1 ./ (Beta));
538
+ B = B + myy * B * (Y' * Gskew - diag(Beta)) * D;
539
+ case 42
540
+ Xsub=X(:, getSamples(numSamples, sampleSize));
541
+ B = (Xsub * ((Xsub' * B) .^ 2)) / size(Xsub,2);
542
+ case 43
543
+ % Uusi optimoitu
544
+ Y = X(:, getSamples(numSamples, sampleSize))' * B;
545
+ Gskew = Y .^ 2;
546
+ Beta = sum(Y .* Gskew);
547
+ D = diag(1 ./ (Beta));
548
+ B = B + myy * B * (Y' * Gskew - diag(Beta)) * D;
549
+
550
+ otherwise
551
+ error('Code for desired nonlinearity not found!');
552
+ end
553
+ end
554
+
555
+
556
+ % Calculate ICA filters.
557
+ W = B' * whiteningMatrix;
558
+
559
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
560
+ % Also plot the last one...
561
+ switch usedDisplay
562
+ case 1
563
+ % There was and may still be other displaymodes...
564
+ % 1D signals
565
+ icaplot('dispsig',(X'*B)');
566
+ drawnow;
567
+ case 2
568
+ % ... and now there are :-)
569
+ % 1D basis
570
+ icaplot('dispsig',A');
571
+ drawnow;
572
+ case 3
573
+ % ... and now there are :-)
574
+ % 1D filters
575
+ icaplot('dispsig',W);
576
+ drawnow;
577
+ otherwise
578
+ end
579
+ end
580
+
581
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
582
+ % DEFLATION APPROACH
583
+ if approachMode == 2
584
+
585
+ B = zeros(vectorSize);
586
+
587
+ % The search for a basis vector is repeated numOfIC times.
588
+ round = 1;
589
+
590
+ numFailures = 0;
591
+
592
+ while round <= numOfIC,
593
+ myy = myyOrig;
594
+ usedNlinearity = gOrig;
595
+ stroke = 0;
596
+ notFine = 1;
597
+ long = 0;
598
+ endFinetuning = 0;
599
+
600
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
601
+ % Show the progress...
602
+ if b_verbose, fprintf('IC %d ', round); end
603
+
604
+ % Take a random initial vector of lenght 1 and orthogonalize it
605
+ % with respect to the other vectors.
606
+ if initialStateMode == 0
607
+ w = randn (vectorSize, 1);
608
+ elseif initialStateMode == 1
609
+ w=whiteningMatrix*guess(:,round);
610
+ end
611
+ w = w - B * B' * w;
612
+ w = w / norm(w);
613
+
614
+ wOld = zeros(size(w));
615
+ wOld2 = zeros(size(w));
616
+
617
+ % This is the actual fixed-point iteration loop.
618
+ % for i = 1 : maxNumIterations + 1
619
+ i = 1;
620
+ gabba = 1;
621
+ while i <= maxNumIterations + gabba
622
+ if (usedDisplay > 0)
623
+ drawnow;
624
+ end
625
+ if (interruptible & g_FastICA_interrupt)
626
+ if b_verbose
627
+ fprintf('\n\nCalculation interrupted by the user\n');
628
+ end
629
+ return;
630
+ end
631
+
632
+ % Project the vector into the space orthogonal to the space
633
+ % spanned by the earlier found basis vectors. Note that we can do
634
+ % the projection with matrix B, since the zero entries do not
635
+ % contribute to the projection.
636
+ w = w - B * B' * w;
637
+ w = w / norm(w);
638
+
639
+ if notFine
640
+ if i == maxNumIterations + 1
641
+ if b_verbose
642
+ fprintf('\nComponent number %d did not converge in %d iterations.\n', round, maxNumIterations);
643
+ end
644
+ round = round - 1;
645
+ numFailures = numFailures + 1;
646
+ if numFailures > failureLimit
647
+ if b_verbose
648
+ fprintf('Too many failures to converge (%d). Giving up.\n', numFailures);
649
+ end
650
+ if round == 0
651
+ A=[];
652
+ W=[];
653
+ end
654
+ return;
655
+ end
656
+ % numFailures > failurelimit
657
+ break;
658
+ end
659
+ % i == maxNumIterations + 1
660
+ else
661
+ % if notFine
662
+ if i >= endFinetuning
663
+ wOld = w; % So the algorithm will stop on the next test...
664
+ end
665
+ end
666
+ % if notFine
667
+
668
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
669
+ % Show the progress...
670
+ if b_verbose, fprintf('.'); end;
671
+
672
+
673
+ % Test for termination condition. Note that the algorithm has
674
+ % converged if the direction of w and wOld is the same, this
675
+ % is why we test the two cases.
676
+ if norm(w - wOld) < epsilon | norm(w + wOld) < epsilon
677
+ if finetuningEnabled & notFine
678
+ if b_verbose, fprintf('Initial convergence, fine-tuning: '); end;
679
+ notFine = 0;
680
+ gabba = maxFinetune;
681
+ wOld = zeros(size(w));
682
+ wOld2 = zeros(size(w));
683
+ usedNlinearity = gFine;
684
+ myy = myyK * myyOrig;
685
+
686
+ endFinetuning = maxFinetune + i;
687
+
688
+ else
689
+ numFailures = 0;
690
+ % Save the vector
691
+ B(:, round) = w;
692
+
693
+ % Calculate the de-whitened vector.
694
+ A(:,round) = dewhiteningMatrix * w;
695
+ % Calculate ICA filter.
696
+ W(round,:) = w' * whiteningMatrix;
697
+
698
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
699
+ % Show the progress...
700
+ if b_verbose, fprintf('computed ( %d steps ) \n', i); end
701
+
702
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
703
+ % Also plot the current state...
704
+ switch usedDisplay
705
+ case 1
706
+ if rem(round, displayInterval) == 0,
707
+ % There was and may still be other displaymodes...
708
+ % 1D signals
709
+ temp = X'*B;
710
+ icaplot('dispsig',temp(:,1:numOfIC)');
711
+ drawnow;
712
+ end
713
+ case 2
714
+ if rem(round, displayInterval) == 0,
715
+ % ... and now there are :-)
716
+ % 1D basis
717
+ icaplot('dispsig',A');
718
+ drawnow;
719
+ end
720
+ case 3
721
+ if rem(round, displayInterval) == 0,
722
+ % ... and now there are :-)
723
+ % 1D filters
724
+ icaplot('dispsig',W);
725
+ drawnow;
726
+ end
727
+ end
728
+ % switch usedDisplay
729
+ break; % IC ready - next...
730
+ end
731
+ %if finetuningEnabled & notFine
732
+ elseif stabilizationEnabled
733
+ if (~stroke) & (norm(w - wOld2) < epsilon | norm(w + wOld2) < ...
734
+ epsilon)
735
+ stroke = myy;
736
+ if b_verbose, fprintf('Stroke!'); end;
737
+ myy = .5*myy;
738
+ if mod(usedNlinearity,2) == 0
739
+ usedNlinearity = usedNlinearity + 1;
740
+ end
741
+ elseif stroke
742
+ myy = stroke;
743
+ stroke = 0;
744
+ if (myy == 1) & (mod(usedNlinearity,2) ~= 0)
745
+ usedNlinearity = usedNlinearity - 1;
746
+ end
747
+ elseif (notFine) & (~long) & (i > maxNumIterations / 2)
748
+ if b_verbose, fprintf('Taking long (reducing step size) '); end;
749
+ long = 1;
750
+ myy = .5*myy;
751
+ if mod(usedNlinearity,2) == 0
752
+ usedNlinearity = usedNlinearity + 1;
753
+ end
754
+ end
755
+ end
756
+
757
+ wOld2 = wOld;
758
+ wOld = w;
759
+
760
+ switch usedNlinearity
761
+ % pow3
762
+ case 10
763
+ w = (X * ((X' * w) .^ 3)) / numSamples - 3 * w;
764
+ case 11
765
+ EXGpow3 = (X * ((X' * w) .^ 3)) / numSamples;
766
+ Beta = w' * EXGpow3;
767
+ w = w - myy * (EXGpow3 - Beta * w) / (3 - Beta);
768
+ case 12
769
+ Xsub=X(:,getSamples(numSamples, sampleSize));
770
+ w = (Xsub * ((Xsub' * w) .^ 3)) / size(Xsub, 2) - 3 * w;
771
+ case 13
772
+ Xsub=X(:,getSamples(numSamples, sampleSize));
773
+ EXGpow3 = (Xsub * ((Xsub' * w) .^ 3)) / size(Xsub, 2);
774
+ Beta = w' * EXGpow3;
775
+ w = w - myy * (EXGpow3 - Beta * w) / (3 - Beta);
776
+ % tanh
777
+ case 20
778
+ hypTan = tanh(a1 * X' * w);
779
+ w = (X * hypTan - a1 * sum(1 - hypTan .^ 2)' * w) / numSamples;
780
+ case 21
781
+ hypTan = tanh(a1 * X' * w);
782
+ Beta = w' * X * hypTan;
783
+ w = w - myy * ((X * hypTan - Beta * w) / ...
784
+ (a1 * sum((1-hypTan .^2)') - Beta));
785
+ case 22
786
+ Xsub=X(:,getSamples(numSamples, sampleSize));
787
+ hypTan = tanh(a1 * Xsub' * w);
788
+ w = (Xsub * hypTan - a1 * sum(1 - hypTan .^ 2)' * w) / size(Xsub, 2);
789
+ case 23
790
+ Xsub=X(:,getSamples(numSamples, sampleSize));
791
+ hypTan = tanh(a1 * Xsub' * w);
792
+ Beta = w' * Xsub * hypTan;
793
+ w = w - myy * ((Xsub * hypTan - Beta * w) / ...
794
+ (a1 * sum((1-hypTan .^2)') - Beta));
795
+ % gauss
796
+ case 30
797
+ % This has been split for performance reasons.
798
+ u = X' * w;
799
+ u2=u.^2;
800
+ ex=exp(-a2 * u2/2);
801
+ gauss = u.*ex;
802
+ dGauss = (1 - a2 * u2) .*ex;
803
+ w = (X * gauss - sum(dGauss)' * w) / numSamples;
804
+ case 31
805
+ u = X' * w;
806
+ u2=u.^2;
807
+ ex=exp(-a2 * u2/2);
808
+ gauss = u.*ex;
809
+ dGauss = (1 - a2 * u2) .*ex;
810
+ Beta = w' * X * gauss;
811
+ w = w - myy * ((X * gauss - Beta * w) / ...
812
+ (sum(dGauss)' - Beta));
813
+ case 32
814
+ Xsub=X(:,getSamples(numSamples, sampleSize));
815
+ u = Xsub' * w;
816
+ u2=u.^2;
817
+ ex=exp(-a2 * u2/2);
818
+ gauss = u.*ex;
819
+ dGauss = (1 - a2 * u2) .*ex;
820
+ w = (Xsub * gauss - sum(dGauss)' * w) / size(Xsub, 2);
821
+ case 33
822
+ Xsub=X(:,getSamples(numSamples, sampleSize));
823
+ u = Xsub' * w;
824
+ u2=u.^2;
825
+ ex=exp(-a2 * u2/2);
826
+ gauss = u.*ex;
827
+ dGauss = (1 - a2 * u2) .*ex;
828
+ Beta = w' * Xsub * gauss;
829
+ w = w - myy * ((Xsub * gauss - Beta * w) / ...
830
+ (sum(dGauss)' - Beta));
831
+ % skew
832
+ case 40
833
+ w = (X * ((X' * w) .^ 2)) / numSamples;
834
+ case 41
835
+ EXGskew = (X * ((X' * w) .^ 2)) / numSamples;
836
+ Beta = w' * EXGskew;
837
+ w = w - myy * (EXGskew - Beta*w)/(-Beta);
838
+ case 42
839
+ Xsub=X(:,getSamples(numSamples, sampleSize));
840
+ w = (Xsub * ((Xsub' * w) .^ 2)) / size(Xsub, 2);
841
+ case 43
842
+ Xsub=X(:,getSamples(numSamples, sampleSize));
843
+ EXGskew = (Xsub * ((Xsub' * w) .^ 2)) / size(Xsub, 2);
844
+ Beta = w' * EXGskew;
845
+ w = w - myy * (EXGskew - Beta*w)/(-Beta);
846
+
847
+ otherwise
848
+ error('Code for desired nonlinearity not found!');
849
+ end
850
+
851
+ % Normalize the new w.
852
+ w = w / norm(w);
853
+ i = i + 1;
854
+ end
855
+ round = round + 1;
856
+ end
857
+ if b_verbose, fprintf('Done.\n'); end
858
+
859
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
860
+ % Also plot the ones that may not have been plotted.
861
+ if (usedDisplay > 0) & (rem(round-1, displayInterval) ~= 0)
862
+ switch usedDisplay
863
+ case 1
864
+ % There was and may still be other displaymodes...
865
+ % 1D signals
866
+ temp = X'*B;
867
+ icaplot('dispsig',temp(:,1:numOfIC)');
868
+ drawnow;
869
+ case 2
870
+ % ... and now there are :-)
871
+ % 1D basis
872
+ icaplot('dispsig',A');
873
+ drawnow;
874
+ case 3
875
+ % ... and now there are :-)
876
+ % 1D filters
877
+ icaplot('dispsig',W);
878
+ drawnow;
879
+ otherwise
880
+ end
881
+ end
882
+ end
883
+
884
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
885
+ % In the end let's check the data for some security
886
+ if ~isreal(A)
887
+ if b_verbose, fprintf('Warning: removing the imaginary part from the result.\n'); end
888
+ A = real(A);
889
+ W = real(W);
890
+ end
891
+
892
+
893
+
894
+
895
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
896
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
897
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
898
+ % Subfunction
899
+ % Calculates tanh simplier and faster than Matlab tanh.
900
+ function y=tanh(x)
901
+ y = 1 - 2 ./ (exp(2 * x) + 1);
902
+
903
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
904
+ function Samples = getSamples(max, percentage)
905
+ Samples = find(rand(1, max) < percentage);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_adv.m ADDED
@@ -0,0 +1,441 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_adv(x, y)
2
+ %
3
+ % This file is needed by FASTICAG
4
+
5
+ % This is the advanced options -dialog
6
+
7
+ % @(#)$Id: gui_adv.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the window
13
+ global hf_FastICA_AdvOpt;
14
+
15
+ % Handles to some of the controls in window
16
+ global hpm_FastICA_finetune;
17
+ global he_FastICA_a1;
18
+ global he_FastICA_a2;
19
+ global he_FastICA_myy;
20
+ global he_FastICA_epsilon;
21
+ global he_FastICA_maxIterations;
22
+ global he_FastICA_maxFinetune;
23
+ global he_FastICA_sampleSize
24
+ global hpm_FastICA_initState;
25
+ global hb_FastICA_initGuess;
26
+ global ht_FastICA_initGuess;
27
+ global hpm_FastICA_displayMode;
28
+ global he_FastICA_displayInterval;
29
+ global hpm_FastICA_verbose;
30
+
31
+ % Some of the main variables needed
32
+ global g_FastICA_initGuess;
33
+ global g_FastICA_finetune;
34
+ global g_FastICA_a1;
35
+ global g_FastICA_a2;
36
+ global g_FastICA_myy;
37
+ global g_FastICA_epsilon;
38
+ global g_FastICA_maxNumIte;
39
+ global g_FastICA_maxFinetune;
40
+ global g_FastICA_initState;
41
+ global g_FastICA_sampleSize;
42
+ global g_FastICA_displayMo;
43
+ global g_FastICA_displayIn;
44
+ global g_FastICA_verbose;
45
+
46
+ global c_FastICA_appr_strD;
47
+ global c_FastICA_appr_strV;
48
+ global c_FastICA_finetune_strD;
49
+ global c_FastICA_finetune_strV;
50
+ global c_FastICA_iSta_strD;
51
+ global c_FastICA_iSta_strV;
52
+ global c_FastICA_dMod_strD;
53
+ global c_FastICA_dMod_strV;
54
+ global c_FastICA_verb_strD;
55
+ global c_FastICA_verb_strV;
56
+
57
+
58
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
+ % Configuration options
60
+ FIGURENAME = 'FastICA: advanced options';
61
+ FIGURETAG = 'f_FastICAAdvOpt';
62
+ FIGURESIZE = [x y 450 280];
63
+
64
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
+ % Check to see if this figure is already open - it should not!
66
+ % Can't have more than one copy - otherwise the global
67
+ % variables and handles can get mixed up.
68
+ if ~isempty(findobj('Tag',FIGURETAG))
69
+ error('Error: advanced options dialog already open!');
70
+ end
71
+
72
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
+ % Initialize some of the controls' values
74
+
75
+ % Did we already load some initial guess
76
+ pm_initState_Value = g_FastICA_initState;
77
+ if isempty(g_FastICA_initGuess) | (g_FastICA_initGuess == 1)
78
+ t_initGuess_String = 'Not loaded';
79
+ else
80
+ t_initGuess_String = 'Loaded';
81
+ end
82
+
83
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
84
+ % Create the figure
85
+ a = figure('Color',[0.8 0.8 0.8], ...
86
+ 'PaperType','a4letter', ...
87
+ 'Name', FIGURENAME, ...
88
+ 'NumberTitle', 'off', ...
89
+ 'Tag', FIGURETAG, ...
90
+ 'Position', FIGURESIZE, ...
91
+ 'MenuBar', 'none');
92
+ set (a, 'Resize', 'off');
93
+
94
+ hf_FastICA_AdvOpt = a;
95
+
96
+ set(hf_FastICA_AdvOpt, 'HandleVisibility', 'callback');
97
+
98
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
+ % From here on it get's ugly as I have not had time to clean it up
100
+
101
+
102
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
103
+ % Create the frames
104
+ pos_l=2;
105
+ pos_w=FIGURESIZE(3)-4;
106
+ pos_h=FIGURESIZE(4)-4;
107
+ pos_t=2;
108
+ h_f_adv_background = uicontrol('Parent',a, ...
109
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
110
+ 'Position',[pos_l pos_t pos_w pos_h], ...
111
+ 'Style','frame', ...
112
+ 'Tag','f_adv_background');
113
+
114
+ pos_w=120;
115
+ pos_l=FIGURESIZE(3)-(pos_w+2+2);
116
+ pos_h=FIGURESIZE(4)-2*4;
117
+ pos_t=4;
118
+ h_f_adv_side = uicontrol('Parent',a, ...
119
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
120
+ 'Position',[pos_l pos_t pos_w pos_h], ...
121
+ 'Style','frame', ...
122
+ 'Tag','f_adv_side');
123
+
124
+ pos_l=4;
125
+ pos_w=FIGURESIZE(3)-8-pos_w-2;
126
+ pos_h=FIGURESIZE(4)-8;
127
+ pos_t=4;
128
+ h_f_advopt = uicontrol('Parent',a, ...
129
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
130
+ 'Position',[pos_l pos_t pos_w pos_h], ...
131
+ 'Style','frame', ...
132
+ 'Tag','f_advopt');
133
+
134
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
135
+ % Controls in f_advopt
136
+ bgc = get(h_f_advopt, 'BackgroundColor');
137
+
138
+ pos_w1=230;
139
+ pos_w2=70;
140
+
141
+ pos_frame=get(h_f_advopt, 'Position');
142
+ pos_h = 20;
143
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
144
+ pos_l = pos_frame(1) + 6;
145
+ b = uicontrol('Parent',a, ...
146
+ 'BackgroundColor',bgc, ...
147
+ 'HorizontalAlignment','left', ...
148
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
149
+ 'String','Fine-tune (g)', ...
150
+ 'Style','text', ...
151
+ 'Tag','t_727');
152
+
153
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
154
+ hpm_FastICA_finetune = uicontrol('Parent',a, ...
155
+ 'BackgroundColor',bgc, ...
156
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
157
+ 'String',c_FastICA_finetune_strD, ...
158
+ 'Style','popupmenu', ...
159
+ 'Tag','pm_finetune', ...
160
+ 'Value',g_FastICA_finetune);
161
+
162
+ pos_t = pos_t - pos_h;
163
+ pos_l = pos_frame(1) + 6;
164
+ b = uicontrol('Parent',a, ...
165
+ 'BackgroundColor',bgc, ...
166
+ 'HorizontalAlignment','left', ...
167
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
168
+ 'String','Parameter a1 (g = ''tanh'')', ...
169
+ 'Style','text', ...
170
+ 'Tag','t_22');
171
+
172
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
173
+ he_FastICA_a1 = uicontrol('Parent',a, ...
174
+ 'BackgroundColor',[1 1 1], ...
175
+ 'HorizontalAlignment','right', ...
176
+ 'Callback','gui_advc Checka1', ...
177
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
178
+ 'String',num2str(g_FastICA_a1), ...
179
+ 'Style','edit', ...
180
+ 'Tag','e_a1');
181
+
182
+ pos_t = pos_t - pos_h;
183
+ pos_l = pos_frame(1) + 6;
184
+ b = uicontrol('Parent',a, ...
185
+ 'BackgroundColor',bgc, ...
186
+ 'HorizontalAlignment','left', ...
187
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
188
+ 'String','Parameter a2 (g = ''gauss'')', ...
189
+ 'Style','text', ...
190
+ 'Tag','t_222');
191
+
192
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
193
+ he_FastICA_a2 = uicontrol('Parent',a, ...
194
+ 'BackgroundColor',[1 1 1], ...
195
+ 'HorizontalAlignment','right', ...
196
+ 'Callback','gui_advc Checka2', ...
197
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
198
+ 'String',num2str(g_FastICA_a2), ...
199
+ 'Style','edit', ...
200
+ 'Tag','e_a2');
201
+
202
+ pos_t = pos_t - pos_h;
203
+ pos_l = pos_frame(1) + 6;
204
+ b = uicontrol('Parent',a, ...
205
+ 'BackgroundColor',bgc, ...
206
+ 'HorizontalAlignment','left', ...
207
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
208
+ 'String','mu (step size)', ...
209
+ 'Style','text', ...
210
+ 'Tag','t_223');
211
+
212
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
213
+ he_FastICA_myy = uicontrol('Parent',a, ...
214
+ 'BackgroundColor',[1 1 1], ...
215
+ 'HorizontalAlignment','right', ...
216
+ 'Callback','gui_advc CheckMyy', ...
217
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
218
+ 'String',num2str(g_FastICA_myy), ...
219
+ 'Style','edit', ...
220
+ 'Tag','e_myy');
221
+
222
+ pos_t = pos_t - pos_h;
223
+ pos_l = pos_frame(1) + 6;
224
+ b = uicontrol('Parent',a, ...
225
+ 'BackgroundColor',bgc, ...
226
+ 'HorizontalAlignment','left', ...
227
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
228
+ 'String','epsilon (stopping criterion)', ...
229
+ 'Style','text', ...
230
+ 'Tag','t_23');
231
+
232
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
233
+ he_FastICA_epsilon = uicontrol('Parent',a, ...
234
+ 'BackgroundColor',[1 1 1], ...
235
+ 'HorizontalAlignment','right', ...
236
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
237
+ 'String',num2str(g_FastICA_epsilon), ...
238
+ 'Style','edit', ...
239
+ 'Tag','e_epsilon');
240
+
241
+ pos_t = pos_t - pos_h;
242
+ pos_l = pos_frame(1) + 6;
243
+ b = uicontrol('Parent',a, ...
244
+ 'BackgroundColor',bgc, ...
245
+ 'HorizontalAlignment','left', ...
246
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
247
+ 'String','Maximum number of iterations', ...
248
+ 'Style','text', ...
249
+ 'Tag','t_24');
250
+
251
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
252
+ he_FastICA_maxIterations = uicontrol('Parent',a, ...
253
+ 'BackgroundColor',[1 1 1], ...
254
+ 'HorizontalAlignment','right', ...
255
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
256
+ 'String',num2str(g_FastICA_maxNumIte), ...
257
+ 'Style','edit', ...
258
+ 'Tag','e_maxIterations');
259
+
260
+ pos_t = pos_t - pos_h;
261
+ pos_l = pos_frame(1) + 6;
262
+ b = uicontrol('Parent',a, ...
263
+ 'BackgroundColor',bgc, ...
264
+ 'HorizontalAlignment','left', ...
265
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
266
+ 'String','Maximum iterations in fine-tuning', ...
267
+ 'Style','text', ...
268
+ 'Tag','t_2412');
269
+
270
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
271
+ he_FastICA_maxFinetune = uicontrol('Parent',a, ...
272
+ 'BackgroundColor',[1 1 1], ...
273
+ 'HorizontalAlignment','right', ...
274
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
275
+ 'String',num2str(g_FastICA_maxFinetune), ...
276
+ 'Style','edit', ...
277
+ 'Tag','e_maxFinetune');
278
+
279
+ pos_t = pos_t - pos_h;
280
+ pos_l = pos_frame(1) + 6;
281
+ b = uicontrol('Parent',a, ...
282
+ 'BackgroundColor',bgc, ...
283
+ 'HorizontalAlignment','left', ...
284
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
285
+ 'String','Sample size (proportion)', ...
286
+ 'Style','text', ...
287
+ 'Tag','t_224');
288
+
289
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
290
+ he_FastICA_sampleSize = uicontrol('Parent',a, ...
291
+ 'BackgroundColor',[1 1 1], ...
292
+ 'HorizontalAlignment','right', ...
293
+ 'Callback','gui_advc CheckSampleSize', ...
294
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
295
+ 'String',num2str(g_FastICA_sampleSize), ...
296
+ 'Style','edit', ...
297
+ 'Tag','e_sampleSize');
298
+
299
+ pos_t = pos_t - pos_h;
300
+ pos_l = pos_frame(1) + 6;
301
+ b = uicontrol('Parent',a, ...
302
+ 'BackgroundColor',bgc, ...
303
+ 'HorizontalAlignment','left', ...
304
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
305
+ 'String','Initial state', ...
306
+ 'Style','text', ...
307
+ 'Tag','t_25');
308
+
309
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
310
+ hpm_FastICA_initState = uicontrol('Parent',a, ...
311
+ 'BackgroundColor',bgc, ...
312
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
313
+ 'String',c_FastICA_iSta_strD, ...
314
+ 'Style','popupmenu', ...
315
+ 'Tag','pm_initState', ...
316
+ 'Value',pm_initState_Value);
317
+
318
+ pos_t = pos_t - pos_h;
319
+ pos_l = pos_frame(1) + 6;
320
+ hb_FastICA_initGuess = uicontrol('Parent',a, ...
321
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
322
+ 'Callback','gui_advc loadGuess', ...
323
+ 'Position',[pos_l pos_t (pos_w1-60) pos_h], ...
324
+ 'String','Load initial guess', ...
325
+ 'UserData', g_FastICA_initGuess, ...
326
+ 'Tag','b_LoadGuess');
327
+
328
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
329
+ ht_FastICA_initGuess = uicontrol('Parent',a, ...
330
+ 'BackgroundColor',bgc, ...
331
+ 'HorizontalAlignment','left', ...
332
+ 'Position',[(pos_l) pos_t (pos_w2) pos_h], ...
333
+ 'String',t_initGuess_String, ...
334
+ 'Style','text', ...
335
+ 'Tag','t_initGuess');
336
+
337
+ pos_t = pos_t - pos_h;
338
+ pos_l = pos_frame(1) + 6;
339
+ b = uicontrol('Parent',a, ...
340
+ 'BackgroundColor',bgc, ...
341
+ 'HorizontalAlignment','left', ...
342
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
343
+ 'String','Display mode', ...
344
+ 'Style','text', ...
345
+ 'Tag','t_27');
346
+
347
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
348
+ hpm_FastICA_displayMode = uicontrol('Parent',a, ...
349
+ 'BackgroundColor',bgc, ...
350
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
351
+ 'String',c_FastICA_dMod_strD, ...
352
+ 'Style','popupmenu', ...
353
+ 'Tag','pm_displayMode', ...
354
+ 'Value',g_FastICA_displayMo);
355
+
356
+ pos_t = pos_t - pos_h;
357
+ pos_l = pos_frame(1) + 6;
358
+ b = uicontrol('Parent',a, ...
359
+ 'BackgroundColor',bgc, ...
360
+ 'HorizontalAlignment','left', ...
361
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
362
+ 'String','Iterations between displays', ...
363
+ 'Style','text', ...
364
+ 'Tag','t_28');
365
+
366
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
367
+ he_FastICA_displayInterval = uicontrol('Parent',a, ...
368
+ 'BackgroundColor',[1 1 1], ...
369
+ 'HorizontalAlignment','right', ...
370
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
371
+ 'String',num2str(g_FastICA_displayIn), ...
372
+ 'Style','edit', ...
373
+ 'Tag','e_displayInterval');
374
+
375
+ pos_t = pos_t - pos_h;
376
+ pos_l = pos_frame(1) + 6;
377
+ b = uicontrol('Parent',a, ...
378
+ 'BackgroundColor',bgc, ...
379
+ 'HorizontalAlignment','left', ...
380
+ 'Position',[pos_l pos_t pos_w1 pos_h], ...
381
+ 'String','Verbose', ...
382
+ 'Style','text', ...
383
+ 'Tag','t_29');
384
+
385
+ pos_l = pos_frame(1) + pos_frame(3) - 6 - pos_w2;
386
+ hpm_FastICA_verbose = uicontrol('Parent',a, ...
387
+ 'BackgroundColor',bgc, ...
388
+ 'Position',[pos_l pos_t pos_w2 pos_h], ...
389
+ 'String',c_FastICA_verb_strD, ...
390
+ 'Style','popupmenu', ...
391
+ 'Tag','pm_verbose', ...
392
+ 'Value',g_FastICA_verbose);
393
+
394
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
395
+ % Controls in f_adv_side
396
+ pos_vspace = 6;
397
+ pos_hspace = 10;
398
+ pos_frame = get(h_f_adv_side, 'Position');
399
+ pos_w = 100;
400
+ pos_h = 30;
401
+ pos_l = pos_frame(1) + pos_hspace;
402
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace;
403
+ b = uicontrol('Parent',a, ...
404
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
405
+ 'Callback','gui_advc OK', ...
406
+ 'Position',[pos_l pos_t pos_w pos_h], ...
407
+ 'String','OK', ...
408
+ 'Tag','b_advOK');
409
+
410
+ pos_t=pos_t-pos_h-pos_vspace;
411
+ b = uicontrol('Parent',a, ...
412
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
413
+ 'Callback','gui_advc Cancel', ...
414
+ 'Position',[pos_l pos_t pos_w pos_h], ...
415
+ 'String','Cancel', ...
416
+ 'Tag','b_advCancel');
417
+
418
+ pos_t=pos_t-pos_h-pos_vspace;
419
+ b = uicontrol('Parent',a, ...
420
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
421
+ 'Callback','gui_advc Default', ...
422
+ 'Position',[pos_l pos_t pos_w pos_h], ...
423
+ 'String','Default', ...
424
+ 'Tag','b_advDefault');
425
+
426
+ pos_t=pos_t-pos_h-pos_vspace;
427
+ b = uicontrol('Parent',a, ...
428
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
429
+ 'Callback','gui_advc Apply', ...
430
+ 'Position',[pos_l pos_t pos_w pos_h], ...
431
+ 'String','Apply', ...
432
+ 'Tag','b_advApply');
433
+
434
+ pos_t = pos_frame(2) + pos_vspace;
435
+ b = uicontrol('Parent',a, ...
436
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
437
+ 'Callback','gui_advc Help', ...
438
+ 'Position',[pos_l pos_t pos_w pos_h], ...
439
+ 'String','Help', ...
440
+ 'Tag','b_advHelp');
441
+
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_advc.m ADDED
@@ -0,0 +1,256 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_advc (action)
2
+ %
3
+ % This file is needed by FASTICAG
4
+
5
+ % This file holds the callbacks for advanced options -dialog
6
+
7
+ % @(#)$Id: gui_advc.m,v 1.3 2003/09/08 11:28:58 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the window
13
+ global hf_FastICA_AdvOpt;
14
+
15
+ % Handles to some of the controls in window
16
+ global hpm_FastICA_finetune;
17
+ global he_FastICA_a1;
18
+ global he_FastICA_a2;
19
+ global he_FastICA_myy;
20
+ global he_FastICA_epsilon;
21
+ global he_FastICA_maxIterations;
22
+ global he_FastICA_maxFinetune;
23
+ global he_FastICA_sampleSize;
24
+ global hpm_FastICA_initState;
25
+ global hb_FastICA_initGuess;
26
+ global ht_FastICA_initGuess;
27
+ global hpm_FastICA_displayMode;
28
+ global he_FastICA_displayInterval;
29
+ global hpm_FastICA_verbose;
30
+
31
+ % Needed handles to the main window
32
+ global hf_FastICA_MAIN;
33
+ global ht_FastICA_icaStatus;
34
+ global ht_FastICA_numOfSamp;
35
+ global hpm_FastICA_stabilization;
36
+
37
+ % Some of the main variables needed
38
+ global g_FastICA_initGuess;
39
+ global g_FastICA_numOfIC;
40
+ global g_FastICA_finetune;
41
+ global g_FastICA_a1;
42
+ global g_FastICA_a2;
43
+ global g_FastICA_myy;
44
+ global g_FastICA_epsilon;
45
+ global g_FastICA_maxNumIte;
46
+ global g_FastICA_maxFinetune;
47
+ global g_FastICA_initState;
48
+ global g_FastICA_sampleSize;
49
+ global g_FastICA_displayMo;
50
+ global g_FastICA_displayIn;
51
+ global g_FastICA_verbose;
52
+
53
+ global c_FastICA_iSta_strV;
54
+
55
+ % What is the load type of load dialog
56
+ global g_FastICA_loadType;
57
+
58
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
+ % This should not take long...
60
+ watchonInFigure = watchon;
61
+
62
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
+ switch action
64
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
65
+ case 'Checka1'
66
+
67
+ e_a1_val = str2num(get(he_FastICA_a1, 'String'));
68
+ if e_a1_val <= 0
69
+ set(he_FastICA_a1, 'String', '0.1');
70
+ end
71
+
72
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
73
+ case 'Checka2'
74
+
75
+ e_a2_val = str2num(get(he_FastICA_a2, 'String'));
76
+ if e_a2_val <= 0
77
+ set(he_FastICA_a2, 'String', '0.1');
78
+ end
79
+
80
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
81
+ case 'CheckMyy'
82
+
83
+ e_myy_val = str2num(get(he_FastICA_myy, 'String'));
84
+ if e_myy_val <= 0
85
+ set(he_FastICA_myy, 'String', '0.1');
86
+ elseif e_myy_val > 1
87
+ set(he_FastICA_myy, 'String', '1');
88
+ end
89
+
90
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
91
+ case 'CheckSampleSize'
92
+
93
+ e_sampleSize_val = str2num(get(he_FastICA_sampleSize, 'String'));
94
+ if e_sampleSize_val > 1
95
+ set(he_FastICA_sampleSize, 'String', '1');
96
+ else
97
+ numOfSamp = str2num(get(ht_FastICA_numOfSamp, 'String'));
98
+ if numOfSamp < 1000
99
+ set(he_FastICA_sampleSize, 'String', '1');
100
+ fprintf('Can''t reduce sample size. Already less than 1000 samples.\n');
101
+ elseif (e_sampleSize_val * numOfSamp) < 1000
102
+ fprintf('Can''t reduce sample size to less than 1000 samples.\n');
103
+ set(he_FastICA_sampleSize, 'String', sprintf('%0.3f',1000/numOfSamp));
104
+ end
105
+ end
106
+
107
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
108
+ case 'loadGuess'
109
+
110
+ handle = findobj('Tag','f_FastICALoad'); % Check if the window is already
111
+ if isempty(handle) % open. If not then open it.
112
+ pos = get(hf_FastICA_MAIN, 'Position');
113
+ gui_l(pos(1), pos(2));
114
+ else
115
+ if strcmp(g_FastICA_loadType, 'guess') % Check if it was the same load
116
+ figure(handle); % window. If it wasn't then
117
+ else % close the other window first
118
+ close(handle); % and then open the load window
119
+ fprintf('''Load data'' -dialog closed!\n');
120
+ pos = get(hf_FastICA_MAIN, 'Position');
121
+ gui_l(pos(1), pos(2));
122
+ end
123
+ end
124
+
125
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
126
+ case 'OK'
127
+
128
+ gui_advc Apply;
129
+
130
+ close(hf_FastICA_AdvOpt);
131
+
132
+ % Use return to avoid reaching the watchoff statement at the end
133
+ % (There used to be a 'break' statement here, but it resulted in
134
+ % errors in more recent version of Matlab -- jarmo)
135
+ return;
136
+
137
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
+ case 'Apply'
139
+
140
+ newValues = 0;
141
+
142
+ val = g_FastICA_finetune;
143
+ g_FastICA_finetune = get(hpm_FastICA_finetune, 'Value');
144
+ if (g_FastICA_finetune ~= val)
145
+ newValues = 1;
146
+ end
147
+
148
+ val = g_FastICA_a1;
149
+ g_FastICA_a1 = str2num(get(he_FastICA_a1, 'String'));
150
+ if (g_FastICA_a1 ~= val)
151
+ newValues = 1;
152
+ end
153
+
154
+ val = g_FastICA_a2;
155
+ g_FastICA_a2 = str2num(get(he_FastICA_a2, 'String'));
156
+ if (g_FastICA_a2 ~= val)
157
+ newValues = 1;
158
+ end
159
+
160
+ val = g_FastICA_myy;
161
+ g_FastICA_myy = str2num(get(he_FastICA_myy, 'String'));
162
+ if (g_FastICA_myy ~= val)
163
+ newValues = 1;
164
+ end
165
+
166
+ % If myy < 1 then will use stabilazed code, and we don't care
167
+ % about the parameter stabilization :-)
168
+ if (g_FastICA_myy == 1)
169
+ set(hpm_FastICA_stabilization, 'Enable', 'on');
170
+ else
171
+ set(hpm_FastICA_stabilization, 'Enable', 'off');
172
+ end
173
+
174
+ val = g_FastICA_epsilon;
175
+ g_FastICA_epsilon = str2num(get(he_FastICA_epsilon, 'String'));
176
+ if (g_FastICA_epsilon ~= val)
177
+ newValues = 1;
178
+ end
179
+
180
+ val = g_FastICA_maxNumIte;
181
+ g_FastICA_maxNumIte = str2num(get(he_FastICA_maxIterations, 'String'));
182
+ if (g_FastICA_maxNumIte ~= val)
183
+ newValues = 1;
184
+ end
185
+
186
+ val = g_FastICA_maxFinetune;
187
+ g_FastICA_maxFinetune = str2num(get(he_FastICA_maxFinetune, 'String'));
188
+ if (g_FastICA_maxFinetune ~= val)
189
+ newValues = 1;
190
+ end
191
+
192
+ val = g_FastICA_sampleSize;
193
+ g_FastICA_sampleSize = str2num(get(he_FastICA_sampleSize, 'String'));
194
+ if (g_FastICA_sampleSize ~= val)
195
+ newValues = 1;
196
+ end
197
+
198
+ val = g_FastICA_initState;
199
+ g_FastICA_initState = get(hpm_FastICA_initState, 'Value');
200
+ if (g_FastICA_initState ~= val)
201
+ newValues = 1;
202
+ end
203
+
204
+ val = g_FastICA_initGuess;
205
+ g_FastICA_initGuess = get(hb_FastICA_initGuess, 'UserData');
206
+ if min(size(val) == size(g_FastICA_initGuess)) == 0
207
+ newValues = 1;
208
+ else
209
+ if (g_FastICA_initGuess ~= val)
210
+ newValues = 1;
211
+ end
212
+ end
213
+
214
+ g_FastICA_displayMo = get(hpm_FastICA_displayMode, 'Value');
215
+ g_FastICA_displayIn = str2num(get(he_FastICA_displayInterval, 'String'));
216
+ g_FastICA_verbose = get(hpm_FastICA_verbose, 'Value');
217
+
218
+ if newValues == 1
219
+ gui_cb NullICA;
220
+ end
221
+
222
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
223
+ case 'Cancel'
224
+
225
+ close(hf_FastICA_AdvOpt);
226
+
227
+ % Use return to avoid reaching the watchoff statement at the end
228
+ % (There used to be a 'break' statement here, but it resulted in
229
+ % errors in more recent version of Matlab -- jarmo)
230
+ return;
231
+
232
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
233
+ case 'Default'
234
+
235
+ % set default values to controls
236
+ set(hpm_FastICA_finetune, 'Value',5);
237
+ set(he_FastICA_a1, 'String','1');
238
+ set(he_FastICA_a2, 'String','1');
239
+ set(he_FastICA_myy, 'String','1');
240
+ set(he_FastICA_epsilon, 'String','0.0001');
241
+ set(he_FastICA_maxIterations, 'String','1000');
242
+ set(he_FastICA_sampleSize, 'String','1');
243
+ set(hpm_FastICA_initState, 'Value',1);
244
+ set(hpm_FastICA_displayMode, 'Value',1);
245
+ set(he_FastICA_displayInterval, 'String','1');
246
+ set(hpm_FastICA_verbose, 'Value',1);
247
+
248
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249
+ case 'Help'
250
+
251
+ gui_help('gui_advc');
252
+
253
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
254
+ end % switch
255
+
256
+ watchoff (watchonInFigure);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cb.m ADDED
@@ -0,0 +1,581 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_cb(action)
2
+ %
3
+ % This file is used by FASTICAG
4
+
5
+ % This file holds the callbacks to the main window
6
+
7
+ % @(#)$Id: gui_cb.m,v 1.5 2003/09/10 10:33:41 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the main figure
13
+ global hf_FastICA_MAIN;
14
+
15
+ % Handles for needed controls in main figure;
16
+ global ht_FastICA_mixedStatus;
17
+ global ht_FastICA_dim;
18
+ global ht_FastICA_numOfSamp;
19
+ global ht_FastICA_newDim;
20
+ global ht_FastICA_whiteStatus;
21
+ global ht_FastICA_icaStatus;
22
+ global hpm_FastICA_approach;
23
+ global he_FastICA_numOfIC;
24
+ global hpm_FastICA_g;
25
+ global hpm_FastICA_stabilization;
26
+
27
+ % Main values are stored here
28
+ global g_FastICA_mixedsig;
29
+ global g_FastICA_mixedmean;
30
+ global g_FastICA_pca_D;
31
+ global g_FastICA_pca_E;
32
+ global g_FastICA_white_sig;
33
+ global g_FastICA_white_wm;
34
+ global g_FastICA_white_dwm;
35
+ global g_FastICA_ica_sig;
36
+ global g_FastICA_ica_A;
37
+ global g_FastICA_ica_W;
38
+ global g_FastICA_initGuess;
39
+ global g_FastICA_approach;
40
+ global g_FastICA_numOfIC;
41
+ global g_FastICA_g;
42
+ global g_FastICA_finetune;
43
+ global g_FastICA_a1;
44
+ global g_FastICA_a2;
45
+ global g_FastICA_myy;
46
+ global g_FastICA_stabilization;
47
+ global g_FastICA_epsilon;
48
+ global g_FastICA_maxNumIte;
49
+ global g_FastICA_maxFinetune;
50
+ global g_FastICA_sampleSize;
51
+ global g_FastICA_initState;
52
+ global g_FastICA_displayMo;
53
+ global g_FastICA_displayIn;
54
+ global g_FastICA_verbose;
55
+
56
+ % String values are here
57
+ global c_FastICA_appr_strV;
58
+ global c_FastICA_g1_strD;
59
+ global c_FastICA_g1_strV;
60
+ global c_FastICA_g2_strD;
61
+ global c_FastICA_g2_strV;
62
+ global c_FastICA_finetune_strD;
63
+ global c_FastICA_finetune_strV;
64
+ global c_FastICA_stabili_strV;
65
+ global c_FastICA_iSta_strV;
66
+ global c_FastICA_dMod_strV;
67
+ global c_FastICA_verb_strV;
68
+
69
+ % What is the load type of load dialog
70
+ global g_FastICA_loadType;
71
+
72
+ % Global variable for stopping the ICA calculations
73
+ global g_FastICA_interrupt;
74
+
75
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76
+ % What ever we do, it will take some time... not much, but some :-)
77
+ watchonInFigure = watchon;
78
+
79
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80
+ switch action
81
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82
+ case 'InitAll'
83
+
84
+ % If the data is already loaded, then get the information from data
85
+ % and show to the user (also set g_FastICA_numOfIC)
86
+ if ~isempty(g_FastICA_mixedsig)
87
+ set(ht_FastICA_mixedStatus, 'String', '');
88
+ [dim, numofsamp] = size(g_FastICA_mixedsig);
89
+ set(ht_FastICA_dim, 'String', int2str(dim));
90
+ set(ht_FastICA_numOfSamp, 'String', int2str(numofsamp));
91
+ set(ht_FastICA_newDim, 'String', int2str(dim));
92
+ set(he_FastICA_numOfIC, 'String', int2str(dim));
93
+ g_FastICA_numOfIC = dim;
94
+ g_FastICA_mixedmean = [];
95
+ end
96
+
97
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
98
+ case 'LoadData'
99
+
100
+ handle = findobj('Tag','f_FastICALoad'); % Check if the window is already
101
+ if isempty(handle) % open. If not then open it.
102
+ pos = get(hf_FastICA_MAIN, 'Position');
103
+ % Based on the feedback obtained from some users, it seems
104
+ % that at least in some systems, pos can sometimes be empty. A
105
+ % similar check is done a few lines below.
106
+ if ~isempty (pos),
107
+ gui_l(pos(1), pos(2));
108
+ else
109
+ gui_l (0, 0);
110
+ end
111
+ else
112
+ if strcmp(g_FastICA_loadType, 'data') % Check if it was the same load
113
+ figure(handle); % window. If it wasn't then
114
+ else % close the other window first
115
+ close(handle); % and then open the load window
116
+ fprintf('''Load initial guess'' -dialog closed!\n');
117
+ pos = get(hf_FastICA_MAIN, 'Position');
118
+ if ~isempty (pos),
119
+ gui_l(pos(1), pos(2));
120
+ else
121
+ gui_l (0, 0);
122
+ end
123
+ end
124
+ end
125
+
126
+ % gui_cb NewData; - is called from the load function if not canceled...
127
+
128
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
129
+ case 'NewData'
130
+
131
+ % New data is loaded or the old data changed. We need to find out
132
+ % somethings about the new data... and do some other stuff also...
133
+ [dim, numofsamp] = size(g_FastICA_mixedsig);
134
+ set(ht_FastICA_dim, 'String', dim);
135
+ set(ht_FastICA_newDim, 'String', dim);
136
+ set(ht_FastICA_numOfSamp, 'String', numofsamp);
137
+ set(he_FastICA_numOfIC, 'String', int2str(dim));
138
+
139
+ g_FastICA_numOfIC = dim; % Default for numOfIC = the new dimension
140
+ % PCA needs to be calculated again.
141
+ g_FastICA_pca_E = []; % We use this to check if PCA is calculated
142
+ gui_cb NullWhite; % Whitening needs to be done again also
143
+
144
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145
+ case 'NullWhite'
146
+
147
+ % Whitening needs to done again next time it's needed
148
+ g_FastICA_white_sig = []; % We use this to check if whitening is calculated
149
+ gui_cb NullICA; % The FPICA must be calculated again
150
+
151
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
+ case 'NullICA'
153
+
154
+ % If IC's are needed they have to bee calculated again
155
+ g_FastICA_ica_sig = []; % We use this to check if FPICA is calculated
156
+ set(ht_FastICA_icaStatus,'String','Not yet done');
157
+
158
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
+ case 'Transpose'
160
+
161
+ if isempty(g_FastICA_mixedmean)
162
+ g_FastICA_mixedsig = g_FastICA_mixedsig';
163
+ else
164
+ g_FastICA_mixedsig = (g_FastICA_mixedsig + ...
165
+ g_FastICA_mixedmean * ...
166
+ ones(1,size(g_FastICA_mixedsig, 2)))';
167
+ g_FastICA_mixedmean = [];
168
+ end
169
+ gui_cb NewData; % Data has been changed
170
+
171
+
172
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
173
+ case 'DoPCA'
174
+
175
+ if ~isempty(g_FastICA_mixedsig)
176
+ % We'll remove mean of the data here also just in case...
177
+ if isempty(g_FastICA_mixedmean)
178
+ [g_FastICA_mixedsig, g_FastICA_mixedmean] = remmean(g_FastICA_mixedsig);
179
+ end
180
+
181
+ % Do PCA interactively: ask the user for eigenvalues
182
+ [g_FastICA_pca_E, g_FastICA_pca_D] = pcamat(g_FastICA_mixedsig, ...
183
+ 0, 0, 'gui', ...
184
+ deblank(c_FastICA_verb_strV(g_FastICA_verbose,:)));
185
+
186
+ newdim = size(g_FastICA_pca_D, 1);
187
+ set(ht_FastICA_newDim, 'String', int2str(newdim));
188
+ set(he_FastICA_numOfIC, 'String', int2str(newdim));
189
+ g_FastICA_numOfIC = newdim;
190
+ gui_cb NullWhite; % Whitening needs to be done again also
191
+ % but we'll do it when it's needed.
192
+ else
193
+ fprintf('Data not loaded yet!\n\n');
194
+ end
195
+
196
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
197
+ case 'OrigDim'
198
+
199
+ gui_cb NewData;
200
+
201
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202
+ case 'ShowMixed'
203
+
204
+ if ~isempty(g_FastICA_mixedsig)
205
+ handle = findobj('Tag','f_FastICA_mix'); % Check if the window is already
206
+ if isempty(handle) % open. If not then open it.
207
+ figure('Tag', 'f_FastICA_mix', ...
208
+ 'Name', 'FastICA: Plot data', ...
209
+ 'NumberTitle', 'off');
210
+ else
211
+ figure(handle);
212
+ clf; % clear the figure for next plots
213
+ end
214
+ if isempty(g_FastICA_mixedmean)
215
+ icaplot('dispsig',g_FastICA_mixedsig, 0, 0, 0, 'Mixed signals');
216
+ else
217
+ icaplot('dispsig',g_FastICA_mixedsig + g_FastICA_mixedmean * ...
218
+ ones(1, size(g_FastICA_mixedsig, 2)), 0, 0, 0, 'Mixed signals');
219
+ end
220
+ else
221
+ fprintf('Data not loaded yet!\n\n');
222
+ end
223
+
224
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
225
+ case 'ShowWhite'
226
+
227
+ if ~isempty(g_FastICA_mixedsig)
228
+ if isempty(g_FastICA_white_sig) % if whitening is not done, we need to
229
+ gui_cb Whiten; % do it before we can display the
230
+ end % whitened signals
231
+
232
+ handle = findobj('Tag','f_FastICA_white'); % Check if the window is already
233
+ if isempty(handle) % open. If not then open it.
234
+ figure('Tag', 'f_FastICA_white', ...
235
+ 'Name', 'FastICA: Plot whitened', ...
236
+ 'NumberTitle', 'off');
237
+ else
238
+ figure(handle);
239
+ clf; % clear the figure for next plots
240
+ end
241
+ icaplot('dispsig',g_FastICA_white_sig,0,0,0,'Whitened signals');
242
+ else
243
+ fprintf('Data not loaded yet!\n\n');
244
+ end
245
+
246
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
247
+ case 'Whiten'
248
+
249
+ set(ht_FastICA_whiteStatus,'String','Computing...');
250
+
251
+ % If PCA is not calculated, we'll have to calculate it now,
252
+ % we'll do it without guestions - we don't reduce the dimension
253
+ % here - but PCAMAT might reduce the dimension automatically.
254
+ if isempty(g_FastICA_pca_E)
255
+ % We'll remove mean of the data here also just in case...
256
+ if isempty(g_FastICA_mixedmean)
257
+ [g_FastICA_mixedsig, g_FastICA_mixedmean] = remmean(g_FastICA_mixedsig);
258
+ end
259
+
260
+ [g_FastICA_pca_E, g_FastICA_pca_D] = pcamat(g_FastICA_mixedsig, 1, ...
261
+ size(g_FastICA_mixedsig, ...
262
+ 1), 'off', ...
263
+ deblank(c_FastICA_verb_strV(g_FastICA_verbose,:)));
264
+
265
+ % Check if the dimension was reduced automatically
266
+ newdim = size(g_FastICA_pca_D, 1);
267
+ set(ht_FastICA_newDim, 'String', int2str(newdim));
268
+ % Check if the numOfIC now has illegal value entered
269
+ % We do that by telling the program that there is new value
270
+ % entered for NumOfIC.
271
+ gui_cb ChangeNumOfIC;
272
+ end
273
+
274
+ % And now we can calculate whitening...
275
+ [g_FastICA_white_sig, g_FastICA_white_wm, g_FastICA_white_dwm] = ...
276
+ whitenv(g_FastICA_mixedsig, g_FastICA_pca_E, g_FastICA_pca_D, deblank(c_FastICA_verb_strV(g_FastICA_verbose,:)));
277
+
278
+ set (ht_FastICA_whiteStatus,'String','');
279
+
280
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
281
+ case 'ChangeApproach'
282
+
283
+ % Get the old value for g
284
+ eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']);
285
+ old_g = deblank(g_str(g_FastICA_g,:));
286
+
287
+ % Get and set the new value for approach
288
+ g_FastICA_approach = get(hpm_FastICA_approach, 'Value');
289
+
290
+ % The possible values for g depend on the value of approach...
291
+ eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strD;']);
292
+ set(hpm_FastICA_g, 'String', g_str);
293
+
294
+ % Match the old g value from the new g values so that if the
295
+ % old_g can be found from the new values (anywhere), then set new g
296
+ % to that value, and if it's not found then set the new value to 1.
297
+ match = 0;
298
+ eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']);
299
+ for i=1:size(g_str,1)
300
+ if strcmp(old_g, deblank(g_str(i,:)))
301
+ match = i;
302
+ end
303
+ end
304
+ if match == 0
305
+ match = 1; % the old g is not availabe anymore, set g = 1.
306
+ end
307
+ g_FastICA_g = match;
308
+ set(hpm_FastICA_g, 'Value', match);
309
+
310
+ gui_cb NullICA; % The options are changed so we must calculate ICA again
311
+
312
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313
+ case 'ChangeNumOfIC'
314
+
315
+ % Get the new value... and store it later on after some checks
316
+ numofic = str2num(get(he_FastICA_numOfIC, 'String'));
317
+
318
+ % The number of IC can't be less than 1 or more than the reduced dimension.
319
+ numoficmax = str2num(get(ht_FastICA_newDim, 'String'));
320
+ if numofic < 1
321
+ set(he_FastICA_numOfIC, 'String', '1');
322
+ g_FastICA_numOfIC = 1;
323
+ elseif numofic > numoficmax
324
+ set(he_FastICA_numOfIC, 'String', int2str (numoficmax));
325
+ g_FastICA_numOfIC = numoficmax;
326
+ else
327
+ g_FastICA_numOfIC = numofic;
328
+ end
329
+
330
+ gui_cb NullICA; % The options are changed so we must calculate ICA again
331
+
332
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
333
+ case 'ChangeG'
334
+
335
+ % Get the new value for g.
336
+ g_FastICA_g = get(hpm_FastICA_g, 'Value');
337
+
338
+ gui_cb NullICA; % The options are changed so we must calculate ICA again
339
+
340
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
341
+ case 'ChangeStab'
342
+
343
+ % Get the new value for g.
344
+ g_FastICA_stabilization = get(hpm_FastICA_stabilization, 'Value');
345
+
346
+ gui_cb NullICA; % The options are changed so we must calculate ICA again
347
+
348
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349
+ case 'AdvOpt'
350
+
351
+ handle = findobj('Tag','f_FastICAAdvOpt');
352
+ if isempty(handle) % Check to see if the window is
353
+ pos = get(hf_FastICA_MAIN, 'Position'); % already open...
354
+ if ~isempty (pos),
355
+ gui_adv(pos(1), pos(2));
356
+ else
357
+ gui_adv(0, 0);
358
+ end
359
+ else
360
+ figure(handle)
361
+ end
362
+
363
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364
+ case 'ShowICASig'
365
+
366
+ if ~isempty(g_FastICA_mixedsig)
367
+ % If the IC's are not already calculated, we'll do it now
368
+ if isempty(g_FastICA_ica_sig)
369
+ gui_cb DoFPICA;
370
+ end
371
+
372
+ % The signals may have been already displaued by the FPICA function
373
+ % BUT the FPICA may also have shown either the basis of the filters
374
+ % so the signals still need to be shown - besides the mean was added
375
+ % in only later after FPICA
376
+
377
+ % Also notice that in this version if there was something wrong in FPICA
378
+ % Then the results are []. - We don't try to plot them!
379
+ if ~isempty(g_FastICA_ica_sig')
380
+ handle = findobj('Tag','f_FastICA_ica'); % Check if the window is already
381
+ if isempty(handle) % open. If not then open it.
382
+ figure('Tag', 'f_FastICA_ica', ...
383
+ 'Name', 'FastICA: Plot ICs', ...
384
+ 'NumberTitle', 'off');
385
+ else
386
+ figure(handle);
387
+ clf; % clear the figure for next plots
388
+ end
389
+
390
+ icaplot('dispsig', g_FastICA_ica_sig, 0, ...
391
+ 0, 0, 'Independent components');
392
+ end
393
+ else
394
+ fprintf('Data not loaded yet!\n\n');
395
+ end
396
+
397
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
398
+ case 'DoFPICA'
399
+
400
+ gui_cb DisableButtons;
401
+ g_FastICA_interrupt = 0;
402
+
403
+ if ~isempty(g_FastICA_mixedsig)
404
+ if isempty(g_FastICA_white_sig) % We need the whitened signal here
405
+ gui_cb Whiten;
406
+ end
407
+
408
+ set(ht_FastICA_icaStatus,'String','Computing...');
409
+
410
+ % The possible values for g depend on approach
411
+ eval(['g_str = c_FastICA_g' int2str(g_FastICA_approach) '_strV;']);
412
+
413
+ % We'll contruct a command string which we'll later on evaluate...
414
+ % This is where the Fixed point algorithm is used.
415
+ command_str = ['[g_FastICA_ica_A,g_FastICA_ica_W]=' ...
416
+ 'fpica(g_FastICA_white_sig,' ...
417
+ 'g_FastICA_white_wm,' ...
418
+ 'g_FastICA_white_dwm,' ...
419
+ '''' deblank(c_FastICA_appr_strV(g_FastICA_approach,:)) ...
420
+ ''',' ...
421
+ 'g_FastICA_numOfIC,' ...
422
+ '''' deblank(g_str(g_FastICA_g,:)) ''',' ...
423
+ '''' ...
424
+ deblank(c_FastICA_finetune_strV(g_FastICA_finetune,:)) ...
425
+ ''',' ...
426
+ 'g_FastICA_a1,' ...
427
+ 'g_FastICA_a2,' ...
428
+ 'g_FastICA_myy,' ...
429
+ '''' ...
430
+ deblank(c_FastICA_stabili_strV(g_FastICA_stabilization,:)) ...
431
+ ''',' ...
432
+ 'g_FastICA_epsilon,' ...
433
+ 'g_FastICA_maxNumIte,' ...
434
+ 'g_FastICA_maxFinetune,' ...
435
+ '''' deblank(c_FastICA_iSta_strV(g_FastICA_initState,:)) ...
436
+ ''',' ...
437
+ 'g_FastICA_initGuess,' ...
438
+ 'g_FastICA_sampleSize,' ...
439
+ '''' deblank(c_FastICA_dMod_strV(g_FastICA_displayMo,:)) ...
440
+ ''',' ...
441
+ 'g_FastICA_displayIn,' ...
442
+ '''' deblank(c_FastICA_verb_strV(g_FastICA_verbose,:)) ...
443
+ ''');'];
444
+
445
+
446
+ % If the user wants to plot while computing...
447
+ % let's at least plot it to the right figure then
448
+ if ~strcmp(deblank(c_FastICA_dMod_strV(g_FastICA_displayMo,:)),'off')
449
+ handle = findobj('Tag','f_FastICA_ica'); % Check if the window is already
450
+ if isempty(handle) % open. If not then open it.
451
+ figure('Tag', 'f_FastICA_ica', ...
452
+ 'Name', 'FastICA: Plot ICs', ...
453
+ 'NumberTitle', 'off');
454
+ else
455
+ figure(handle);
456
+ clf; % clear the figure for next plots
457
+ end
458
+ end
459
+
460
+ % ... and so let's do it...
461
+ eval(command_str);
462
+
463
+ % Also notice that in this version if there was something wrong in FPICA
464
+ % Then the results are [].
465
+ if ~isempty(g_FastICA_ica_W)
466
+ % Add the mean back in.
467
+ g_FastICA_ica_sig = g_FastICA_ica_W * g_FastICA_mixedsig ...
468
+ + (g_FastICA_ica_W * g_FastICA_mixedmean) ...
469
+ * ones(1,size(g_FastICA_mixedsig, 2));
470
+ set (ht_FastICA_icaStatus,'String','Done');
471
+ else
472
+ gui_cb NullICA; % set icasig=[] and do what ever needs to be done then
473
+ end
474
+
475
+ if ~(g_FastICA_interrupt)
476
+ gui_cb EnableButtons;
477
+ end
478
+ else
479
+ fprintf('Data not loaded yet!\n\n');
480
+ end
481
+
482
+
483
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
484
+ case 'Interrupt'
485
+ g_FastICA_interrupt = 1;
486
+ set(ht_FastICA_icaStatus,'String','Interrupted');
487
+ gui_cb EnableButtons;
488
+
489
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
490
+ case 'DisableButtons'
491
+ set(findobj('Tag','b_Transpose'),'Enable','off');
492
+ set(findobj('Tag','b_ShowMixed'),'Enable','off');
493
+ set(findobj('Tag','b_DoPCA'),'Enable','off');
494
+ set(findobj('Tag','b_OrigDim'),'Enable','off');
495
+ set(findobj('Tag','b_ShowWhite'),'Enable','off');
496
+ set(findobj('Tag','b_advOpt'),'Enable','off');
497
+ set(findobj('Tag','b_ShowICASig'),'Enable','off');
498
+ set(findobj('Tag','b_LoadData'),'Enable','off');
499
+ set(findobj('Tag','b_DoFPICA'),'Enable','off');
500
+ set(findobj('Tag','b_SaveData'),'Enable','off');
501
+ set(findobj('Tag','b_Quit'),'Enable','off');
502
+ set(findobj('Tag','b_Interrupt'),'Visible','on');
503
+ drawnow;
504
+
505
+
506
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
507
+ case 'EnableButtons'
508
+ set(findobj('Tag','b_Transpose'),'Enable','on');
509
+ set(findobj('Tag','b_ShowMixed'),'Enable','on');
510
+ set(findobj('Tag','b_DoPCA'),'Enable','on');
511
+ set(findobj('Tag','b_OrigDim'),'Enable','on');
512
+ set(findobj('Tag','b_ShowWhite'),'Enable','on');
513
+ set(findobj('Tag','b_advOpt'),'Enable','on');
514
+ set(findobj('Tag','b_ShowICASig'),'Enable','on');
515
+ set(findobj('Tag','b_LoadData'),'Enable','on');
516
+ set(findobj('Tag','b_DoFPICA'),'Enable','on');
517
+ set(findobj('Tag','b_SaveData'),'Enable','on');
518
+ set(findobj('Tag','b_Quit'),'Enable','on');
519
+ set(findobj('Tag','b_Interrupt'),'Visible','off');
520
+ drawnow;
521
+
522
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
523
+ case 'SaveData'
524
+
525
+ handle = findobj('Tag','f_FastICASave'); % Check if the window is already
526
+ if isempty(handle) % open. If not then open it.
527
+ pos = get(hf_FastICA_MAIN, 'Position');
528
+ if ~isempty (pos),
529
+ gui_s(pos(1), pos(2));
530
+ else
531
+ gui_s(0, 0);
532
+ end
533
+ else
534
+ figure(handle); % window. If it wasn't then
535
+ end
536
+
537
+
538
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539
+ case 'Quit'
540
+
541
+ % We'll close the other dialogs if they are open.
542
+ Tags = ['f_FastICALoad '
543
+ 'f_FastICAAdvOpt'
544
+ 'f_FastICASave '
545
+ 'f_FastICA_mix '
546
+ 'f_FastICA_white'
547
+ 'f_FastICA_ica '];
548
+ for i=1:size(Tags,1)
549
+ handle = findobj('Tag', deblank(Tags(i,:)));
550
+ if ~isempty(handle)
551
+ close(handle);
552
+ end
553
+ end
554
+
555
+ % Close this window
556
+ close(hf_FastICA_MAIN);
557
+
558
+ % Clear the used global variables.
559
+ gui_cg;
560
+
561
+ % Use return to avoid reaching the watchoff statement at the end
562
+ % (There used to be a 'break' statement here, but it resulted in
563
+ % errors in more recent version of Matlab -- jarmo)
564
+ return;
565
+ % ... and we're done.
566
+
567
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
568
+ case 'About'
569
+
570
+ gui_help('gui_cb_about');
571
+
572
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
573
+ case 'Help'
574
+
575
+ gui_help('gui_cb_help');
576
+
577
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
578
+
579
+ end % switch
580
+
581
+ watchoff (watchonInFigure);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_cg.m ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_cg()
2
+ %
3
+ % This function is needed by FASTICAG
4
+
5
+ % This file just removes the global variables
6
+ % that are used in FASTICAG from the memory
7
+
8
+ % @(#)$Id: gui_cg.m,v 1.2 2003/04/05 14:23:57 jarmo Exp $
9
+
10
+ clear global c_FastICA_appr_strD;
11
+ clear global c_FastICA_appr_strV;
12
+ clear global c_FastICA_dMod_strD;
13
+ clear global c_FastICA_dMod_strV;
14
+ clear global c_FastICA_finetune_strD;
15
+ clear global c_FastICA_finetune_strV;
16
+ clear global c_FastICA_g1_strD;
17
+ clear global c_FastICA_g1_strV;
18
+ clear global c_FastICA_g2_strD;
19
+ clear global c_FastICA_g2_strV;
20
+ clear global c_FastICA_iSta_strD;
21
+ clear global c_FastICA_iSta_strV;
22
+ clear global c_FastICA_stabili_strD;
23
+ clear global c_FastICA_stabili_strV;
24
+ clear global c_FastICA_verb_strD;
25
+ clear global c_FastICA_verb_strV;
26
+ clear global g_FastICA_a1;
27
+ clear global g_FastICA_a2;
28
+ clear global g_FastICA_approach;
29
+ clear global g_FastICA_displayIn;
30
+ clear global g_FastICA_displayMo;
31
+ clear global g_FastICA_epsilon;
32
+ clear global g_FastICA_finetune;
33
+ clear global g_FastICA_g;
34
+ clear global g_FastICA_ica_A;
35
+ clear global g_FastICA_ica_W;
36
+ clear global g_FastICA_ica_sig;
37
+ clear global g_FastICA_initGuess;
38
+ clear global g_FastICA_initState;
39
+ clear global g_FastICA_interrupt;
40
+ clear global g_FastICA_loadType;
41
+ clear global g_FastICA_maxFinetune;
42
+ clear global g_FastICA_maxNumIte;
43
+ clear global g_FastICA_mixedmean;
44
+ clear global g_FastICA_mixedsig;
45
+ clear global g_FastICA_myy;
46
+ clear global g_FastICA_numOfIC;
47
+ clear global g_FastICA_pca_D;
48
+ clear global g_FastICA_pca_E;
49
+ clear global g_FastICA_sampleSize;
50
+ clear global g_FastICA_stabilization;
51
+ clear global g_FastICA_verbose;
52
+ clear global g_FastICA_white_dwm;
53
+ clear global g_FastICA_white_sig;
54
+ clear global g_FastICA_white_wm;
55
+ clear global hb_FastICA_initGuess;
56
+ clear global he_FastICA_a1;
57
+ clear global he_FastICA_a2;
58
+ clear global he_FastICA_displayInterval;
59
+ clear global he_FastICA_epsilon;
60
+ clear global he_FastICA_file;
61
+ clear global he_FastICA_suffix;
62
+ clear global he_FastICA_maxFinetune;
63
+ clear global he_FastICA_maxIterations;
64
+ clear global he_FastICA_myy;
65
+ clear global he_FastICA_numOfIC;
66
+ clear global he_FastICA_sampleSize;
67
+ clear global hf_FastICA_MAIN;
68
+ clear global hf_FastICA_AdvOpt;
69
+ clear global hf_FastICA_Load;
70
+ clear global hf_FastICA_Save;
71
+ clear global hpm_FastICA_approach;
72
+ clear global hpm_FastICA_displayMode;
73
+ clear global hpm_FastICA_finetune;
74
+ clear global hpm_FastICA_g;
75
+ clear global hpm_FastICA_initState;
76
+ clear global hpm_FastICA_stabilization;
77
+ clear global hpm_FastICA_verbose;
78
+ clear global ht_FastICA_dim;
79
+ clear global ht_FastICA_icaStatus;
80
+ clear global ht_FastICA_initGuess;
81
+ clear global ht_FastICA_mixedStatus;
82
+ clear global ht_FastICA_newDim;
83
+ clear global ht_FastICA_numOfSamp;
84
+ clear global ht_FastICA_whiteStatus;
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_help.m ADDED
@@ -0,0 +1,224 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_help(which_help)
2
+ %
3
+ % Used by FASTICAG
4
+
5
+ % All the help texts and title used by GUI are stored here.
6
+ % Make changes here.
7
+ % Also displays the helpwindow with the selected text
8
+
9
+ % @(#)$Id: gui_help.m,v 1.6 2005/10/19 13:05:34 jarmo Exp $
10
+
11
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
12
+ switch which_help
13
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14
+ case 'pcamat'
15
+
16
+ helptitle = 'FastICA: Reduce dimension';
17
+ helptext=[ ...
18
+ 'You may reduce the dimension of the data by selecting only the '
19
+ 'subspace corresponding to certain eigenvalues of the covariance '
20
+ 'matrix of the data. Give the indices of the first and last '
21
+ 'eigenvalues (sorted in descending order) to be included (all '
22
+ 'eigenvalues in between will be included as well). The eigenvalues '
23
+ 'and their indices can be seen in the graphical plot now on the '
24
+ 'screen. The heights of the bars give the eigenvalues, with indices '
25
+ 'below. '
26
+ ' '
27
+ 'For example, give ''1'' and ''n'' if you want to reduce the dimension '
28
+ 'to n by principal component analysis, which means discarding the '
29
+ 'subspaces corresponding to the smallest eigenvalues. Such a '
30
+ 'dimension reduction may reduce noise and improve the performance of'
31
+ 'ICA. '];
32
+
33
+
34
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
+ case 'gui_cb_about'
36
+
37
+ helptitle='About FastICA';
38
+ helptext =[ ...
39
+ 'FastICA for Matlab 7.x and 6.x '
40
+ 'Version 2.5, October 19 2005 '
41
+ 'Copyright (c) Hugo G�vert, Jarmo Hurri, Jaakko S�rel�, and Aapo Hyv�rinen.'
42
+ ' '
43
+ 'For more information please see: '
44
+ 'http://www.cis.hut.fi/projects/ica/fastica/ '];
45
+
46
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
+ case 'gui_cb_help'
48
+
49
+ helptitle='FastICA GUI';
50
+ helptext = [...
51
+ 'Basic function: '
52
+ ' '
53
+ '- Click LOAD DATA and give the name of the variable that contains '
54
+ ' the data. '
55
+ ' '
56
+ '- Click DO ICA to perform the analysis. '
57
+ ' '
58
+ '- Click SAVE RESULTS to store the results for future use. '
59
+ ' '
60
+ 'Options: '
61
+ ' '
62
+ 'If the input matrix contains the signals as column vectors instead of '
63
+ 'row vectors, click on TRANSPOSE to transpose the data matrix. '
64
+ ' '
65
+ 'Click on PLOT DATA to see the data as 1-D time signals. '
66
+ ' '
67
+ 'Clicking REDUCE DIM gives you a graphical plot of the eigenvalue '
68
+ 'structure of the covariance matrix of the data. You can then reduce '
69
+ 'the dimension of the data by retaining only the subspaces corresponding to '
70
+ 'the largest (or smallest) eigenvalues (i.e. variances). To undo this '
71
+ 'operation click ORIGINAL DIM. You can plot the whitened (preprocessed '
72
+ 'data) by PLOT WHITENED. '
73
+ ' '
74
+ 'Click on DO ICA to perform independent component analysis. '
75
+ 'Clicking on PLOT ICS has the same effect, except that DO ICA forces '
76
+ 'recomputation of ICA. '
77
+ ' '
78
+ 'You can choose the decorrelation approach by the ''Approach'' drop-down menu:'
79
+ 'deflation means that the independent components are estimated '
80
+ 'one-by-one, whereas in the symmetric approach they are estimated in '
81
+ 'parallel. You can now choose the number of independent components to be '
82
+ 'estimated in both deflation and symmetric approaches. '
83
+ ' '
84
+ 'You have a choice of three nonlinearities: '
85
+ ' '
86
+ '''pow3'' (default) : g(u)=u^3 '
87
+ '''tanh'' : g(u)=tanh(u) '
88
+ '''gauss'' : g(u)=u*exp(-u^2/2) '
89
+ '''skew'' : g(u)=u^2 '
90
+ ' '
91
+ 'For example, you could choose approach=''symmetric'' and nonlinearity=''tanh'' '
92
+ 'to perform maximum likelihood ICA estimation for supergaussian data. '
93
+ ' '
94
+ 'If the algorithm does not seem to converge, you can use the stabilized '
95
+ 'version of the fixed-point algorithm. To use the stabilized version, '
96
+ 'choose ''on'' from the drop-down menu ''Stabilization''. '
97
+ 'If you have specified a value less than 1 for the parameter ''mu'' from '
98
+ 'the ''Advanced Options'' menu then the ''Stabilization'' drop-down menu is '
99
+ 'not active. This is because if the parameter ''mu'' is less than 1 then the '
100
+ 'program will use the stabilized code. Please see the help for '
101
+ 'Advanced Options for more information about stabilization. '
102
+ ' '
103
+ 'The ADVANCED OPTIONS menu has its own HELP button. '
104
+ ' '
105
+ 'During computations, an INTERRUPT button appears. Clicking the button '
106
+ 'interrupts the computations. '];
107
+
108
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109
+ case 'gui_advc'
110
+
111
+ helptitle='FastICA GUI: Advanced options';
112
+ helptext = [...
113
+ 'Advanced options: '
114
+ ' '
115
+ 'In some cases, it may be desired to improve the statistical '
116
+ 'performance of the algorithm by using a fine-tuning procedure. This '
117
+ 'means that after (initial) convergence, the algorithm is run '
118
+ '(possibly) with a different nonlinearity, and using a smaller step '
119
+ 'size and the stabilized version of the fixed-point algorithm. '
120
+ 'You can specify the nonlinearity that will then be used with the '
121
+ 'parameter ''Finetune''. If you set the the finetuning to ''off'', then the'
122
+ 'fine-tuning won''t be done. '
123
+ ' '
124
+ 'You can also fine-tune the nonlinearities used in the fixed-point '
125
+ 'algorithm. '
126
+ 'The nonlinearities tanh and gauss contain parameters a1 and a2, so '
127
+ 'that the nonlinearities are in fact defined as: '
128
+ '''tanh'' : g(u)=tanh(a1*u) '
129
+ '''gauss'' : g(u)=u*exp(-a2*u^2/2) '
130
+ 'The default values of a1 and a2 are 1, in which case they effectively '
131
+ 'disappear from the definitions. '
132
+ ' '
133
+ 'If the algorithm does not seem to converge, you can use the stabilized'
134
+ 'version of the fixed-point algorithm. There are two ways of doing '
135
+ 'this. The first one is to explicitly specify the value of the step '
136
+ 'size parameter ''mu''. The default value is 1. Choosing a value that '
137
+ 'is smaller than 1 implies that the computations are made using the '
138
+ 'stabilized fixed-point algorithm. The second way to use the stabilized'
139
+ 'version is simpler: choose ''on'' in the drop-down menu ''stabilization'' '
140
+ '(on the main menu page). Then the value of mu will be changed '
141
+ 'automatically during the ICA calculations. If the program senses that '
142
+ 'the algorithm is stuck between two points, it will halve the value of '
143
+ 'mu (.5 * mu) for duration of one round. (This is called a ''stroke.''). '
144
+ 'Also if there is no convergence before half of the maximum number of '
145
+ 'iterations has been reached then the mu will be halved for the rest '
146
+ 'of the rounds. '
147
+ ' '
148
+ 'The parameter ''epsilon'' is used to decide if the algorithm has '
149
+ 'converged. A larger epsilon makes the convergence test less strict. '
150
+ 'Note that if you use finetuning or stabilization, epsilon may need to '
151
+ 'be reduced accordingly. '
152
+ ' '
153
+ '''Maximum number of iterations'' gives the absolute maximum of '
154
+ 'iterations used in the estimation procedure. In the deflation '
155
+ 'approach, this is iterations per component. '
156
+ ' '
157
+ 'You can input the ''Initial state'' of the algorithm, i.e. the initial '
158
+ 'value for A. Choose ''guess'' in the drop-down menu ''Initial state'', '
159
+ 'click on ''Load Initial guess'', and give the name of the variable in '
160
+ 'Matlab workspace that contains the initial value. '
161
+ ' '
162
+ 'In the drop-down menu ''Display mode'' you can choose if the results are'
163
+ 'plotted during computations. You may wish to switch this off '
164
+ 'especially if you have lots of data which takes a long time to plot. '
165
+ '''Iteration between displays'' tells how often the running estimates of '
166
+ 'the independent components are plotted: A value of 1 means after every'
167
+ 'iteration. '
168
+ ' '
169
+ 'If the data vector is very long (more than 10 000 points), it may be '
170
+ 'advisable to use only a part of the data at every iteration. The '
171
+ 'option ''Sample size'' allows you to give the proportion (0-1) of the '
172
+ 'data that is used at every step. The sample is chosen randomly at '
173
+ 'every step. '
174
+ ' '
175
+ 'Click on DEFAULT to return to default values for all advanced options.'
176
+ 'You can make the new values take effect without closing the window by '
177
+ 'clicking APPLY. '];
178
+
179
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180
+ case 'gui_lc_data'
181
+
182
+ helptitle='FastICA GUI: Load data';
183
+ helptext = [...
184
+ 'Input the name of the variable in Matlab workspace that contains the '
185
+ 'data. The data must be in a single matrix, each row (or column) giving'
186
+ 'the values of one signal. If the signals are in column vectors, click '
187
+ 'TRANSPOSE after loading the data to transpose the data matrix. '
188
+ ' '
189
+ 'If the data is in a file, load it to Matlab workspace first. '];
190
+
191
+ case 'gui_lc_guess'
192
+
193
+ helptitle='FastICA GUI: Load guess';
194
+ helptext = [...
195
+ 'Input the name of the variable in Matlab workspace that contains the'
196
+ 'initial value for the mixing matrix A, and click OK. If the initial '
197
+ 'value is in a file, load it to Matlab workspace first. '];
198
+
199
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200
+ case 'gui_sc'
201
+
202
+ helptitle='FastICA GUI: Save results';
203
+ helptext = [...
204
+ 'The results will be saved as variables in Matlab workspace. '
205
+ 'You give a suffix that identifies the variables. For example, if you '
206
+ 'give ''_FASTICA'', the results will be stored in the following variables:'
207
+ ' '
208
+ 'W_FASTICA : estimate of the separating matrix '
209
+ 'A_FASTICA : estimate of the mixing matrix '
210
+ 'IC_FASTICA : estimated independent components (row vectors) '
211
+ ' '
212
+ 'Additional results related to preprocessing: '
213
+ 'D_FASTICA and E_FASTICA : give the eigenvalue decomposition of the '
214
+ ' covariance matrix '
215
+ 'whiteningMatrix_FASTICA : matrix performing whitening and dimension '
216
+ ' reduction '
217
+ 'dewhiteningMatrix_FASTICA : the pseudoinverse of the whitening matrix '
218
+ 'whitesig_FASTICA : whitened (i.e. preprocessed) signals. '];
219
+
220
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
221
+
222
+ end
223
+
224
+ helpwin(helptext, helptitle);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_l.m ADDED
@@ -0,0 +1,180 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_l (x, y)
2
+ %
3
+ % This file is needed by FASTICAG
4
+
5
+ % The load dialog for loading new data
6
+ % and new initial guess.
7
+
8
+ % @(#)$Id: gui_l.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $
9
+
10
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
+ % Global variables
12
+
13
+ % Handle to the window
14
+ global hf_FastICA_Load;
15
+
16
+ % Handles to some of the controls in window
17
+ global he_FastICA_file;
18
+
19
+ % What is the load type of load dialog
20
+ global g_FastICA_loadType;
21
+
22
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
23
+ % Configuration options
24
+ FIGURENAME = 'FastICA: Load';
25
+ FIGURETAG = 'f_FastICALoad';
26
+ FIGURESIZE = [x y 450 150];
27
+
28
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
+ % Check to see if this figure is already open - it should not!
30
+ % Can't have more than one copy - otherwise the global
31
+ % variables and handles can get mixed up.
32
+ if ~isempty(findobj('Tag',FIGURETAG))
33
+ error('Error: load dialog already open!');
34
+ end
35
+
36
+
37
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
+ % Initialize some of the controls' values
39
+
40
+ % What are we loading - who is calling?
41
+ caller = get(gcf, 'CurrentObject');
42
+
43
+ switch get(caller, 'Tag')
44
+ case 'b_LoadData' % Do we load new data...
45
+ loadString = 'Load data from variable in Matlab.';
46
+ g_FastICA_loadType = 'data';
47
+ FIGURENAME = 'FastICA: Load data';
48
+
49
+ case 'b_LoadGuess' % ... or new initial guess?
50
+ loadString = 'Load initial guess for mixing matrix A from variable in Matlab.';
51
+ g_FastICA_loadType = 'guess';
52
+ FIGURENAME = 'FastICA: Load initial guess';
53
+ end
54
+
55
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
+ % Create the figure
57
+ a = figure('Color',[0.8 0.8 0.8], ...
58
+ 'PaperType','a4letter', ...
59
+ 'Name', FIGURENAME, ...
60
+ 'NumberTitle', 'off', ...
61
+ 'Tag', FIGURETAG, ...
62
+ 'Position', FIGURESIZE, ...
63
+ 'MenuBar', 'none');
64
+ set (a, 'Resize', 'off');
65
+
66
+ hf_FastICA_Load = a;
67
+
68
+ set(hf_FastICA_Load, 'HandleVisibility', 'callback');
69
+
70
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
+ % From here on it get's ugly as I have not had time to clean it up
72
+
73
+
74
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
75
+ % Create the frames
76
+ pos_l=2;
77
+ pos_w=FIGURESIZE(3)-4;
78
+ pos_h=FIGURESIZE(4)-4;
79
+ pos_t=2;
80
+ h_f_load_background = uicontrol('Parent',a, ...
81
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
82
+ 'Position',[pos_l pos_t pos_w pos_h], ...
83
+ 'Style','frame', ...
84
+ 'Tag','f_load_background');
85
+
86
+ pos_w=120;
87
+ pos_l=FIGURESIZE(3)-(pos_w+2+2);
88
+ pos_h=FIGURESIZE(4)-2*4;
89
+ pos_t=4;
90
+ h_f_load_side = uicontrol('Parent',a, ...
91
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
92
+ 'Position',[pos_l pos_t pos_w pos_h], ...
93
+ 'Style','frame', ...
94
+ 'Tag','f_load_side');
95
+
96
+ pos_l=4;
97
+ pos_w=FIGURESIZE(3)-8-pos_w-2;
98
+ pos_h=FIGURESIZE(4)-8;
99
+ pos_t=4;
100
+ h_f_load = uicontrol('Parent',a, ...
101
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
102
+ 'Position',[pos_l pos_t pos_w pos_h], ...
103
+ 'Style','frame', ...
104
+ 'Tag','f_load');
105
+
106
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107
+ % Controls in f_load
108
+ bgc = get(h_f_load, 'BackgroundColor');
109
+
110
+ pos_w=230;
111
+
112
+ pos_frame=get(h_f_load, 'Position');
113
+ pos_h = 40;
114
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
115
+ pos_l = pos_frame(1) + 6;
116
+
117
+ b = uicontrol('Parent',a, ...
118
+ 'BackgroundColor',bgc, ...
119
+ 'HorizontalAlignment','left', ...
120
+ 'Position',[pos_l pos_t pos_w pos_h], ...
121
+ 'String',loadString, ...
122
+ 'Style','text', ...
123
+ 'Tag','t_93');
124
+
125
+ pos_h = 20;
126
+ pos_t = pos_t - pos_h - 10;
127
+ pos_l = pos_frame(1) + 6;
128
+
129
+ b = uicontrol('Parent',a, ...
130
+ 'BackgroundColor',bgc, ...
131
+ 'HorizontalAlignment','left', ...
132
+ 'Position',[pos_l pos_t pos_w pos_h], ...
133
+ 'String','Name of the variable:', ...
134
+ 'Style','text', ...
135
+ 'Tag','t_92');
136
+
137
+ pos_w = 200;
138
+ pos_l = pos_l + 30;
139
+ pos_t = pos_t - pos_h;
140
+ he_FastICA_file = uicontrol('Parent',a, ...
141
+ 'BackgroundColor',[1 1 1], ...
142
+ 'HorizontalAlignment','left', ...
143
+ 'Position',[pos_l pos_t pos_w pos_h], ...
144
+ 'String','', ...
145
+ 'Style','edit', ...
146
+ 'Tag','e_file');
147
+
148
+
149
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
+ % Controls in f_load_side
151
+ pos_vspace = 6;
152
+ pos_hspace = 10;
153
+ pos_frame = get(h_f_load_side, 'Position');
154
+ pos_w = 100;
155
+ pos_h = 30;
156
+ pos_l = pos_frame(1) + pos_hspace;
157
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace;
158
+ b = uicontrol('Parent',a, ...
159
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
160
+ 'Callback','gui_lc Load', ...
161
+ 'Position',[pos_l pos_t pos_w pos_h], ...
162
+ 'String','Load', ...
163
+ 'Tag','b_lLoad');
164
+
165
+ pos_t=pos_t-pos_h-pos_vspace;
166
+ b = uicontrol('Parent',a, ...
167
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
168
+ 'Callback','gui_lc Cancel', ...
169
+ 'Position',[pos_l pos_t pos_w pos_h], ...
170
+ 'String','Cancel', ...
171
+ 'Tag','b_lCancel');
172
+
173
+ pos_t = pos_frame(2) + pos_vspace;
174
+ b = uicontrol('Parent',a, ...
175
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
176
+ 'Callback','gui_lc Help', ...
177
+ 'Position',[pos_l pos_t pos_w pos_h], ...
178
+ 'String','Help', ...
179
+ 'Tag','b_lHelp');
180
+
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_lc.m ADDED
@@ -0,0 +1,112 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_lc (action)
2
+ %
3
+ % This file is used by FASTICAG
4
+
5
+ % This file holds the callbacks for load-dialog
6
+
7
+ % @(#)$Id: gui_lc.m,v 1.4 2003/09/11 12:01:19 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the window
13
+ global hf_FastICA_Load;
14
+
15
+ % Handles to some of the controls in window
16
+ global he_FastICA_file;
17
+
18
+ % Needed handles from the main figure
19
+ global ht_FastICA_mixedStatus;
20
+
21
+ % Needed handles from the advOpt figure
22
+ global hb_FastICA_initGuess;
23
+ global ht_FastICA_initGuess;
24
+ global hpm_FastICA_initState;
25
+
26
+ % The needed main variables
27
+ global g_FastICA_mixedsig;
28
+ global g_FastICA_mixedmean;
29
+
30
+ % What is the load type of load dialog
31
+ global g_FastICA_loadType;
32
+
33
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
+ % This should not take long...
35
+ watchonInFigure = watchon;
36
+
37
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
38
+ switch action
39
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40
+ case 'Load'
41
+
42
+ varName = get(he_FastICA_file, 'String'); % The name of the variable to be loaded
43
+ command=['evalin(''base'',''assignin(''''caller'''',''''data'''',' varName ')'')'];
44
+ eval(command,'fprintf(''Variable not found in MATLAB workspace, data not loaded!\n'');data=[];'); % Variable is copyed to 'data'
45
+ if length (size (data)) > 2,
46
+ fprintf (['Input data can not have more than two dimensions, data' ...
47
+ ' not loaded.\n']);
48
+ data = [];
49
+ end
50
+
51
+ if any (any (isnan (data))),
52
+ fprintf ('Input data contains NaN''s, data not loaded.\n');
53
+ data = [];
54
+ end
55
+
56
+
57
+ if isempty(data) % if there was no name given...
58
+ watchoff (watchonInFigure);
59
+ % There used to be a 'break' statement here, but it resulted in
60
+ % errors in more recent version of Matlab -- jarmo
61
+ return;
62
+ end
63
+ switch g_FastICA_loadType
64
+ case 'data' % New data
65
+ g_FastICA_mixedsig = data;
66
+ if ~isa (g_FastICA_mixedsig, 'double')
67
+ fprintf ('Warning: converting input data into regular (double) precision.\n');
68
+ g_FastICA_mixedsig = double (g_FastICA_mixedsig);
69
+ end
70
+
71
+ set(ht_FastICA_mixedStatus, 'String', '');
72
+ g_FastICA_mixedmean = []; % New data - so that means ...
73
+ gui_cb NewData;
74
+
75
+ case 'guess' % New initial guess
76
+ set(hb_FastICA_initGuess, 'UserData', data); % Since we loaded new initial
77
+ set(ht_FastICA_initGuess, 'String', 'Loaded'); % guess, we wan't to use it too
78
+ set(hpm_FastICA_initState, 'Value', 2); % ... set initState to 'guess'
79
+ end
80
+
81
+ close(hf_FastICA_Load); % close the dialog
82
+
83
+ % Use return to avoid reaching the watchoff statement at the end
84
+ % (There used to be a 'break' statement here, but it resulted in
85
+ % errors in more recent version of Matlab -- jarmo)
86
+ return;
87
+
88
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
89
+ case 'Cancel'
90
+
91
+ close(hf_FastICA_Load); % do nothing just exit
92
+
93
+ % Use return to avoid reaching the watchoff statement at the end
94
+ % (There used to be a 'break' statement here, but it resulted in
95
+ % errors in more recent version of Matlab -- jarmo)
96
+ return;
97
+
98
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
99
+ case 'Help'
100
+
101
+ % Which help do we show?
102
+ switch g_FastICA_loadType
103
+ case 'data'
104
+ gui_help('gui_lc_data');
105
+ case 'guess'
106
+ gui_help('gui_lc_guess');
107
+ end
108
+
109
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
110
+ end % switch
111
+
112
+ watchoff (watchonInFigure);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_s.m ADDED
@@ -0,0 +1,177 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_s (x, y)
2
+ %
3
+ % This file is used by FASTICAG
4
+
5
+ % The save dialog for saving the results
6
+
7
+ % @(#)$Id: gui_s.m,v 1.4 2004/07/27 13:09:26 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the window
13
+ global hf_FastICA_Save;
14
+
15
+ % Handles to some of the controls in window
16
+ global he_FastICA_suffix;
17
+
18
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
19
+ % Configuration options
20
+ FIGURENAME = 'FastICA: Save results';
21
+ FIGURETAG = 'f_FastICASave';
22
+ FIGURESIZE = [x y 450 150];
23
+
24
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
25
+ % Check to see if this figure is already open - it should not!
26
+ % Can't have more than one copy - otherwise the global
27
+ % variables and handles can get mixed up.
28
+ if ~isempty(findobj('Tag',FIGURETAG))
29
+ error('Error: load dialog already open!');
30
+ end
31
+
32
+
33
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34
+ % Initialize some of the controls' values
35
+
36
+ saveString = 'Save results as variables in MATLAB workspace.';
37
+ promptString = 'Suffix to identify the results:';
38
+ helpString = 'If you give e.g. ''_FastICA'', the variables will be called A_FastICA, W_FastICA, etc.';
39
+
40
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41
+ % Create the figure
42
+ a = figure('Color',[0.8 0.8 0.8], ...
43
+ 'PaperType','a4letter', ...
44
+ 'Name', FIGURENAME, ...
45
+ 'NumberTitle', 'off', ...
46
+ 'Tag', FIGURETAG, ...
47
+ 'Position', FIGURESIZE, ...
48
+ 'MenuBar', 'none');
49
+ set (a, 'Resize', 'off');
50
+
51
+ hf_FastICA_Save = a;
52
+
53
+ set(hf_FastICA_Save, 'HandleVisibility', 'callback');
54
+
55
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
+ % From here on it get's ugly as I have not had time to clean it up
57
+
58
+
59
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
60
+ % Create the frames
61
+ pos_l=2;
62
+ pos_w=FIGURESIZE(3)-4;
63
+ pos_h=FIGURESIZE(4)-4;
64
+ pos_t=2;
65
+ h_f_save_background = uicontrol('Parent',a, ...
66
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
67
+ 'Position',[pos_l pos_t pos_w pos_h], ...
68
+ 'Style','frame', ...
69
+ 'Tag','f_save_background');
70
+
71
+ pos_w=120;
72
+ pos_l=FIGURESIZE(3)-(pos_w+2+2);
73
+ pos_h=FIGURESIZE(4)-2*4;
74
+ pos_t=4;
75
+ h_f_save_side = uicontrol('Parent',a, ...
76
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
77
+ 'Position',[pos_l pos_t pos_w pos_h], ...
78
+ 'Style','frame', ...
79
+ 'Tag','f_save_side');
80
+
81
+ pos_l=4;
82
+ pos_w=FIGURESIZE(3)-8-pos_w-2;
83
+ pos_h=FIGURESIZE(4)-8;
84
+ pos_t=4;
85
+ h_f_save = uicontrol('Parent',a, ...
86
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
87
+ 'Position',[pos_l pos_t pos_w pos_h], ...
88
+ 'Style','frame', ...
89
+ 'Tag','f_save');
90
+
91
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92
+ % Controls in f_save
93
+ bgc = get(h_f_save, 'BackgroundColor');
94
+
95
+ pos_w=230;
96
+
97
+ pos_frame=get(h_f_save, 'Position');
98
+ pos_h = 40;
99
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - 6;
100
+ pos_l = pos_frame(1) + 6;
101
+
102
+ b = uicontrol('Parent',a, ...
103
+ 'BackgroundColor',bgc, ...
104
+ 'HorizontalAlignment','left', ...
105
+ 'Position',[pos_l pos_t pos_w pos_h], ...
106
+ 'String',saveString, ...
107
+ 'Style','text', ...
108
+ 'Tag','t_93');
109
+
110
+ pos_h = 20;
111
+ pos_t = pos_t - pos_h - 10;
112
+ pos_l = pos_frame(1) + 6;
113
+
114
+ b = uicontrol('Parent',a, ...
115
+ 'BackgroundColor',bgc, ...
116
+ 'HorizontalAlignment','left', ...
117
+ 'Position',[pos_l pos_t pos_w pos_h], ...
118
+ 'String',promptString, ...
119
+ 'Style','text', ...
120
+ 'Tag','t_92');
121
+
122
+ pos_w = 200;
123
+ pos_l = pos_l + 30;
124
+ pos_t = pos_t - pos_h;
125
+ he_FastICA_suffix = uicontrol('Parent',a, ...
126
+ 'BackgroundColor',[1 1 1], ...
127
+ 'HorizontalAlignment','left', ...
128
+ 'Position',[pos_l pos_t pos_w pos_h], ...
129
+ 'String','', ...
130
+ 'Style','edit', ...
131
+ 'Tag','e_suffix');
132
+
133
+ pos_w = pos_frame(3) - 12;
134
+ pos_h = 30;
135
+ pos_t = pos_frame(2) + 6;
136
+ pos_l = pos_frame(1) + 6;
137
+
138
+ b = uicontrol('Parent',a, ...
139
+ 'BackgroundColor',bgc, ...
140
+ 'HorizontalAlignment','left', ...
141
+ 'Position',[pos_l pos_t pos_w pos_h], ...
142
+ 'String',helpString, ...
143
+ 'Style','text', ...
144
+ 'Tag','t_97');
145
+
146
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
147
+ % Controls in f_save_side
148
+ pos_vspace = 6;
149
+ pos_hspace = 10;
150
+ pos_frame = get(h_f_save_side, 'Position');
151
+ pos_w = 100;
152
+ pos_h = 30;
153
+ pos_l = pos_frame(1) + pos_hspace;
154
+ pos_t = pos_frame(2) + pos_frame(4) - pos_h - pos_vspace;
155
+ b = uicontrol('Parent',a, ...
156
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
157
+ 'Callback','gui_sc Save', ...
158
+ 'Position',[pos_l pos_t pos_w pos_h], ...
159
+ 'String','Save', ...
160
+ 'Tag','b_sSave');
161
+
162
+ pos_t=pos_t-pos_h-pos_vspace;
163
+ b = uicontrol('Parent',a, ...
164
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
165
+ 'Callback','gui_sc Cancel', ...
166
+ 'Position',[pos_l pos_t pos_w pos_h], ...
167
+ 'String','Cancel', ...
168
+ 'Tag','b_sCancel');
169
+
170
+ pos_t = pos_frame(2) + pos_vspace;
171
+ b = uicontrol('Parent',a, ...
172
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
173
+ 'Callback','gui_sc Help', ...
174
+ 'Position',[pos_l pos_t pos_w pos_h], ...
175
+ 'String','Help', ...
176
+ 'Tag','b_sHelp');
177
+
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/gui_sc.m ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function gui_sc (action)
2
+ %
3
+ % This file is used by FASTICAG
4
+
5
+ % This file holds the callbacks for save-dialog
6
+
7
+ % @(#)$Id: gui_sc.m,v 1.3 2003/09/08 11:28:59 jarmo Exp $
8
+
9
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10
+ % Global variables
11
+
12
+ % Handle to the window
13
+ global hf_FastICA_Save;
14
+
15
+ % Handles to some of the controls in window
16
+ global he_FastICA_suffix;
17
+
18
+ % The needed main variables
19
+ global g_FastICA_ica_sig;
20
+ global g_FastICA_ica_A;
21
+ global g_FastICA_ica_W;
22
+ global g_FastICA_white_sig;
23
+ global g_FastICA_white_wm;
24
+ global g_FastICA_white_dwm;
25
+ global g_FastICA_pca_E;
26
+ global g_FastICA_pca_D;
27
+
28
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
+ % This should not take long...
30
+ watchonInFigure = watchon;
31
+
32
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33
+ switch action
34
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
+ case 'Save'
36
+
37
+ suffix = deblank(get(he_FastICA_suffix, 'String')); % The suffix for the variables
38
+
39
+ fprintf('Saving results in variables in Matlab workspace.\n');
40
+ assignin('base',['IC' suffix],g_FastICA_ica_sig);
41
+ assignin('base',['A' suffix],g_FastICA_ica_A);
42
+ assignin('base',['W' suffix],g_FastICA_ica_W);
43
+ assignin('base',['whitesig' suffix],g_FastICA_white_sig);
44
+ assignin('base',['whiteningMatrix' suffix],g_FastICA_white_wm);
45
+ assignin('base',['dewhiteningMatrix' suffix],g_FastICA_white_dwm);
46
+ assignin('base',['E' suffix],g_FastICA_pca_E);
47
+ assignin('base',['D' suffix],g_FastICA_pca_D);
48
+
49
+ close(hf_FastICA_Save); % close the dialog
50
+
51
+ % Use return to avoid reaching the watchoff statement at the end
52
+ % (There used to be a 'break' statement here, but it resulted in
53
+ % errors in more recent version of Matlab -- jarmo)
54
+ return;
55
+
56
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
57
+ case 'Cancel'
58
+
59
+ close(hf_FastICA_Save); % do nothing just exit
60
+
61
+ % Use return to avoid reaching the watchoff statement at the end
62
+ % (There used to be a 'break' statement here, but it resulted in
63
+ % errors in more recent version of Matlab -- jarmo)
64
+ return;
65
+
66
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67
+ case 'Help'
68
+
69
+ gui_help('gui_sc');
70
+
71
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
72
+ end % switch
73
+
74
+ watchoff (watchonInFigure);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/icaplot.m ADDED
@@ -0,0 +1,397 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function icaplot(mode, varargin);
2
+ %ICAPLOT - plot signals in various ways
3
+ %
4
+ % ICAPLOT is mainly for plottinf and comparing the mixed signals and
5
+ % separated ica-signals.
6
+ %
7
+ % ICAPLOT has many different modes. The first parameter of the function
8
+ % defines the mode. Other parameters and their order depends on the
9
+ % mode. The explanation for the more common parameters is in the end.
10
+ %
11
+ % Classic
12
+ % icaplot('classic', s1, n1, range, xrange, titlestr)
13
+ %
14
+ % Plots the signals in the same manner as the FASTICA and FASTICAG
15
+ % programs do. All the signals are plotted in their own axis.
16
+ %
17
+ % Complot
18
+ % icaplot('complot', s1, n1, range, xrange, titlestr)
19
+ %
20
+ % The signals are plotted on the same axis. This is good for
21
+ % visualization of the shape of the signals. The scale of the signals
22
+ % has been altered so that they all fit nicely.
23
+ %
24
+ % Histogram
25
+ % icaplot('histogram', s1, n1, range, bins, style)
26
+ %
27
+ % The histogram of the signals is plotted. The number of bins can be
28
+ % specified with 'bins'-parameter. The style for the histograms can
29
+ % be either 'bar' (default) of 'line'.
30
+ %
31
+ % Scatter
32
+ % icaplot('scatter', s1, n1, s2, n2, range, titlestr, s1label,
33
+ % s2label, markerstr)
34
+ %
35
+ % A scatterplot is plotted so that the signal 1 is the 'X'-variable
36
+ % and the signal 2 is the 'Y'-variable. The 'markerstr' can be used
37
+ % to specify the maker used in the plot. The format for 'markerstr'
38
+ % is the same as for Matlab's PLOT.
39
+ %
40
+ % Compare
41
+ % icaplot('compare', s1, n1, s2, n2, range, xrange, titlestr,
42
+ % s1label, s2label)
43
+ %
44
+ % This for for comparing two signals. The main used in this context
45
+ % would probably be to see how well the separated ICA-signals explain
46
+ % the observed mixed signals. The s2 signals are first scaled with
47
+ % REGRESS function.
48
+ %
49
+ % Compare - Sum
50
+ % icaplot('sum', s1, n1, s2, n2, range, xrange, titlestr, s1label,
51
+ % s2label)
52
+ %
53
+ % The same as Compare, but this time the signals in s2 (specified by
54
+ % n2) are summed together.
55
+ %
56
+ % Compare - Sumerror
57
+ % icaplot('sumerror', s1, n1, s2, n2, range, xrange, titlestr,
58
+ % s1label, s2label)
59
+ %
60
+ % The same as Compare - Sum, but also the 'error' between the signal
61
+ % 1 and the summed IC's is plotted.
62
+ %
63
+ %
64
+ % More common parameters
65
+ % The signals to be plotted are in matrices s1 and s2. The n1 and n2
66
+ % are used to tell the index of the signal or signals to be plotted
67
+ % from s1 or s2. If n1 or n2 has a value of 0, then all the signals
68
+ % from corresponding matrix will be plotted. The values for n1 and n2
69
+ % can also be vectors (like: [1 3 4]) In some casee if there are more
70
+ % than 1 signal to be plotted from s1 or s2 then the plot will
71
+ % contain as many subplots as are needed.
72
+ %
73
+ % The range of the signals to be plotted can be limited with
74
+ % 'range'-parameter. It's value is a vector ( 10000:15000 ). If range
75
+ % is 0, then the whole range will be plotted.
76
+ %
77
+ % The 'xrange' is used to specify only the labels used on the
78
+ % x-axis. The value of 'xrange' is a vector containing the x-values
79
+ % for the plots or [start end] for begin and end of the range
80
+ % ( 10000:15000 or [10 15] ). If xrange is 0, then value of range
81
+ % will be used for x-labels.
82
+ %
83
+ % You can give a title for the plot with 'titlestr'. Also the
84
+ % 's1label' and 's2label' are used to give more meaningfull label for
85
+ % the signals.
86
+ %
87
+ % Lastly, you can omit some of the arguments from the and. You will
88
+ % have to give values for the signal matrices (s1, s2) and the
89
+ % indexes (n1, n2)
90
+
91
+ % @(#)$Id: icaplot.m,v 1.2 2003/04/05 14:23:58 jarmo Exp $
92
+
93
+ switch mode
94
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
+ % 'dispsig' is to replace the old DISPSIG
96
+ % '' & 'classic' are just another names - '' quite short one :-)
97
+ case {'', 'classic', 'dispsig'}
98
+ % icaplot(mode, s1, n1, range, xrange, titlestr)
99
+ if length(varargin) < 1, error('Not enough arguments.'); end
100
+ if length(varargin) < 5, titlestr = '';else titlestr = varargin{5}; end
101
+ if length(varargin) < 4, xrange = 0;else xrange = varargin{4}; end
102
+ if length(varargin) < 3, range = 0;else range = varargin{3}; end
103
+ if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end
104
+ s1 = varargin{1};
105
+ range=chkrange(range, s1);
106
+ xrange=chkxrange(xrange, range);
107
+ n1=chkn(n1, s1);
108
+
109
+ clf;
110
+
111
+ numSignals = size(n1, 2);
112
+ for i = 1:numSignals,
113
+ subplot(numSignals, 1, i);
114
+ plot(xrange, s1(n1(i), range));
115
+ end
116
+ subplot(numSignals,1, 1);
117
+ if (~isempty(titlestr))
118
+ title(titlestr);
119
+ end
120
+
121
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
+ case 'complot'
123
+ % icaplot(mode, s1, n1, range, xrange, titlestr)
124
+ if length(varargin) < 1, error('Not enough arguments.'); end
125
+ if length(varargin) < 5, titlestr = '';else titlestr = varargin{5}; end
126
+ if length(varargin) < 4, xrange = 0;else xrange = varargin{4}; end
127
+ if length(varargin) < 3, range = 0;else range = varargin{3}; end
128
+ if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end
129
+ s1 = remmean(varargin{1});
130
+ range=chkrange(range, s1);
131
+ xrange=chkxrange(xrange, range);
132
+ n1=chkn(n1, s1);
133
+
134
+ for i = 1:size(n1, 2)
135
+ S1(i, :) = s1(n1(i), range);
136
+ end
137
+
138
+ alpha = mean(max(S1')-min(S1'));
139
+ for i = 1:size(n1,2)
140
+ S2(i,:) = S1(i,:) - alpha*(i-1)*ones(size(S1(1,:)));
141
+ end
142
+
143
+ plot(xrange, S2');
144
+ axis([min(xrange) max(xrange) min(min(S2)) max(max(S2)) ]);
145
+
146
+ set(gca,'YTick',(-size(S1,1)+1)*alpha:alpha:0);
147
+ set(gca,'YTicklabel',fliplr(n1));
148
+
149
+ if (~isempty(titlestr))
150
+ title(titlestr);
151
+ end
152
+
153
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
154
+ case 'histogram'
155
+ % icaplot(mode, s1, n1, range, bins, style)
156
+ if length(varargin) < 1, error('Not enough arguments.'); end
157
+ if length(varargin) < 5, style = 'bar';else style = varargin{5}; end
158
+ if length(varargin) < 4, bins = 10;else bins = varargin{4}; end
159
+ if length(varargin) < 3, range = 0;else range = varargin{3}; end
160
+ if length(varargin) < 2, n1 = 0;else n1 = varargin{2}; end
161
+ s1 = varargin{1};
162
+ range = chkrange(range, s1);
163
+ n1 = chkn(n1, s1);
164
+
165
+ numSignals = size(n1, 2);
166
+ rows = floor(sqrt(numSignals));
167
+ columns = ceil(sqrt(numSignals));
168
+ while (rows * columns < numSignals)
169
+ columns = columns + 1;
170
+ end
171
+
172
+ switch style
173
+ case {'', 'bar'}
174
+ for i = 1:numSignals,
175
+ subplot(rows, columns, i);
176
+ hist(s1(n1(i), range), bins);
177
+ title(int2str(n1(i)));
178
+ drawnow;
179
+ end
180
+
181
+ case 'line'
182
+ for i = 1:numSignals,
183
+ subplot(rows, columns, i);
184
+ [Y, X]=hist(s1(n1(i), range), bins);
185
+ plot(X, Y);
186
+ title(int2str(n1(i)));
187
+ drawnow;
188
+ end
189
+ otherwise
190
+ fprintf('Unknown style.\n')
191
+ end
192
+
193
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194
+ case 'scatter'
195
+ % icaplot(mode, s1, n1, s2, n2, range, titlestr, xlabelstr, ylabelstr, markerstr)
196
+ if length(varargin) < 4, error('Not enough arguments.'); end
197
+ if length(varargin) < 9, markerstr = '.';else markerstr = varargin{9}; end
198
+ if length(varargin) < 8, ylabelstr = 'Signal 2';else ylabelstr = varargin{8}; end
199
+ if length(varargin) < 7, xlabelstr = 'Signal 1';else xlabelstr = varargin{7}; end
200
+ if length(varargin) < 6, titlestr = '';else titlestr = varargin{6}; end
201
+ if length(varargin) < 5, range = 0;else range = varargin{5}; end
202
+ n2 = varargin{4};
203
+ s2 = varargin{3};
204
+ n1 = varargin{2};
205
+ s1 = varargin{1};
206
+ range = chkrange(range, s1);
207
+ n1 = chkn(n1, s1);
208
+ n2 = chkn(n2, s2);
209
+
210
+ rows = size(n1, 2);
211
+ columns = size(n2, 2);
212
+ for r = 1:rows
213
+ for c = 1:columns
214
+ subplot(rows, columns, (r-1)*columns + c);
215
+ plot(s1(n1(r), range),s2(n2(c), range),markerstr);
216
+ if (~isempty(titlestr))
217
+ title(titlestr);
218
+ end
219
+ if (rows*columns == 1)
220
+ xlabel(xlabelstr);
221
+ ylabel(ylabelstr);
222
+ else
223
+ xlabel([xlabelstr ' (' int2str(n1(r)) ')']);
224
+ ylabel([ylabelstr ' (' int2str(n2(c)) ')']);
225
+ end
226
+ drawnow;
227
+ end
228
+ end
229
+
230
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
231
+ case {'compare', 'sum', 'sumerror'}
232
+ % icaplot(mode, s1, n1, s2, n2, range, xrange, titlestr, s1label, s2label)
233
+ if length(varargin) < 4, error('Not enough arguments.'); end
234
+ if length(varargin) < 9, s2label = 'IC';else s2label = varargin{9}; end
235
+ if length(varargin) < 8, s1label = 'Mix';else s1label = varargin{8}; end
236
+ if length(varargin) < 7, titlestr = '';else titlestr = varargin{7}; end
237
+ if length(varargin) < 6, xrange = 0;else xrange = varargin{6}; end
238
+ if length(varargin) < 5, range = 0;else range = varargin{5}; end
239
+ s1 = varargin{1};
240
+ n1 = varargin{2};
241
+ s2 = varargin{3};
242
+ n2 = varargin{4};
243
+ range = chkrange(range, s1);
244
+ xrange = chkxrange(xrange, range);
245
+ n1 = chkn(n1, s1);
246
+ n2 = chkn(n2, s2);
247
+
248
+ numSignals = size(n1, 2);
249
+ if (numSignals > 1)
250
+ externalLegend = 1;
251
+ else
252
+ externalLegend = 0;
253
+ end
254
+
255
+ rows = floor(sqrt(numSignals+externalLegend));
256
+ columns = ceil(sqrt(numSignals+externalLegend));
257
+ while (rows * columns < (numSignals+externalLegend))
258
+ columns = columns + 1;
259
+ end
260
+
261
+ clf;
262
+
263
+ for j = 1:numSignals
264
+ subplot(rows, columns, j);
265
+ switch mode
266
+ case 'compare'
267
+ plotcompare(s1, n1(j), s2,n2, range, xrange);
268
+ [legendtext,legendstyle]=legendcompare(n1(j),n2,s1label,s2label,externalLegend);
269
+ case 'sum'
270
+ plotsum(s1, n1(j), s2,n2, range, xrange);
271
+ [legendtext,legendstyle]=legendsum(n1(j),n2,s1label,s2label,externalLegend);
272
+ case 'sumerror'
273
+ plotsumerror(s1, n1(j), s2,n2, range, xrange);
274
+ [legendtext,legendstyle]=legendsumerror(n1(j),n2,s1label,s2label,externalLegend);
275
+ end
276
+
277
+ if externalLegend
278
+ title([titlestr ' (' s1label ' ' int2str(n1(j)) ')']);
279
+ else
280
+ legend(char(legendtext));
281
+ if (~isempty(titlestr))
282
+ title(titlestr);
283
+ end
284
+ end
285
+ end
286
+
287
+ if (externalLegend)
288
+ subplot(rows, columns, numSignals+1);
289
+ legendsize = size(legendtext, 2);
290
+ hold on;
291
+ for i=1:legendsize
292
+ plot([0 1],[legendsize-i legendsize-i], char(legendstyle(i)));
293
+ text(1.5, legendsize-i, char(legendtext(i)));
294
+ end
295
+ hold off;
296
+ axis([0 6 -1 legendsize]);
297
+ axis off;
298
+ end
299
+
300
+
301
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
302
+ end
303
+
304
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
305
+ function plotcompare(s1, n1, s2, n2, range, xrange);
306
+ style=getStyles;
307
+ K = regress(s1(n1,:)',s2');
308
+ plot(xrange, s1(n1,range), char(style(1)));
309
+ hold on
310
+ for i=1:size(n2,2)
311
+ plotstyle=char(style(i+1));
312
+ plot(xrange, K(n2(i))*s2(n2(i),range), plotstyle);
313
+ end
314
+ hold off
315
+
316
+ function [legendText, legendStyle]=legendcompare(n1, n2, s1l, s2l, externalLegend);
317
+ style=getStyles;
318
+ if (externalLegend)
319
+ legendText(1)={[s1l ' (see the titles)']};
320
+ else
321
+ legendText(1)={[s1l ' ', int2str(n1)]};
322
+ end
323
+ legendStyle(1)=style(1);
324
+ for i=1:size(n2, 2)
325
+ legendText(i+1) = {[s2l ' ' int2str(n2(i))]};
326
+ legendStyle(i+1) = style(i+1);
327
+ end
328
+
329
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
330
+ function plotsum(s1, n1, s2, n2, range, xrange);
331
+ K = diag(regress(s1(n1,:)',s2'));
332
+ sigsum = sum(K(:,n2)*s2(n2,:));
333
+ plot(xrange, s1(n1, range),'k-', ...
334
+ xrange, sigsum(range), 'b-');
335
+
336
+ function [legendText, legendStyle]=legendsum(n1, n2, s1l, s2l, externalLegend);
337
+ if (externalLegend)
338
+ legendText(1)={[s1l ' (see the titles)']};
339
+ else
340
+ legendText(1)={[s1l ' ', int2str(n1)]};
341
+ end
342
+ legendText(2)={['Sum of ' s2l ': ', int2str(n2)]};
343
+ legendStyle={'k-';'b-'};
344
+
345
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
346
+ function plotsumerror(s1, n1, s2, n2, range, xrange);
347
+ K = diag(regress(s1(n1,:)',s2'));
348
+ sigsum = sum(K(:,n2)*s2(n2,:));
349
+ plot(xrange, s1(n1, range),'k-', ...
350
+ xrange, sigsum(range), 'b-', ...
351
+ xrange, s1(n1, range)-sigsum(range), 'r-');
352
+
353
+ function [legendText, legendStyle]=legendsumerror(n1, n2, s1l, s2l, externalLegend);
354
+ if (externalLegend)
355
+ legendText(1)={[s1l ' (see the titles)']};
356
+ else
357
+ legendText(1)={[s1l ' ', int2str(n1)]};
358
+ end
359
+ legendText(2)={['Sum of ' s2l ': ', int2str(n2)]};
360
+ legendText(3)={'"Error"'};
361
+ legendStyle={'k-';'b-';'r-'};
362
+
363
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364
+ function style=getStyles;
365
+ color = {'k','r','g','b','m','c','y'};
366
+ line = {'-',':','-.','--'};
367
+ for i = 0:size(line,2)-1
368
+ for j = 1:size(color, 2)
369
+ style(j + i*size(color, 2)) = strcat(color(j), line(i+1));
370
+ end
371
+ end
372
+
373
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
374
+ function range=chkrange(r, s)
375
+ if r == 0
376
+ range = 1:size(s, 2);
377
+ else
378
+ range = r;
379
+ end
380
+
381
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382
+ function xrange=chkxrange(xr,r);
383
+ if xr == 0
384
+ xrange = r;
385
+ elseif size(xr, 2) == 2
386
+ xrange = xr(1):(xr(2)-xr(1))/(size(r,2)-1):xr(2);
387
+ elseif size(xr, 2)~=size(r, 2)
388
+ error('Xrange and range have different sizes.');
389
+ else
390
+ xrange = xr;
391
+ end
392
+
393
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
394
+ function n=chkn(n,s)
395
+ if n == 0
396
+ n = 1:size(s, 1);
397
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/pcamat.m ADDED
@@ -0,0 +1,358 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [E, D] = pcamat(vectors, firstEig, lastEig, s_interactive, ...
2
+ s_verbose);
3
+ %PCAMAT - Calculates the pca for data
4
+ %
5
+ % [E, D] = pcamat(vectors, firstEig, lastEig, ...
6
+ % interactive, verbose);
7
+ %
8
+ % Calculates the PCA matrices for given data (row) vectors. Returns
9
+ % the eigenvector (E) and diagonal eigenvalue (D) matrices containing the
10
+ % selected subspaces. Dimensionality reduction is controlled with
11
+ % the parameters 'firstEig' and 'lastEig' - but it can also be done
12
+ % interactively by setting parameter 'interactive' to 'on' or 'gui'.
13
+ %
14
+ % ARGUMENTS
15
+ %
16
+ % vectors Data in row vectors.
17
+ % firstEig Index of the largest eigenvalue to keep.
18
+ % Default is 1.
19
+ % lastEig Index of the smallest eigenvalue to keep.
20
+ % Default is equal to dimension of vectors.
21
+ % interactive Specify eigenvalues to keep interactively. Note that if
22
+ % you set 'interactive' to 'on' or 'gui' then the values
23
+ % for 'firstEig' and 'lastEig' will be ignored, but they
24
+ % still have to be entered. If the value is 'gui' then the
25
+ % same graphical user interface as in FASTICAG will be
26
+ % used. Default is 'off'.
27
+ % verbose Default is 'on'.
28
+ %
29
+ %
30
+ % EXAMPLE
31
+ % [E, D] = pcamat(vectors);
32
+ %
33
+ % Note
34
+ % The eigenvalues and eigenvectors returned by PCAMAT are not sorted.
35
+ %
36
+ % This function is needed by FASTICA and FASTICAG
37
+
38
+ % For historical reasons this version does not sort the eigenvalues or
39
+ % the eigen vectors in any ways. Therefore neither does the FASTICA or
40
+ % FASTICAG. Generally it seams that the components returned from
41
+ % whitening is almost in reversed order. (That means, they usually are,
42
+ % but sometime they are not - depends on the EIG-command of matlab.)
43
+
44
+ % @(#)$Id: pcamat.m,v 1.5 2003/12/15 18:24:32 jarmo Exp $
45
+
46
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
47
+ % Default values:
48
+ if nargin < 5, s_verbose = 'on'; end
49
+ if nargin < 4, s_interactive = 'off'; end
50
+ if nargin < 3, lastEig = size(vectors, 1); end
51
+ if nargin < 2, firstEig = 1; end
52
+
53
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
54
+ % Check the optional parameters;
55
+ switch lower(s_verbose)
56
+ case 'on'
57
+ b_verbose = 1;
58
+ case 'off'
59
+ b_verbose = 0;
60
+ otherwise
61
+ error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose));
62
+ end
63
+
64
+ switch lower(s_interactive)
65
+ case 'on'
66
+ b_interactive = 1;
67
+ case 'off'
68
+ b_interactive = 0;
69
+ case 'gui'
70
+ b_interactive = 2;
71
+ otherwise
72
+ error(sprintf('Illegal value [ %s ] for parameter: ''interactive''\n', ...
73
+ s_interactive));
74
+ end
75
+
76
+ oldDimension = size (vectors, 1);
77
+ if ~(b_interactive)
78
+ if lastEig < 1 | lastEig > oldDimension
79
+ error(sprintf('Illegal value [ %d ] for parameter: ''lastEig''\n', lastEig));
80
+ end
81
+ if firstEig < 1 | firstEig > lastEig
82
+ error(sprintf('Illegal value [ %d ] for parameter: ''firstEig''\n', firstEig));
83
+ end
84
+ end
85
+
86
+
87
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
88
+ % Calculate PCA
89
+
90
+ % Calculate the covariance matrix.
91
+ if b_verbose, fprintf ('Calculating covariance...\n'); end
92
+ covarianceMatrix = cov(vectors', 1);
93
+
94
+ % Calculate the eigenvalues and eigenvectors of covariance
95
+ % matrix.
96
+ [E, D] = eig (covarianceMatrix);
97
+
98
+ % The rank is determined from the eigenvalues - and not directly by
99
+ % using the function rank - because function rank uses svd, which
100
+ % in some cases gives a higher dimensionality than what can be used
101
+ % with eig later on (eig then gives negative eigenvalues).
102
+ rankTolerance = 1e-7;
103
+ maxLastEig = sum (diag (D) > rankTolerance);
104
+ if maxLastEig == 0,
105
+ fprintf (['Eigenvalues of the covariance matrix are' ...
106
+ ' all smaller than tolerance [ %g ].\n' ...
107
+ 'Please make sure that your data matrix contains' ...
108
+ ' nonzero values.\nIf the values are very small,' ...
109
+ ' try rescaling the data matrix.\n'], rankTolerance);
110
+ error ('Unable to continue, aborting.');
111
+ end
112
+
113
+ % Sort the eigenvalues - decending.
114
+ eigenvalues = flipud(sort(diag(D)));
115
+
116
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
117
+ % Interactive part - command-line
118
+ if b_interactive == 1
119
+
120
+ % Show the eigenvalues to the user
121
+ hndl_win=figure;
122
+ bar(eigenvalues);
123
+ title('Eigenvalues');
124
+
125
+ % ask the range from the user...
126
+ % ... and keep on asking until the range is valid :-)
127
+ areValuesOK=0;
128
+ while areValuesOK == 0
129
+ firstEig = input('The index of the largest eigenvalue to keep? (1) ');
130
+ lastEig = input(['The index of the smallest eigenvalue to keep? (' ...
131
+ int2str(oldDimension) ') ']);
132
+ % Check the new values...
133
+ % if they are empty then use default values
134
+ if isempty(firstEig), firstEig = 1;end
135
+ if isempty(lastEig), lastEig = oldDimension;end
136
+ % Check that the entered values are within the range
137
+ areValuesOK = 1;
138
+ if lastEig < 1 | lastEig > oldDimension
139
+ fprintf('Illegal number for the last eigenvalue.\n');
140
+ areValuesOK = 0;
141
+ end
142
+ if firstEig < 1 | firstEig > lastEig
143
+ fprintf('Illegal number for the first eigenvalue.\n');
144
+ areValuesOK = 0;
145
+ end
146
+ end
147
+ % close the window
148
+ close(hndl_win);
149
+ end
150
+
151
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
152
+ % Interactive part - GUI
153
+ if b_interactive == 2
154
+
155
+ % Show the eigenvalues to the user
156
+ hndl_win = figure('Color',[0.8 0.8 0.8], ...
157
+ 'PaperType','a4letter', ...
158
+ 'Units', 'normalized', ...
159
+ 'Name', 'FastICA: Reduce dimension', ...
160
+ 'NumberTitle','off', ...
161
+ 'Tag', 'f_eig');
162
+ h_frame = uicontrol('Parent', hndl_win, ...
163
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
164
+ 'Units', 'normalized', ...
165
+ 'Position',[0.13 0.05 0.775 0.17], ...
166
+ 'Style','frame', ...
167
+ 'Tag','f_frame');
168
+
169
+ b = uicontrol('Parent',hndl_win, ...
170
+ 'Units','normalized', ...
171
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
172
+ 'HorizontalAlignment','left', ...
173
+ 'Position',[0.142415 0.0949436 0.712077 0.108507], ...
174
+ 'String','Give the indices of the largest and smallest eigenvalues of the covariance matrix to be included in the reduced data.', ...
175
+ 'Style','text', ...
176
+ 'Tag','StaticText1');
177
+ e_first = uicontrol('Parent',hndl_win, ...
178
+ 'Units','normalized', ...
179
+ 'Callback',[ ...
180
+ 'f=round(str2num(get(gcbo, ''String'')));' ...
181
+ 'if (f < 1), f=1; end;' ...
182
+ 'l=str2num(get(findobj(''Tag'',''e_last''), ''String''));' ...
183
+ 'if (f > l), f=l; end;' ...
184
+ 'set(gcbo, ''String'', int2str(f));' ...
185
+ ], ...
186
+ 'BackgroundColor',[1 1 1], ...
187
+ 'HorizontalAlignment','right', ...
188
+ 'Position',[0.284831 0.0678168 0.12207 0.0542535], ...
189
+ 'Style','edit', ...
190
+ 'String', '1', ...
191
+ 'Tag','e_first');
192
+ b = uicontrol('Parent',hndl_win, ...
193
+ 'Units','normalized', ...
194
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
195
+ 'HorizontalAlignment','left', ...
196
+ 'Position',[0.142415 0.0678168 0.12207 0.0542535], ...
197
+ 'String','Range from', ...
198
+ 'Style','text', ...
199
+ 'Tag','StaticText2');
200
+ e_last = uicontrol('Parent',hndl_win, ...
201
+ 'Units','normalized', ...
202
+ 'Callback',[ ...
203
+ 'l=round(str2num(get(gcbo, ''String'')));' ...
204
+ 'lmax = get(gcbo, ''UserData'');' ...
205
+ 'if (l > lmax), l=lmax; fprintf([''The selected value was too large, or the selected eigenvalues were close to zero\n'']); end;' ...
206
+ 'f=str2num(get(findobj(''Tag'',''e_first''), ''String''));' ...
207
+ 'if (l < f), l=f; end;' ...
208
+ 'set(gcbo, ''String'', int2str(l));' ...
209
+ ], ...
210
+ 'BackgroundColor',[1 1 1], ...
211
+ 'HorizontalAlignment','right', ...
212
+ 'Position',[0.467936 0.0678168 0.12207 0.0542535], ...
213
+ 'Style','edit', ...
214
+ 'String', int2str(maxLastEig), ...
215
+ 'UserData', maxLastEig, ...
216
+ 'Tag','e_last');
217
+ % in the first version oldDimension was used instead of
218
+ % maxLastEig, but since the program would automatically
219
+ % drop the eigenvalues afte maxLastEig...
220
+ b = uicontrol('Parent',hndl_win, ...
221
+ 'Units','normalized', ...
222
+ 'BackgroundColor',[0.701961 0.701961 0.701961], ...
223
+ 'HorizontalAlignment','left', ...
224
+ 'Position',[0.427246 0.0678168 0.0406901 0.0542535], ...
225
+ 'String','to', ...
226
+ 'Style','text', ...
227
+ 'Tag','StaticText3');
228
+ b = uicontrol('Parent',hndl_win, ...
229
+ 'Units','normalized', ...
230
+ 'Callback','uiresume(gcbf)', ...
231
+ 'Position',[0.630697 0.0678168 0.12207 0.0542535], ...
232
+ 'String','OK', ...
233
+ 'Tag','Pushbutton1');
234
+ b = uicontrol('Parent',hndl_win, ...
235
+ 'Units','normalized', ...
236
+ 'Callback',[ ...
237
+ 'gui_help(''pcamat'');' ...
238
+ ], ...
239
+ 'Position',[0.767008 0.0678168 0.12207 0.0542535], ...
240
+ 'String','Help', ...
241
+ 'Tag','Pushbutton2');
242
+
243
+ h_axes = axes('Position' ,[0.13 0.3 0.775 0.6]);
244
+ set(hndl_win, 'currentaxes',h_axes);
245
+ bar(eigenvalues);
246
+ title('Eigenvalues');
247
+
248
+ uiwait(hndl_win);
249
+ firstEig = str2num(get(e_first, 'String'));
250
+ lastEig = str2num(get(e_last, 'String'));
251
+
252
+ % close the window
253
+ close(hndl_win);
254
+ end
255
+
256
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
257
+ % See if the user has reduced the dimension enought
258
+
259
+ if lastEig > maxLastEig
260
+ lastEig = maxLastEig;
261
+ if b_verbose
262
+ fprintf('Dimension reduced to %d due to the singularity of covariance matrix\n',...
263
+ lastEig-firstEig+1);
264
+ end
265
+ else
266
+ % Reduce the dimensionality of the problem.
267
+ if b_verbose
268
+ if oldDimension == (lastEig - firstEig + 1)
269
+ fprintf ('Dimension not reduced.\n');
270
+ else
271
+ fprintf ('Reducing dimension...\n');
272
+ end
273
+ end
274
+ end
275
+
276
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
277
+ % Drop the smaller eigenvalues
278
+ if lastEig < oldDimension
279
+ lowerLimitValue = (eigenvalues(lastEig) + eigenvalues(lastEig + 1)) / 2;
280
+ else
281
+ lowerLimitValue = eigenvalues(oldDimension) - 1;
282
+ end
283
+
284
+ lowerColumns = diag(D) > lowerLimitValue;
285
+
286
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287
+ % Drop the larger eigenvalues
288
+ if firstEig > 1
289
+ higherLimitValue = (eigenvalues(firstEig - 1) + eigenvalues(firstEig)) / 2;
290
+ else
291
+ higherLimitValue = eigenvalues(1) + 1;
292
+ end
293
+ higherColumns = diag(D) < higherLimitValue;
294
+
295
+ % Combine the results from above
296
+ selectedColumns = lowerColumns & higherColumns;
297
+
298
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
299
+ % print some info for the user
300
+ if b_verbose
301
+ fprintf ('Selected [ %d ] dimensions.\n', sum (selectedColumns));
302
+ end
303
+ if sum (selectedColumns) ~= (lastEig - firstEig + 1),
304
+ error ('Selected a wrong number of dimensions.');
305
+ end
306
+
307
+ if b_verbose
308
+ fprintf ('Smallest remaining (non-zero) eigenvalue [ %g ]\n', eigenvalues(lastEig));
309
+ fprintf ('Largest remaining (non-zero) eigenvalue [ %g ]\n', eigenvalues(firstEig));
310
+ fprintf ('Sum of removed eigenvalues [ %g ]\n', sum(diag(D) .* ...
311
+ (~selectedColumns)));
312
+ end
313
+
314
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315
+ % Select the colums which correspond to the desired range
316
+ % of eigenvalues.
317
+ E = selcol(E, selectedColumns);
318
+ D = selcol(selcol(D, selectedColumns)', selectedColumns);
319
+
320
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321
+ % Some more information
322
+ if b_verbose
323
+ sumAll=sum(eigenvalues);
324
+ sumUsed=sum(diag(D));
325
+ retained = (sumUsed / sumAll) * 100;
326
+ fprintf('[ %g ] %% of (non-zero) eigenvalues retained.\n', retained);
327
+ end
328
+
329
+
330
+
331
+
332
+
333
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
334
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335
+ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
336
+ function newMatrix = selcol(oldMatrix, maskVector);
337
+
338
+ % newMatrix = selcol(oldMatrix, maskVector);
339
+ %
340
+ % Selects the columns of the matrix that marked by one in the given vector.
341
+ % The maskVector is a column vector.
342
+
343
+ % 15.3.1998
344
+
345
+ if size(maskVector, 1) ~= size(oldMatrix, 2),
346
+ error ('The mask vector and matrix are of uncompatible size.');
347
+ end
348
+
349
+ numTaken = 0;
350
+
351
+ for i = 1 : size (maskVector, 1),
352
+ if maskVector(i, 1) == 1,
353
+ takingMask(1, numTaken + 1) = i;
354
+ numTaken = numTaken + 1;
355
+ end
356
+ end
357
+
358
+ newMatrix = oldMatrix(:, takingMask);
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/remmean.m ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [newVectors, meanValue] = remmean(vectors);
2
+ %REMMEAN - remove the mean from vectors
3
+ %
4
+ % [newVectors, meanValue] = remmean(vectors);
5
+ %
6
+ % Removes the mean of row vectors.
7
+ % Returns the new vectors and the mean.
8
+ %
9
+ % This function is needed by FASTICA and FASTICAG
10
+
11
+ % @(#)$Id: remmean.m,v 1.2 2003/04/05 14:23:58 jarmo Exp $
12
+
13
+ newVectors = zeros (size (vectors));
14
+ meanValue = mean (vectors')';
15
+ newVectors = vectors - meanValue * ones (1,size (vectors, 2));
scripts/eeglab_current/eeglab14_1_1b/plugins/FastICA_2.5/FastICA_25/whitenv.m ADDED
@@ -0,0 +1,82 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ function [newVectors, whiteningMatrix, dewhiteningMatrix] = whitenv ...
2
+ (vectors, E, D, s_verbose);
3
+ %WHITENV - Whitenv vectors.
4
+ %
5
+ % [newVectors, whiteningMatrix, dewhiteningMatrix] = ...
6
+ % whitenv(vectors, E, D, verbose);
7
+ %
8
+ % Whitens the data (row vectors) and reduces dimension. Returns
9
+ % the whitened vectors (row vectors), whitening and dewhitening matrices.
10
+ %
11
+ % ARGUMENTS
12
+ %
13
+ % vectors Data in row vectors.
14
+ % E Eigenvector matrix from function 'pcamat'
15
+ % D Diagonal eigenvalue matrix from function 'pcamat'
16
+ % verbose Optional. Default is 'on'
17
+ %
18
+ % EXAMPLE
19
+ % [E, D] = pcamat(vectors);
20
+ % [nv, wm, dwm] = whitenv(vectors, E, D);
21
+ %
22
+ %
23
+ % This function is needed by FASTICA and FASTICAG
24
+ %
25
+ % See also PCAMAT
26
+
27
+ % @(#)$Id: whitenv.m,v 1.3 2003/10/12 09:04:43 jarmo Exp $
28
+
29
+ % ========================================================
30
+ % Default value for 'verbose'
31
+ if nargin < 4, s_verbose = 'on'; end
32
+
33
+ % Check the optional parameter verbose;
34
+ switch lower(s_verbose)
35
+ case 'on'
36
+ b_verbose = 1;
37
+ case 'off'
38
+ b_verbose = 0;
39
+ otherwise
40
+ error(sprintf('Illegal value [ %s ] for parameter: ''verbose''\n', s_verbose));
41
+ end
42
+
43
+ % ========================================================
44
+ % In some cases, rounding errors in Matlab cause negative
45
+ % eigenvalues (elements in the diagonal of D). Since it
46
+ % is difficult to know when this happens, it is difficult
47
+ % to correct it automatically. Therefore an error is
48
+ % signalled and the correction is left to the user.
49
+ if any (diag (D) < 0),
50
+ error (sprintf (['[ %d ] negative eigenvalues computed from the' ...
51
+ ' covariance matrix.\nThese are due to rounding' ...
52
+ ' errors in Matlab (the correct eigenvalues are\n' ...
53
+ 'probably very small).\nTo correct the situation,' ...
54
+ ' please reduce the number of dimensions in the' ...
55
+ ' data\nby using the ''lastEig'' argument in' ...
56
+ ' function FASTICA, or ''Reduce dim.'' button\nin' ...
57
+ ' the graphical user interface.'], ...
58
+ sum (diag (D) < 0)));
59
+ end
60
+
61
+ % ========================================================
62
+ % Calculate the whitening and dewhitening matrices (these handle
63
+ % dimensionality simultaneously).
64
+ whiteningMatrix = inv (sqrt (D)) * E';
65
+ dewhiteningMatrix = E * sqrt (D);
66
+
67
+ % Project to the eigenvectors of the covariance matrix.
68
+ % Whiten the samples and reduce dimension simultaneously.
69
+ if b_verbose, fprintf ('Whitening...\n'); end
70
+ newVectors = whiteningMatrix * vectors;
71
+
72
+ % ========================================================
73
+ % Just some security...
74
+ if ~isreal(newVectors)
75
+ error ('Whitened vectors have imaginary values.');
76
+ end
77
+
78
+ % Print some information to user
79
+ if b_verbose
80
+ fprintf ('Check: covariance differs from identity by [ %g ].\n', ...
81
+ max (max (abs (cov (newVectors', 1) - eye (size (newVectors, 1))))));
82
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/eegplugin_bva_io.m ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % eegplugin_bva_io() - EEGLAB plugin for importing Brainvision
2
+ % .vhdr data files.
3
+ %
4
+ % Usage:
5
+ % >> eegplugin_bva_io(fig, trystrs, catchstrs);
6
+ %
7
+ % Inputs:
8
+ % fig - [integer] EEGLAB figure
9
+ % trystrs - [struct] "try" strings for menu callbacks.
10
+ % catchstrs - [struct] "catch" strings for menu callbacks.
11
+ %
12
+ % Author: Andreas Widmann for binary import, 2004
13
+ % Arnaud Delorme for Matlab import and EEGLAB interface
14
+ %
15
+ % See also: pop_loadbv()
16
+
17
+ % Copyright (C) 2004 Andreas Widmann & Arnaud Delorme
18
+ %
19
+ % This program is free software; you can redistribute it and/or modify
20
+ % it under the terms of the GNU General Public License as published by
21
+ % the Free Software Foundation; either version 2 of the License, or
22
+ % (at your option) any later version.
23
+ %
24
+ % This program is distributed in the hope that it will be useful,
25
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ % GNU General Public License for more details.
28
+ %
29
+ % You should have received a copy of the GNU General Public License
30
+ % along with this program; if not, write to the Free Software
31
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
+
33
+ % $Id: eegplugin_bva_io.m 53 2010-05-22 21:57:38Z arnodelorme $
34
+
35
+ function vers = eegplugin_bva_io(fig, trystrs, catchstrs)
36
+
37
+ vers = 'bva_io1.5.13';
38
+ if nargin < 3
39
+ error('eegplugin_bva_io requires 3 arguments');
40
+ end;
41
+
42
+ % add folder to path
43
+ % ------------------
44
+ if ~exist('eegplugin_bva_io')
45
+ p = which('eegplugin_bva_io.m');
46
+ p = p(1:findstr(p,'eegplugin_bva_io.m')-1);
47
+ addpath( p );
48
+ end;
49
+
50
+ % find import data menu
51
+ % ---------------------
52
+ menui = findobj(fig, 'tag', 'import data');
53
+ menuo = findobj(fig, 'tag', 'export');
54
+
55
+ % menu callbacks
56
+ % --------------
57
+ icadefs;
58
+ versiontype = 1;
59
+ if exist('EEGLAB_VERSION')
60
+ if EEGLAB_VERSION(1) == '4'
61
+ versiontype = 0;
62
+ end;
63
+ end;
64
+ if versiontype == 0
65
+ comcnt1 = [ trystrs.no_check '[EEGTMP LASTCOM] = pop_loadbv;' catchstrs.new_non_empty ];
66
+ comcnt2 = [ trystrs.no_check '[EEGTMP LASTCOM] = pop_loadbva;' catchstrs.new_non_empty ];
67
+ else
68
+ comcnt1 = [ trystrs.no_check '[EEG LASTCOM] = pop_loadbv;' catchstrs.new_non_empty ];
69
+ comcnt2 = [ trystrs.no_check '[EEG LASTCOM] = pop_loadbva;' catchstrs.new_non_empty ];
70
+ end;
71
+ comcnt3 = [ trystrs.no_check 'LASTCOM = pop_writebva(EEG);' catchstrs.add_to_hist ];
72
+
73
+ % create menus
74
+ % ------------
75
+ uimenu( menui, 'label', 'From Brain Vis. Rec. .vhdr file', 'callback', comcnt1, 'separator', 'on' );
76
+ uimenu( menui, 'label', 'From Brain Vis. Anal. Matlab file', 'callback', comcnt2 );
77
+ uimenu( menuo, 'label', 'Write Brain Vis. exchange format file', 'callback', comcnt3, 'separator', 'on' );
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/loadbvef.m ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % loadbvef() - Load BrainVision electrode location file
2
+ %
3
+ % Usage:
4
+ % >> chanlocs = loadbvef( filename );
5
+ %
6
+ % Inputs:
7
+ % filename - filename incl. filepath
8
+ %
9
+ % Outputs:
10
+ % chanlocs - EEGLAB chanlocs structure
11
+ %
12
+ % References:
13
+ % http://de.mathworks.com/help/matlab/import_export/importing-xml-documents.html
14
+ %
15
+ % Author: Andreas Widmann, University of Leipzig, 2015
16
+
17
+ %123456789012345678901234567890123456789012345678901234567890123456789012
18
+
19
+ % Copyright (C) 2015 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
20
+ %
21
+ % This program is free software; you can redistribute it and/or modify
22
+ % it under the terms of the GNU General Public License as published by
23
+ % the Free Software Foundation; either version 2 of the License, or
24
+ % (at your option) any later version.
25
+ %
26
+ % This program is distributed in the hope that it will be useful,
27
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
28
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29
+ % GNU General Public License for more details.
30
+ %
31
+ % You should have received a copy of the GNU General Public License
32
+ % along with this program; if not, write to the Free Software
33
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
34
+
35
+ function [ chanlocs ] = loadbvef( filename )
36
+
37
+ % Import/export tag/field name mapping
38
+ fieldNames = { 'Name', 'labels', 1; 'Theta', 'sph_theta_besa', 0; 'Phi', 'sph_phi_besa', 0; 'Radius', 'sph_radius', 0 };
39
+
40
+ % Read file
41
+ xDoc = xmlread( filename );
42
+
43
+ % Loop over electrodes
44
+ allListitems = xDoc.getElementsByTagName( 'Electrode' );
45
+
46
+ for k = 0:allListitems.getLength - 1
47
+
48
+ thisListitem = allListitems.item( k );
49
+
50
+ % Loop over fields
51
+ for iField = 1:size( fieldNames, 1 )
52
+
53
+ thisList = thisListitem.getElementsByTagName( fieldNames{ iField, 1 } );
54
+ thisElement = thisList.item( 0 );
55
+
56
+ % String or numeric
57
+ if fieldNames{ iField, 3 }
58
+ chanlocs( k + 1 ).( fieldNames{ iField, 2 } ) = char( thisElement.getFirstChild.getData ); %#ok<AGROW>
59
+ else
60
+ chanlocs( k + 1 ).( fieldNames{ iField, 2 } ) = str2double( thisElement.getFirstChild.getData ); %#ok<AGROW>
61
+ end
62
+
63
+ end
64
+
65
+ end
66
+
67
+ % Convert from BESA
68
+ chanlocs = convertlocs( chanlocs, 'sphbesa2all' );
69
+ chanlocs = rmfield( chanlocs, { 'sph_phi_besa', 'sph_theta_besa' } );
70
+
71
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/parsebvmrk.m ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % parsebvmrk() - convert Brain Vision Data Exchange format marker
2
+ % configuration structure to EEGLAB event structure
3
+ %
4
+ % Usage:
5
+ % >> EVENT = parsebvmrk(MRK);
6
+ %
7
+ % Inputs:
8
+ % MRK - marker configuration structure
9
+ %
10
+ % Outputs:
11
+ % EVENT - EEGLAB event structure
12
+ %
13
+ % Author: Andreas Widmann, University of Leipzig, 2007
14
+
15
+ % Copyright (C) 2007 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
16
+ %
17
+ % This program is free software; you can redistribute it and/or modify
18
+ % it under the terms of the GNU General Public License as published by
19
+ % the Free Software Foundation; either version 2 of the License, or
20
+ % (at your option) any later version.
21
+ %
22
+ % This program is distributed in the hope that it will be useful,
23
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
24
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25
+ % GNU General Public License for more details.
26
+ %
27
+ % You should have received a copy of the GNU General Public License
28
+ % along with this program; if not, write to the Free Software
29
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
+
31
+ % $Id: parsebvmrk.m 37 2007-06-26 12:56:17Z andreaswidmann $
32
+
33
+ function EVENT = parsebvmrk(MRK)
34
+
35
+ for idx = 1:size(MRK.markerinfos, 1)
36
+ [mrkType mrkDesc EVENT(idx).latency EVENT(idx).duration EVENT(idx).channel EVENT(idx).bvtime] = ...
37
+ strread(MRK.markerinfos{idx, 1}, '%s%s%f%d%d%d', 'delimiter', ',');
38
+ EVENT(idx).bvmknum = MRK.markerinfos{idx, 2};
39
+
40
+ if strcmpi(mrkType, 'New Segment') || strcmpi(mrkType, 'DC Correction')
41
+ EVENT(idx).type = 'boundary';
42
+ else
43
+ EVENT(idx).type = char(mrkDesc);
44
+ end
45
+
46
+ EVENT(idx).code = char(mrkType);
47
+ EVENT(idx).urevent = idx;
48
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbv.m ADDED
@@ -0,0 +1,423 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % pop_loadbv() - load Brain Vision Data Exchange format dataset and
2
+ % return EEGLAB EEG structure
3
+ %
4
+ % Usage:
5
+ % >> [EEG, com] = pop_loadbv; % pop-up window mode
6
+ % >> [EEG, com] = pop_loadbv(path, hdrfile);
7
+ % >> [EEG, com] = pop_loadbv(path, hdrfile, srange);
8
+ % >> [EEG, com] = pop_loadbv(path, hdrfile, [], chans);
9
+ % >> [EEG, com] = pop_loadbv(path, hdrfile, srange, chans);
10
+ %
11
+ % Optional inputs:
12
+ % path - path to files
13
+ % hdrfile - name of Brain Vision vhdr-file (incl. extension)
14
+ % srange - scalar first sample to read (up to end of file) or
15
+ % vector first and last sample to read (e.g., [7 42];
16
+ % default: all)
17
+ % chans - vector channels channels to read (e.g., [1:2 4];
18
+ % default: all)
19
+ %
20
+ % Outputs:
21
+ % EEG - EEGLAB EEG structure
22
+ % com - history string
23
+ %
24
+ % Note:
25
+ % Import "Brain Vision Data Exchange" format files with this function.
26
+ % Brain Vision Data Exchange files consist of a set of 3 files, a header
27
+ % file (.vhdr), a marker file (.vmrk), and a data file. Export from
28
+ % BrainVision Analyzer with "Generic Data" export. Select header and
29
+ % marker file for export (text format; XML format is not yet supported).
30
+ % Binary and text data formats, in both multiplexed and vectorized data
31
+ % orientation are supported. Binary data formats offer higher precision
32
+ % and faster file import.
33
+ %
34
+ % Author: Andreas Widmann & Arnaud Delorme, 2004-
35
+
36
+ % Copyright (C) 2004 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
37
+ %
38
+ % This program is free software; you can redistribute it and/or modify
39
+ % it under the terms of the GNU General Public License as published by
40
+ % the Free Software Foundation; either version 2 of the License, or
41
+ % (at your option) any later version.
42
+ %
43
+ % This program is distributed in the hope that it will be useful,
44
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
45
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46
+ % GNU General Public License for more details.
47
+ %
48
+ % You should have received a copy of the GNU General Public License
49
+ % along with this program; if not, write to the Free Software
50
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51
+
52
+ % $Id: pop_loadbv.m 53 2010-05-22 21:57:38Z arnodelorme $
53
+ % Revision 1.5 2010/03/23 21:19:52 roy
54
+ % added some lines so that the function can deal with the space lines in the ASCII multiplexed data file
55
+
56
+ function [EEG, com] = pop_loadbv(path, hdrfile, srange, chans)
57
+
58
+ com = '';
59
+ EEG = [];
60
+
61
+ if nargin < 2
62
+ [hdrfile path] = uigetfile2('*.vhdr', 'Select Brain Vision vhdr-file - pop_loadbv()');
63
+ if hdrfile(1) == 0, return; end
64
+
65
+ drawnow;
66
+ uigeom = {[1 0.5] [1 0.5]};
67
+ uilist = {{ 'style' 'text' 'string' 'Interval (samples; e.g., [7 42]; default: all):'} ...
68
+ { 'style' 'edit' 'string' ''} ...
69
+ { 'style' 'text' 'string' 'Channels (e.g., [1:2 4]; default: all):'} ...
70
+ { 'style' 'edit' 'string' ''}};
71
+ result = inputgui(uigeom, uilist, 'pophelp(''pop_loadbv'')', 'Load a Brain Vision Data Exchange format dataset');
72
+ if isempty(result), return, end
73
+ if ~isempty(result{1}),
74
+ srange = str2num(result{1});
75
+ end
76
+ if ~isempty(result{2}),
77
+ chans = str2num(result{2});
78
+ end
79
+ end
80
+
81
+ % Header file
82
+ disp('pop_loadbv(): reading header file');
83
+ hdr = readbvconf(path, hdrfile);
84
+
85
+ % Common Infos
86
+ try
87
+ EEG = eeg_emptyset;
88
+ catch
89
+ end
90
+ EEG.comments = ['Original file: ' hdr.commoninfos.datafile];
91
+ hdr.commoninfos.numberofchannels = str2double(hdr.commoninfos.numberofchannels);
92
+ EEG.srate = 1000000 / str2double(hdr.commoninfos.samplinginterval);
93
+
94
+ % Binary Infos
95
+ if strcmpi(hdr.commoninfos.dataformat, 'binary')
96
+ switch lower(hdr.binaryinfos.binaryformat)
97
+ case 'int_16', binformat = 'int16'; bps = 2;
98
+ case 'uint_16', binformat = 'uint16'; bps = 2;
99
+ case 'ieee_float_32', binformat = 'float32'; bps = 4;
100
+ otherwise, error('Unsupported binary format');
101
+ end
102
+ end
103
+
104
+ % Channel Infos
105
+ if ~exist('chans', 'var')
106
+ chans = 1:hdr.commoninfos.numberofchannels;
107
+ EEG.nbchan = hdr.commoninfos.numberofchannels;
108
+ elseif isempty(chans)
109
+ chans = 1:hdr.commoninfos.numberofchannels;
110
+ EEG.nbchan = hdr.commoninfos.numberofchannels;
111
+ else
112
+ EEG.nbchan = length(chans);
113
+ end
114
+ if any(chans < 1) || any(chans > hdr.commoninfos.numberofchannels)
115
+ error('chans out of available channel range');
116
+ end
117
+ if isfield(hdr, 'channelinfos')
118
+ for chan = 1:length(chans)
119
+ try
120
+ [EEG.chanlocs(chan).labels, chanlocs(chan).ref, chanlocs(chan).scale, chanlocs(chan).unit] = strread(hdr.channelinfos{chans(chan)}, '%s%s%s%s', 1, 'delimiter', ',');
121
+ catch % Octave compatible code below
122
+ str = hdr.channelinfos{chans(chan)};
123
+ [EEG.chanlocs(chan).labels str] = strtok(str, ',');
124
+ [chanlocs(chan).ref str] = strtok(str, ',');
125
+ [chanlocs(chan).scale str] = strtok(str, ',');
126
+ [chanlocs(chan).unit str] = strtok(str, ',');
127
+ end;
128
+ EEG.chanlocs(chan).labels = char(EEG.chanlocs(chan).labels);
129
+ chanlocs(chan).scale = str2double(char(chanlocs(chan).scale));
130
+ % chanlocs(chan).unit = native2unicode(double(char(chanlocs(chan).scale)), 'UTF-8');
131
+ % EEG.chanlocs(chan).datachan = chans(chan);
132
+ end
133
+ if isempty([chanlocs.scale])
134
+ chanlocs = rmfield(chanlocs, 'scale');
135
+ end
136
+ end;
137
+ % [EEG.chanlocs.type] = deal([]);
138
+
139
+ % Coordinates
140
+ if isfield(hdr, 'coordinates')
141
+ hdr.coordinates(end+1:length(chans)) = { [] };
142
+ onenon0channel = 0;
143
+ for chan = 1:length(chans)
144
+ if ~isempty(hdr.coordinates{chans(chan)})
145
+ if ismatlab,
146
+ [EEG.chanlocs(chan).sph_radius, theta, phi] = strread(hdr.coordinates{chans(chan)}, '%f%f%f', 'delimiter', ',');
147
+ else
148
+ str = hdr.coordinates{chans(chan)};
149
+ [EEG.chanlocs(chan).sph_radius str] = strtok(str, ','); EEG.chanlocs(chan).sph_radius = str2num(EEG.chanlocs(chan).sph_radius);
150
+ [theta str] = strtok(str, ','); theta = str2num(theta);
151
+ [phi str] = strtok(str, ','); phi = str2num(phi);
152
+ end;
153
+ if EEG.chanlocs(chan).sph_radius == 0 && theta == 0 && phi == 0
154
+ EEG.chanlocs(chan).sph_radius = [];
155
+ EEG.chanlocs(chan).sph_theta = [];
156
+ EEG.chanlocs(chan).sph_phi = [];
157
+ else
158
+ onenon0channel = 1;
159
+ EEG.chanlocs(chan).sph_theta = phi - 90 * sign(theta);
160
+ EEG.chanlocs(chan).sph_phi = -abs(theta) + 90;
161
+ end
162
+ end;
163
+ end
164
+ try,
165
+ if onenon0channel
166
+ [EEG.chanlocs, EEG.chaninfo] = pop_chanedit(EEG.chanlocs, 'convert', 'sph2topo');
167
+ [EEG.chanlocs, EEG.chaninfo] = pop_chanedit(EEG.chanlocs, 'convert', 'sph2cart');
168
+ end;
169
+ catch, end
170
+ end
171
+
172
+ % Open data file and find the number of data points
173
+ % -------------------------------------------------
174
+ disp('pop_loadbv(): reading EEG data');
175
+ [IN, message] = fopen(fullfile(path, hdr.commoninfos.datafile), 'r');
176
+ if IN == -1
177
+ [IN, message] = fopen(fullfile(path, lower(hdr.commoninfos.datafile)));
178
+ if IN == -1
179
+ error(message)
180
+ end;
181
+ end
182
+ if isfield( hdr.commoninfos, 'datapoints' ) && ~isempty( hdr.commoninfos.datapoints ) && isnumeric( str2double( hdr.commoninfos.datapoints ) ) && str2double( hdr.commoninfos.datapoints ) > 0
183
+ hdr.commoninfos.datapoints = str2double(hdr.commoninfos.datapoints);
184
+ elseif strcmpi( hdr.commoninfos.dataformat, 'binary' )
185
+ fseek( IN, 0, 'eof' );
186
+ hdr.commoninfos.datapoints = ftell( IN ) / ( hdr.commoninfos.numberofchannels * bps );
187
+ fseek( IN, 0, 'bof' );
188
+ else
189
+ hdr.commoninfos.datapoints = NaN;
190
+ end
191
+
192
+ if ~strcmpi(hdr.commoninfos.dataformat, 'binary') % ASCII
193
+ % tmppoint = hdr.commoninfos.datapoints;
194
+ tmpchan = fscanf(IN, '%s', 1);
195
+
196
+ % AW: Determination of number of datapoints will not work for files without chanlabels and/or multiplexed dataformat. Suggest trusting in header.
197
+ % tmpdata = fscanf(IN, '%f', inf);
198
+ % hdr.commoninfos.datapoints = length(tmpdata);
199
+ % chanlabels = 1;
200
+ if isnan(str2double(tmpchan))
201
+ % hdr.commoninfos.datapoints = hdr.commoninfos.datapoints+1;
202
+ chanlabels = 1;
203
+ else
204
+ chanlabels = 0;
205
+ end
206
+ end
207
+
208
+ % Sample range
209
+ if ~exist('srange', 'var') || isempty(srange)
210
+ srange = [ 1 hdr.commoninfos.datapoints];
211
+ EEG.pnts = hdr.commoninfos.datapoints;
212
+ elseif length(srange) == 1
213
+ EEG.pnts = hdr.commoninfos.datapoints - srange(1) + 1;
214
+ else
215
+ EEG.pnts = srange(2) - srange(1) + 1;
216
+ end
217
+ if any(srange < 1) || any(srange > hdr.commoninfos.datapoints)
218
+ error('srange out of available data range');
219
+ end
220
+
221
+ % Read data
222
+ if strcmpi(hdr.commoninfos.dataformat, 'binary')
223
+ switch lower(hdr.commoninfos.dataorientation)
224
+ case 'multiplexed'
225
+ if EEG.nbchan == hdr.commoninfos.numberofchannels % Read all channels
226
+ fseek(IN, (srange(1) - 1) * EEG.nbchan * bps, 'bof');
227
+ EEG.data = fread(IN, [EEG.nbchan, EEG.pnts], [binformat '=>float32']);
228
+ else % Read channel subset
229
+ EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]); % Preallocate memory
230
+ for chan = 1:length(chans)
231
+ fseek(IN, (srange(1) - 1) * hdr.commoninfos.numberofchannels * bps + (chans(chan) - 1) * bps, 'bof');
232
+ EEG.data(chan, :) = fread(IN, [1, EEG.pnts], [binformat '=>float32'], (hdr.commoninfos.numberofchannels - 1) * bps);
233
+ end
234
+ end
235
+ case 'vectorized'
236
+ if isequal(EEG.pnts, hdr.commoninfos.datapoints) && EEG.nbchan == hdr.commoninfos.numberofchannels % Read entire file
237
+ EEG.data = fread(IN, [EEG.pnts, EEG.nbchan], [binformat '=>float32']).';
238
+ else % Read fraction of file
239
+ EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]); % Preallocate memory
240
+ for chan = 1:length(chans)
241
+ fseek(IN, ((chans(chan) - 1) * hdr.commoninfos.datapoints + srange(1) - 1) * bps, 'bof');
242
+ EEG.data(chan, :) = fread(IN, [1, EEG.pnts], [binformat '=>float32']);
243
+ end
244
+ end
245
+ otherwise
246
+ error('Unsupported data orientation')
247
+ end
248
+ else % ASCII data
249
+ % disp('If this function does not work, export your data in binary format');
250
+ % EEG.data = repmat(single(0), [EEG.nbchan, EEG.pnts]);
251
+ % if strcmpi(lower(hdr.commoninfos.dataorientation), 'vectorized')
252
+ % count = 1;
253
+ % fseek(IN, 0, 'bof');
254
+ % len = inf;
255
+ % for chan = 1:hdr.commoninfos.numberofchannels
256
+ % if chanlabels, tmpchan = fscanf(IN, '%s', 1); end;
257
+ % tmpdata = fscanf(IN, '%f', len); len = length(tmpdata);
258
+ % if ismember(chan, chans)
259
+ % EEG.data(count, :) = tmpdata(srange(1):srange(2))';
260
+ % count = count + 1;
261
+ % end;
262
+ % end;
263
+ % elseif strcmpi(lower(hdr.commoninfos.dataorientation), 'multiplexed')
264
+ % % fclose(IN);
265
+ % % error('ASCII multiplexed reading not implemeted yet; export as a different format');
266
+ % if EEG.nbchan == hdr.commoninfos.numberofchannels % Read all channels
267
+ % tmpchan= fgetl(IN);
268
+ % count = 1;
269
+ % while ~feof(IN)
270
+ % tmpstr = fgetl(IN);
271
+ % if ~isempty(tmpstr)
272
+ % temp_ind = tmpstr==',';
273
+ % tmpstr(temp_ind) = '.';
274
+ % tmpdata = strread(tmpstr);
275
+ % EEG.data(:,count) = tmpdata';
276
+ % count = count + 1;
277
+ % end;
278
+ % end;
279
+ % EEG.pnts = count - 1;
280
+ % else
281
+ %
282
+ % end;
283
+ % end;
284
+
285
+ % Rewritten by AW, 2013-10-02. Old version by Arno did no longer work. MATLAB changes?
286
+ tmpdata = zeros([hdr.commoninfos.numberofchannels, hdr.commoninfos.datapoints], 'single');
287
+ fseek(IN, 0, 'bof');
288
+ switch lower(hdr.commoninfos.dataorientation)
289
+
290
+ case 'vectorized'
291
+ if chanlabels || (isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.')) % Read line by line
292
+
293
+ for iChan = 1:hdr.commoninfos.numberofchannels
294
+ tmpstr = fgetl(IN);
295
+ if chanlabels
296
+ [tmpchan, count, errmsg, nextindex] = sscanf(tmpstr, '%s', 1);
297
+ tmpstr = tmpstr(nextindex:end);
298
+ end
299
+ if isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.')
300
+ tmpdata(iChan, :) = sscanf(regexprep(tmpstr, hdr.asciiinfos.decimalsymbol, '.'), '%f', inf);
301
+ else
302
+ tmpdata(iChan, :) = sscanf(tmpstr, '%f', inf);
303
+ end
304
+ end
305
+
306
+ else
307
+ tmpdata = fscanf(IN, '%f', inf);
308
+ tmpdata = reshape(tmpdata, hdr.commoninfos.datapoints, hdr.commoninfos.numberofchannels)';
309
+ end
310
+
311
+ case 'multiplexed'
312
+ if chanlabels
313
+ tmpchan = fgetl(IN);
314
+ end
315
+ if isfield(hdr, 'asciiinfos') && isfield(hdr.asciiinfos, 'decimalsymbol') && ~strcmp(hdr.asciiinfos.decimalsymbol, '.') % Read line by line
316
+ for iPnt = 1:hdr.commoninfos.datapoints
317
+ tmpstr = fgetl(IN);
318
+ tmpdata(:, iPnt) = sscanf(regexprep(tmpstr, hdr.asciiinfos.decimalsymbol, '.'), '%f', inf);
319
+ end
320
+ else
321
+ tmpdata = fscanf(IN, '%f', inf);
322
+ tmpdata = reshape(tmpdata, hdr.commoninfos.numberofchannels, hdr.commoninfos.datapoints);
323
+ end
324
+
325
+ otherwise
326
+ error('Unknown data orientation')
327
+
328
+ end
329
+
330
+ EEG.data = tmpdata(chans, srange(1):srange(2));
331
+
332
+ end
333
+
334
+ fclose(IN);
335
+ EEG.trials = 1;
336
+ EEG.xmin = 0;
337
+ EEG.xmax = (EEG.pnts - 1) / EEG.srate;
338
+
339
+ % Convert to EEG.data to double for MATLAB < R14
340
+ if str2double(version('-release')) < 14
341
+ EEG.data = double(EEG.data);
342
+ end
343
+
344
+ % Scale data
345
+ if exist('chanlocs', 'var') && isfield(chanlocs, 'scale')
346
+ disp('pop_loadbv(): scaling EEG data');
347
+ for chan = 1:EEG.nbchan
348
+ if ~isnan(chanlocs(chan).scale)
349
+ EEG.data(chan, :) = EEG.data(chan, :) * chanlocs(chan).scale;
350
+ end;
351
+ end
352
+ end
353
+
354
+ % Marker file
355
+ if isfield(hdr.commoninfos, 'markerfile')
356
+ disp('pop_loadbv(): reading marker file');
357
+ MRK = readbvconf(path, hdr.commoninfos.markerfile);
358
+
359
+ if hdr.commoninfos.datafile ~= MRK.commoninfos.datafile
360
+ disp('pop_loadbv() warning: data files in header and marker files inconsistent.');
361
+ end
362
+
363
+ % Marker infos
364
+ if isfield(MRK, 'markerinfos')
365
+ EEG.event = parsebvmrk(MRK);
366
+
367
+ % Correct event latencies by first sample offset
368
+ tmpevent = EEG.event;
369
+ for index = 1:length(EEG.event)
370
+ tmpevent(index).latency = tmpevent(index).latency - srange(1) + 1;
371
+ end;
372
+ EEG.event = tmpevent;
373
+
374
+ % Remove unreferenced events
375
+ EEG.event = EEG.event([tmpevent.latency] >= 1 & [tmpevent.latency] <= EEG.pnts);
376
+
377
+ % Copy event structure to urevent structure
378
+ EEG.urevent = rmfield(EEG.event, 'urevent');
379
+
380
+ % find if boundaries at homogenous intervals
381
+ % ------------------------------------------
382
+ tmpevent = EEG.event;
383
+ boundaries = strmatch('boundary', {tmpevent.type});
384
+ boundlats = unique([tmpevent(boundaries).latency]);
385
+ if (isfield(hdr.commoninfos, 'segmentationtype') && (strcmpi(hdr.commoninfos.segmentationtype, 'markerbased') || strcmpi(hdr.commoninfos.segmentationtype, 'fixtime'))) && length(boundaries) > 1 && length(unique(diff([boundlats EEG.pnts + 1]))) == 1
386
+ EEG.trials = length(boundlats);
387
+ EEG.pnts = EEG.pnts / EEG.trials;
388
+ EEG.event(boundaries) = [];
389
+
390
+ % adding epoch field
391
+ % ------------------
392
+ tmpevent = EEG.event;
393
+ for index = 1:length(EEG.event)
394
+ EEG.event(index).epoch = ceil(tmpevent(index).latency / EEG.pnts);
395
+ end
396
+
397
+ % finding minimum time
398
+ % --------------------
399
+ tles = strmatch('time 0', lower({tmpevent.code}))';
400
+ if ~isempty(tles)
401
+ for iTLE = tles(:)'
402
+ EEG.event(iTLE).type ='TLE';
403
+ end
404
+ EEG.xmin = -(tmpevent(tles(1)).latency - 1) / EEG.srate;
405
+ end
406
+ else
407
+ for index = 1:length(boundaries)
408
+ EEG.event(boundaries(index)).duration = NaN;
409
+ end;
410
+ end
411
+ end
412
+ end
413
+
414
+ EEG.ref = 'common';
415
+
416
+ try
417
+ EEG = eeg_checkset(EEG);
418
+ catch
419
+ end
420
+
421
+ if nargout == 2
422
+ com = sprintf('EEG = pop_loadbv(''%s'', ''%s'', %s, %s);', path, hdrfile, mat2str(srange), mat2str(chans));
423
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_loadbva.m ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % pop_loadbva() - import a Matlab file from brain vision analyser
2
+ % software.
3
+ %
4
+ % Usage:
5
+ % >> OUTEEG = pop_loadbva( filename );
6
+ %
7
+ % Inputs:
8
+ % filename - file name
9
+ %
10
+ % Outputs:
11
+ % OUTEEG - EEGLAB data structure
12
+ %
13
+ % Author: Arnaud Delorme, SCCN/INC/UCSD, Dec 2003
14
+ %
15
+ % See also: eeglab()
16
+
17
+ % Copyright (C) 2003 Arnaud Delorme, Salk Institute, arno@salk.edu
18
+ %
19
+ % This program is free software; you can redistribute it and/or modify
20
+ % it under the terms of the GNU General Public License as published by
21
+ % the Free Software Foundation; either version 2 of the License, or
22
+ % (at your option) any later version.
23
+ %
24
+ % This program is distributed in the hope that it will be useful,
25
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
26
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
+ % GNU General Public License for more details.
28
+ %
29
+ % You should have received a copy of the GNU General Public License
30
+ % along with this program; if not, write to the Free Software
31
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
+
33
+ function [EEG, com] = pop_loadbva(filename)
34
+
35
+ EEG = [];
36
+ com = '';
37
+
38
+ if nargin < 1
39
+ [tmpfilename, filepath] = uigetfile('*.mat;*.MAT', 'Choose a Matlab file from Brain Vision Analyser -- pop_loadbva');
40
+ if tmpfilename == 0 return; end;
41
+ filename = [ filepath tmpfilename ];
42
+ end;
43
+
44
+ disp('Importing data');
45
+ EEG = eeg_emptyset;
46
+ bva = load(filename, '-mat');
47
+ allfields = fieldnames(bva);
48
+ chanstruct = bva.Channels;
49
+ channames = lower({ chanstruct.Name });
50
+ for index = 1:length(allfields)
51
+ switch lower(allfields{index})
52
+ case { 't' 'markercount' 'markers' 'samplerate' 'segmentcount' 'channelcount' 'channels' },
53
+ otherwise
54
+ count1 = strmatch(lower(allfields{index}), channames, 'exact');
55
+ count2 = strmatch(lower(allfields{index}(2:end)), channames, 'exact');
56
+ if ~isempty(count1) | ~isempty(count2)
57
+ count = [ count1 count2 ];
58
+ count = count(1);
59
+ else
60
+ disp(['Warning: channel ''' lower(allfields{index}) ''' not in channel location structure']);
61
+ count = length(chanstruct)+1;
62
+ chanstruct(end+1).Name = allfields{index};
63
+ chanstruct(end+1).Phi = [];
64
+ chanstruct(end+1).Theta = [];
65
+ chanstruct(end+1).Radius = [];
66
+ end;
67
+ if bva.SegmentCount > 1
68
+ EEG.data(count,:,:) = getfield(bva, allfields{index})';
69
+ bva = rmfield(bva, allfields{index});
70
+ else
71
+ EEG.data(count,:) = getfield(bva, allfields{index});
72
+ bva = rmfield(bva, allfields{index});
73
+ end;
74
+ end;
75
+ end;
76
+
77
+ EEG.nbchan = size(EEG.data,1);
78
+ EEG.srate = bva.SampleRate;
79
+ EEG.xmin = bva.t(1)/1000;
80
+ EEG.xmax = bva.t(end)/1000;
81
+ EEG.pnts = size(EEG.data,2);
82
+ EEG.trials = size(EEG.data,3);
83
+ EEG.setname = 'Brain Vision Analyzer file';
84
+ EEG.comments = [ 'Original file: ' filename ];
85
+
86
+ % convert channel location structure
87
+ % ----------------------------------
88
+ disp('Importing channel location information');
89
+ for index = 1:length(chanstruct)
90
+ EEG.chanlocs(index).labels = chanstruct(index).Name;
91
+ if chanstruct(index).Radius ~= 0
92
+ EEG.chanlocs(index).sph_theta_besa = chanstruct(index).Theta;
93
+ EEG.chanlocs(index).sph_phi_besa = chanstruct(index).Phi;
94
+ EEG.chanlocs(index).sph_radius = chanstruct(index).Radius;
95
+ else
96
+ EEG.chanlocs(index).sph_theta_besa = [];
97
+ EEG.chanlocs(index).sph_phi_besa = [];
98
+ EEG.chanlocs(index).sph_radius = [];
99
+ end;
100
+ end;
101
+ EEG.chanlocs = convertlocs(EEG.chanlocs, 'sphbesa2all');
102
+ EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_theta_besa');
103
+ EEG.chanlocs = rmfield(EEG.chanlocs, 'sph_phi_besa');
104
+
105
+ % convert event information
106
+ % -------------------------
107
+ disp('Importing events');
108
+ index = 0;
109
+ if isfield(bva, 'Markers')
110
+ for index1 = 1:size(bva.Markers,1)
111
+ for index2 = 0:size(bva.Markers,2)-1
112
+ if ~isempty(bva.Markers(index2*size(bva.Markers,1)+index1).Description)
113
+ index = index + 1;
114
+ EEG.event(index).type = bva.Markers(index2*size(bva.Markers,1)+index1).Description;
115
+ EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position;
116
+ EEG.event(index).Points = bva.Markers(index2*size(bva.Markers,1)+index1).Points;
117
+ try
118
+ EEG.event(index).bvatype = bva.Markers(index2*size(bva.Markers,1)+index1).Type;
119
+ EEG.event(index).description = bva.Markers(index2*size(bva.Markers,1)+index1).Description;
120
+ catch, end;
121
+ try
122
+ EEG.event(index).chan = bva.Markers(index2*size(bva.Markers,1)+index1).Chan;
123
+ catch, end;
124
+ try
125
+ EEG.event(index).channelnumber = bva.Markers(index2*size(bva.Markers,1)+index1).ChannelNumber;
126
+ catch, end;
127
+ if bva.SegmentCount > 1
128
+ EEG.event(index).epoch = index1;
129
+ EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position+(index1-1)*EEG.pnts;
130
+ else
131
+ EEG.event(index).latency = bva.Markers(index2*size(bva.Markers,1)+index1).Position;
132
+ end;
133
+ end;
134
+ end;
135
+ end;
136
+ end
137
+ EEG = eeg_checkset(EEG, 'makeur');
138
+ EEG = eeg_checkset(EEG, 'eventconsistency');
139
+
140
+ com = sprintf('EEG = pop_loadbva(''%s'');', filename);
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/pop_writebva.m ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % pop_writebva() - export EEG dataset
2
+ %
3
+ % Usage:
4
+ % >> EEG = pop_writebva(EEG); % a window pops up
5
+ % >> EEG = pop_writebva(EEG, filename);
6
+ %
7
+ % Inputs:
8
+ % EEG - eeglab dataset
9
+ % filename - file name
10
+ %
11
+ % Author: Arnaud Delorme, SCCN, INC, UCSD, 2005-
12
+
13
+ % Copyright (C) 2005, Arnaud Delorme, SCCN, INC, UCSD, arno@salk.edu
14
+ %
15
+ % This program is free software; you can redistribute it and/or modify
16
+ % it under the terms of the GNU General Public License as published by
17
+ % the Free Software Foundation; either version 2 of the License, or
18
+ % (at your option) any later version.
19
+ %
20
+ % This program is distributed in the hope that it will be useful,
21
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
22
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23
+ % GNU General Public License for more details.
24
+ %
25
+ % You should have received a copy of the GNU General Public License
26
+ % along with this program; if not, write to the Free Software
27
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28
+
29
+ function com = pop_writebva(EEG, filename);
30
+
31
+ com = '';
32
+ if nargin < 1
33
+ help pop_writebva;
34
+ return;
35
+ end;
36
+
37
+ if nargin < 2
38
+ [filename, filepath] = uiputfile('*', 'Output file');
39
+ if length( filepath ) == 0 return; end;
40
+ filename = [ filepath filename ];
41
+ end;
42
+
43
+ % remove extension if any
44
+ % -----------------------
45
+ posdot = find(filename == '.');
46
+ if ~isempty(posdot), filename = filename(1:posdot(end)-1); end;
47
+
48
+ % open output file
49
+ % ----------------
50
+ fid1 = fopen( [ filename '.vhdr' ], 'w' );
51
+ fid2 = fopen( [ filename '.vmrk' ], 'w' );
52
+ fid3 = fopen( [ filename '.dat' ], 'wb', 'ieee-le');
53
+ [ tmppath basename ] = fileparts( filename );
54
+
55
+ % write data
56
+ % ----------
57
+ for index = 1:EEG.nbchan
58
+ fwrite(fid3, EEG.data(index,:), 'float' );
59
+ end;
60
+
61
+ % write header
62
+ % ------------
63
+ fprintf(fid1, 'Brain Vision Data Exchange Header File Version 1.0\n');
64
+ fprintf(fid1, '; Data created from the EEGLAB software\n');
65
+ fprintf(fid1, '\n');
66
+ fprintf(fid1, '[Common Infos]\n');
67
+ fprintf(fid1, 'DataFile=%s\n', [ basename '.dat' ]);
68
+ if ~isempty(EEG.event)
69
+ fprintf(fid1, 'MarkerFile=%s\n', [ basename '.vmrk' ]);
70
+ end;
71
+ fprintf(fid1, 'DataFormat=BINARY\n');
72
+ fprintf(fid1, '; Data orientation: VECTORIZED=ch1,pt1, ch1,pt2..., MULTIPLEXED=ch1,pt1, ch2,pt1 ...\n');
73
+ fprintf(fid1, 'DataOrientation=VECTORIZED\n');
74
+ fprintf(fid1, 'DataType=TIMEDOMAIN\n');
75
+ fprintf(fid1, 'NumberOfChannels=%d\n', EEG.nbchan);
76
+ fprintf(fid1, 'DataPoints=%d\n', EEG.pnts*EEG.trials);
77
+ fprintf(fid1, '; Sampling interval in microseconds if time domain (convert to Hertz:\n');
78
+ fprintf(fid1, '; 1000000 / SamplingInterval) or in Hertz if frequency domain:\n');
79
+ fprintf(fid1, 'SamplingInterval=%d\n', 1000000/EEG.srate);
80
+ if EEG.trials > 1
81
+ fprintf(fid1, 'SegmentationType=MARKERBASED\n');
82
+ end;
83
+ fprintf(fid1, '\n');
84
+ fprintf(fid1, '[Binary Infos]\n');
85
+ fprintf(fid1, 'BinaryFormat=IEEE_FLOAT_32\n');
86
+ fprintf(fid1, '\n');
87
+ if ~isempty(EEG.chanlocs)
88
+ fprintf(fid1, '[Channel Infos]\n');
89
+ fprintf(fid1, '; Each entry: Ch<Channel number>=<Name>,<Reference channel name>,\n');
90
+ fprintf(fid1, '; <Resolution in microvolts>,<Future extensions..\n');
91
+ fprintf(fid1, '; Fields are delimited by commas, some fields might be omited (empty).\n');
92
+ fprintf(fid1, '; Commas in channel names are coded as "\1".\n');
93
+ for index = 1:EEG.nbchan
94
+ fprintf(fid1, 'Ch%d=%s,, \n', index, EEG.chanlocs(index).labels);
95
+ end;
96
+ fprintf(fid1, '\n');
97
+
98
+ disp('Warning: channel location were not exported to BVA (it will use default');
99
+ disp(' 10-20 BESA locations based on channel names)');
100
+ %if isfield(EEG.chanlocs, 'sph_radius')
101
+ % fprintf(fid1, '[Coordinates]\n');
102
+ % fprintf(fid1, '; Each entry: Ch<Channel number>=<Radius>,<Theta>,<Phi>\n');
103
+ % loc = convertlocs(EEG.chanlocs, 'sph2sphbesa');
104
+ % for index = 1:EEG.nbchan
105
+ % fprintf(fid1, 'Ch%d=%d,%d,%d\n', index, round(loc(index).sph_theta_besa), ...
106
+ % round(loc(index).sph_phi_besa), 0);
107
+ % end;
108
+ %end;
109
+ end;
110
+
111
+ % export event information
112
+ % ------------------------
113
+ if ~isempty(EEG.event)
114
+ fprintf(fid2, 'Brain Vision Data Exchange Marker File, Version 1.0\n');
115
+ fprintf(fid2, '; Data created from the EEGLAB software\n');
116
+ fprintf(fid2, '; The channel numbers are related to the channels in the exported file.\n');
117
+ fprintf(fid2, '\n');
118
+ fprintf(fid2, '[Common Infos]\n');
119
+ fprintf(fid2, 'DataFile=%s\n', [ basename '.dat' ]);
120
+ fprintf(fid2, '\n');
121
+ fprintf(fid2, '[Marker Infos]\n');
122
+ fprintf(fid2, '; Each entry: Mk<Marker number>=<Type>,<Description>,<Position in data points>,\n');
123
+ fprintf(fid2, '; <Size in data points>, <Channel number (0 = marker is related to all channels)>,\n');
124
+ fprintf(fid2, '; <Date (YYYYMMDDhhmmssuuuuuu)>\n');
125
+ fprintf(fid2, '; Fields are delimited by commas, some fields might be omited (empty).\n');
126
+ fprintf(fid2, '; Commas in type or description text are coded as "\1".\n');
127
+
128
+ % rename type and comments
129
+ % ------------------------
130
+ for index = 1:length(EEG.event)
131
+ EEG.event(index).comment = EEG.event(index).type;
132
+ EEG.event(index).type = 'Stimulus';
133
+ end;
134
+
135
+ % make event cell array
136
+ % ---------------------
137
+ for index = 1:EEG.trials
138
+ EEG.event(end+1).type = 'New Segment';
139
+ EEG.event(end ).latency = (index-1)*EEG.pnts+1;
140
+ end;
141
+ tmpevent = EEG.event;
142
+ [tmp latorder ] = sort( [ tmpevent.latency ] );
143
+ EEG.event = EEG.event(latorder);
144
+
145
+ % Recode boundary events
146
+ % ----------------------
147
+ bndArray = find(strcmp('boundary', {tmpevent.comment})); % Find boundary events
148
+ isDupArray = ismember([tmpevent(bndArray).latency], [tmpevent(strcmp('New Segment', {tmpevent.type})).latency]); % Find already existing New Segment events with identical latency
149
+ notduplist = bndArray(~isDupArray);
150
+ duplist = bndArray(isDupArray);
151
+ for index = 1:length(notduplist)
152
+ EEG.event(notduplist(index)).type = 'New Segment'; % Recode boundary event type
153
+ EEG.event(notduplist(index)).comment = ''; % Recode boundary event comment
154
+ end;
155
+ EEG.event(duplist) = []; % Remove duplicate New Segment events
156
+
157
+ % rename latency events
158
+ % ---------------------
159
+ time0ind = [];
160
+ for index = 1:length(EEG.event)
161
+ if mod( EEG.event(index).latency, EEG.pnts) == -EEG.xmin*EEG.srate+1
162
+ time0ind = [ time0ind index ];
163
+ end;
164
+ end;
165
+ for index = length(time0ind):-1:1
166
+ EEG.event(time0ind(index)+1:end+1) = EEG.event(time0ind(index):end);
167
+ EEG.event(time0ind(index)).type = 'Time 0';
168
+ EEG.event(time0ind(index)).comment = '';
169
+ end;
170
+
171
+ % write events
172
+ % ------------
173
+ e = EEG.event;
174
+ for index = 1:length(e)
175
+
176
+ % duration field
177
+ % --------------
178
+ if isfield(e, 'duration')
179
+ if ~isempty(e(index).duration)
180
+ tmpdur = e(index).duration;
181
+ else tmpdur = 0;
182
+ end;
183
+ else tmpdur = 0;
184
+ end;
185
+
186
+ % comment field
187
+ % -------------
188
+ if isfield(e, 'comment')
189
+ if ~isempty(e(index).comment)
190
+ tmpcom = e(index).comment;
191
+ else tmpcom = '';
192
+ end;
193
+ else tmpcom = num2str(e(index).type);
194
+ end;
195
+
196
+ fprintf(fid2, 'Mk%d=%s,%s,%d,%d,0,0\n', index, num2str(e(index).type), num2str(tmpcom), round(e(index).latency), tmpdur);
197
+ end;
198
+ end
199
+ fclose(fid1);
200
+ fclose(fid2);
201
+ fclose(fid3);
202
+
203
+ com = sprintf('pop_writebva(%s,''%s'');', inputname(1), filename);
204
+ return;
scripts/eeglab_current/eeglab14_1_1b/plugins/bva-io1.5.13/readbvconf.m ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % readbvconf() - read Brain Vision Data Exchange format configuration
2
+ % file
3
+ %
4
+ % Usage:
5
+ % >> CONF = readbvconf(pathname, filename);
6
+ %
7
+ % Inputs:
8
+ % pathname - path to file
9
+ % filename - filename
10
+ %
11
+ % Outputs:
12
+ % CONF - structure configuration
13
+ %
14
+ % Author: Andreas Widmann, University of Leipzig, 2007
15
+
16
+ % Copyright (C) 2007 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
17
+ %
18
+ % This program is free software; you can redistribute it and/or modify
19
+ % it under the terms of the GNU General Public License as published by
20
+ % the Free Software Foundation; either version 2 of the License, or
21
+ % (at your option) any later version.
22
+ %
23
+ % This program is distributed in the hope that it will be useful,
24
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ % GNU General Public License for more details.
27
+ %
28
+ % You should have received a copy of the GNU General Public License
29
+ % along with this program; if not, write to the Free Software
30
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
+
32
+ % $Id: readbvconf.m 44 2009-11-12 02:00:56Z arnodelorme $
33
+
34
+ function CONF = readbvconf(pathname, filename)
35
+
36
+ if nargin < 2
37
+ error('Not enough input arguments');
38
+ end
39
+
40
+ % Open and read file
41
+ [IN, message] = fopen(fullfile(pathname, filename), 'r');
42
+ if IN == -1
43
+ [IN, message] = fopen(fullfile(pathname, lower(filename)));
44
+ if IN == -1
45
+ error(message)
46
+ end;
47
+ end
48
+ raw={};
49
+ while ~feof(IN)
50
+ raw = [raw; {fgetl(IN)}];
51
+ end
52
+ fclose(IN);
53
+
54
+ % Remove comments and empty lines
55
+ raw(strmatch(';', raw)) = [];
56
+ raw(cellfun('isempty', raw) == true) = [];
57
+
58
+ % Find sections
59
+ sectionArray = [strmatch('[', raw)' length(raw) + 1];
60
+ for iSection = 1:length(sectionArray) - 1
61
+
62
+ % Convert section name
63
+ tmpstr = deblank(raw{sectionArray(iSection)});
64
+ fieldName = lower(tmpstr(2:end-1));
65
+ %fieldName = lower(char(strread(tmpstr(2:end), '[%s', 'delimiter', ']')));
66
+ fieldName(isspace(fieldName) == true) = [];
67
+
68
+ % Fill structure with parameter value pairs
69
+ switch fieldName
70
+ case {'commoninfos' 'binaryinfos' 'asciiinfos'}
71
+ for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1
72
+ splitArray = strfind(raw{line}, '=');
73
+ CONF.(fieldName).(lower(raw{line}(1:splitArray(1) - 1))) = raw{line}(splitArray(1) + 1:end);
74
+ end
75
+ case {'channelinfos' 'coordinates'}
76
+ for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1
77
+ splitArray = strfind(raw{line}, '=');
78
+ CONF.(fieldName)(str2double(raw{line}(3:splitArray(1) - 1))) = {raw{line}(splitArray(1) + 1:end)};
79
+ end
80
+ case {'markerinfos'} % Allow discontinuity for markers (but not channelinfos and coordinates!)
81
+ for line = sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1
82
+ splitArray = strfind(raw{line}, '=');
83
+ CONF.(fieldName)(line - sectionArray(iSection), :) = {raw{line}(splitArray(1) + 1:end) str2double(raw{line}(3:splitArray(1) - 1))};
84
+ end
85
+ if ~all(1:size(CONF.(fieldName), 1) == [CONF.(fieldName){:, 2}])
86
+ warning('Marker number discontinuity.')
87
+ end
88
+ case 'comment'
89
+ CONF.(fieldName) = raw(sectionArray(iSection) + 1:sectionArray(iSection + 1) - 1);
90
+ otherwise
91
+ fprintf('Unrecognized entry: %s\n', fieldName);
92
+ end
93
+ end
scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/README.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ v2.3 versus v2.2
2
+ - added the function adjustcylinder2.m
scripts/eeglab_current/eeglab14_1_1b/plugins/dipfit2.3/adjustcylinder2.m ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ % adjustcylinder() - Adjust 3d object coordinates to match a pair of points
2
+ %
3
+ % Usage:
4
+ % >> [x y z] = adjustcylinder( x, y, z, pos1, pos2);
5
+ %
6
+ % Inputs:
7
+ % x,y,z - 3-D point coordinates
8
+ % pos1 - position of first point [x y z]
9
+ % pos2 - position of second point [x y z]
10
+ %
11
+ % Outputs:
12
+ % x,y,z - updated 3-D point coordinates
13
+ %
14
+ % Author: Arnaud Delorme, CNL / Salk Institute, 30 Mai 2003
15
+
16
+ % Copyright (C) 2003 Arnaud Delorme
17
+ %
18
+ % This program is free software; you can redistribute it and/or modify
19
+ % it under the terms of the GNU General Public License as published by
20
+ % the Free Software Foundation; either version 2 of the License, or
21
+ % (at your option) any later version.
22
+ %
23
+ % This program is distributed in the hope that it will be useful,
24
+ % but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ % GNU General Public License for more details.
27
+ %
28
+ % You should have received a copy of the GNU General Public License
29
+ % along with this program; if not, write to the Free Software
30
+ % Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31
+
32
+ function [x, y, z] = adjustcylinder2( h, pos1, pos2);
33
+
34
+ % figure; plot3(x(2,:),y(2,:),z(2,:)); [ x(2,:)' y(2,:)' z(2,:)']
35
+
36
+ % stretch z coordinates to match for vector length
37
+ % ------------------------------------------------
38
+ dist = sqrt(sum((pos1-pos2).^2));
39
+ z = get(h, 'zdata');
40
+ zrange = max(z(:)) - min(z(:));
41
+ set(h, 'zdata', get(h, 'zdata') /zrange*dist);
42
+
43
+ % rotate in 3-D to match vector angle [0 0 1] -> vector angle)
44
+ % only have to rotate in the x-z and y-z plane
45
+ % --------------------------------------------
46
+ vectrot = [ pos2(1)-pos1(1) pos2(2)-pos1(2) pos2(3)-pos1(3)];
47
+ [thvect phivect] = cart2sph( vectrot(1), vectrot(2), vectrot(3) );
48
+
49
+ rotatematlab(h, [0 0 1], thvect/pi*180, [0 0 0]);
50
+ rotatematlab(h, [thvect+pi/2 0]/pi*180, (pi/2-phivect)/pi*180, [0 0 0]);
51
+
52
+ x = get(h, 'xdata') + pos1(1);
53
+ y = get(h, 'ydata') + pos1(2);
54
+ z = get(h, 'zdata') + pos1(3);
55
+
56
+ set(h, 'xdata', x);
57
+ set(h, 'ydata', y);
58
+ set(h, 'zdata', z);
59
+ return;
60
+