-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathicassoGet.m
executable file
·198 lines (181 loc) · 5.54 KB
/
icassoGet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
function out=icassoGet(sR,field,index)
%function out=icassoGet(sR,field,[index])
%
%PURPOSE
%
%Auxiliary function for obtaining various information from the
%Icasso result data structure. Using icassoGet, you can return
%information related to original data, e.g.: data matrix,
%(de)whitening matrix, total number of estimates, number of
%estimates on each round. You can also return specified estimated
%independent components (sources), and rows of demixing matrices
%from. (However, it is easier to use function icassoResult to return
%the final estimation results from the complete Icasso procedure.)
%
%EXAMPLES OF BASIC USAGE
%
% M=icassoGet(sR,'m');
%
%returns total number of estimates.
%
% nic=icassoGet(sR,'numOfIC')
%
%returns number of estimated IC components on each round in an Nx1
%vector (The number may differ in deflatory estimation mode due to
%convergence problems.)
%
% r=icassoGet(sR,'round',[25 17 126]);
%
%workspace variable r contains now a 3x2 matrix where the first
%column shows the number of estimation cycle. The second column
%is the order of appearance of the estimate within the cycle:
%e.g. 2 5 : estimate 25 was 5th estimate in cycle 2
% 1 17 : 17 1st 1
% 7 6 : 126 6th 7
%
% W=icassoGet(sR,'demixingmatrix',[25 17 126]);
%
%returns the demixing matrix rows for estimates 25, 17, and 126.
%
% s=icassoGet(sR,'source');
%
%returns _all_ M estimated independent components (sources), i.e.,
%estimates from all resampling cycles.
%
%INPUT
%
%[An argument in brackets is optional. If it isn't given or it's
% an empty matrix/string, the function will use a default value.]
%
% sR (struct) Icasso result data structure (from icassoEst).
% field (string) (case insensitive) determines what is returned:
% 'data' the original data centered
% 'N' the number of estimation cycles
% 'M' the total number of estimates available;
% equal to sum(icassoGet(sR,'numofic'));
% 'numofic' number of ICs extracted on each cycle (Nx1
% vector)
% 'odim' original data dimension
% 'rdim' reduced data dimension (after PCA)
% 'round' output is an Mx2 matrix that identifies from
% which estimation round each estimate
% originates:
% out(i,1) is the estimation round for
% estimate i,
% out(i,2) is the ordinal number of the
% estimate within the round.
% 'source' estimated source signals
% 'dewhitemat' dewhitening matrix for the original data
% 'whitemat' dewhitening matrix for the original data
% 'demixingmatrix' demixing matrix rows ('W' works as well)
%
% [index] (vector of integers) specifies which estimates to return
% Applies only for 'demixingmatrix', and 'source'
% Default: leaving this argument out corresponds to
% selecting all estimates, i.e., giving [1:M] as index
% vector.
%
%OUTPUT
%
% out (type and meaning vary according to input argument 'field')
%
%SEE ALSO
% icassoResult
%COPYRIGHT NOTICE
%This function is a part of Icasso software library
%Copyright (C) 2003-2005 Johan Himberg
%
%This program is free software; you can redistribute it and/or
%modify it under the terms of the GNU General Public License
%as published by the Free Software Foundation; either version 2
%of the License, or any later version.
%
%This program is distributed in the hope that it will be useful,
%but WITHOUT ANY WARRANTY; without even the implied warranty of
%MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
%GNU General Public License for more details.
%
%You should have received a copy of the GNU General Public License
%along with this program; if not, write to the Free Software
%Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
% ver 1.2 100105
M=size(sR.index,1);
if nargin<3,
index=1:M;
end
switch lower(field)
case 'm'
out=size(sR.index,1);
case 'n'
out=length(sR.A);
case 'odim'
out=size(sR.whiteningMatrix,2);
case 'rdim'
out=size(sR.whiteningMatrix,1);
case 'numofic'
for i=1:length(sR.A),
out(i,1)=size(sR.A{i},2);
end
case 'a'
out = getMixing(sR,index);
case {'w','demixingmatrix'}
out=getDeMixing(sR,index);
case 'data'
out=sR.signal;
case {'dewhitemat'}
out=sR.dewhiteningMatrix;
case {'whitemat'}
out=sR.whiteningMatrix;
case 'source'
out=getSource(sR,index);
case 'round'
out=sR.index(index,:)
otherwise
error('Unknown operation.');
end
function A=getMixing(sR,index);
%function A=getMixing(sR,index);
%
% reindex
index2=sR.index(index,:);
N=size(index2,1); A=[];
for i=1:N,
A(:,i)=sR.A{index2(i,1)}(:,index2(i,2));
end
function W=getDeMixing(sR,index);
%
%function W=getDeMixing(sR,index);
%
% reindex
index2=sR.index(index,:);
N=size(index2,1); W=[];
for i=1:N,
W(i,:)=sR.W{index2(i,1)}(index2(i,2),:);
end
function S=getSource(sR,index)
%function S=getSource(sR,index)
%
X=sR.signal;
W=getDeMixing(sR,index);
S=W*X;
%% Old stuff
%function dWh=getDeWhitening(sR,index);
%
%function dWh=getDeWhitening(sR,index);
%
%
%index=sR.index(index,:);
%Nindex=size(index,1); W=[];
%for i=1:Nindex,
% dWh(:,i)=sR.dewhiteningMatrix{1}(:,index(i,2));
%end
%function W=getWhitening(sR,index);
%
%function W=getWhitening(sR,index);
%
%
%index=sR.index(index,:);
%Nindex=size(index,1); W=[];
%for i=1:Nindex,
% W(:,i)=sR.whiteningMatrix{index(i,1)}(:,index(i,2));
%end