-
Notifications
You must be signed in to change notification settings - Fork 7
/
bf_features_regmulticov.m
80 lines (59 loc) · 1.84 KB
/
bf_features_regmulticov.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
function res = bf_features_regmulticov(BF, S)
% Simple covariance computation with regularization
%
% Mark Woolrich
%--------------------------------------------------------------------------
if nargin == 0
regmulticov = cfg_const;
regmulticov.tag = 'regmulticov';
regmulticov.name = 'Regularized multiple covariance';
regmulticov.val = {0};
res = regmulticov;
return
elseif nargin < 2
error('Two input arguments are required');
end
D = BF.data.D;
ntrials = length(S.trials);
classchanind = find(strcmp(D.chanlabels,'Class')); %MWW
if ~isempty(classchanind)
NK = max(squash(D(classchanind,:,:)));
else
NK = 1;
end
for k = 1:NK
YY = 0;
ns = 0;
spm('Pointer', 'Watch');drawnow;
spm_progress_bar('Init', ntrials, 'Computing covariance'); drawnow;
if ntrials > 100, Ibar = floor(linspace(1, ntrials,100));
else Ibar = 1:ntrials; end
num_of_invalid_covs=0;
for i = 1:ntrials,
if ~isempty(classchanind)
sampleind = S.samples(D(classchanind, S.samples, S.trials(i)) == k);
else
sampleind = S.samples;
end
nsamps = length(sampleind);
if(nsamps>1)
Y = D(S.channels, sampleind, S.trials(i));
Y = detrend(Y', 'constant');
YY = YY+(Y'*Y);
ns = ns + nsamps - 1;
else
num_of_invalid_covs=num_of_invalid_covs+1;
end;
if ismember(i, Ibar),
spm_progress_bar('Set', i); drawnow;
end
end
spm_progress_bar('Clear');
if(ntrials-num_of_invalid_covs < 10),
warning(['Only ' num2str(ntrials-num_of_invalid_covs) ' valid trial covariances for class ' num2str(k)]);
end;
C = YY/ns;
features.C{k} = C;
features.N{k} = ns;
end
res = features;