Skip to content

Commit b12cd8a

Browse files
committed
Support for multiple target matrices in FETPF
1 parent 4e6ffe8 commit b12cd8a

File tree

1 file changed

+51
-10
lines changed
  • src/+datools/+statistical/+ensemble

1 file changed

+51
-10
lines changed

src/+datools/+statistical/+ensemble/FETPF.m

+51-10
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@
2525
[email protected](varargin{1}, kept);
2626

2727
obj.B = s.B;
28-
obj.Bsqrt = sqrtm(s.B);
28+
if iscell(obj.B)
29+
Bs = cell(numel(obj.B), 1);
30+
for i = 1:numel(obj.B)
31+
Bs{i} = sqrtm(obj.B{i});
32+
end
33+
obj.Bsqrt = Bs;
34+
else
35+
obj.Bsqrt = sqrtm(s.B);
36+
end
2937
obj.SurrogateEnsN = s.SurrogateEnsembleSize;
3038
obj.Laplace = s.Laplace;
3139

@@ -54,19 +62,52 @@ function analysis(obj, R, y)
5462
xfm = mean(xf, 2);
5563
Af = xf - xfm;
5664

57-
Covsqrt = (1/sqrt(ensN - 1)*Af);
58-
Bsqrtf = obj.Bsqrt;
59-
60-
s = svd(Bsqrtf\Covsqrt);
61-
trC = sum(s.^2);
62-
tr2C = trC*trC;
63-
trC2 = sum(s.^4);
64-
6565
n = size(xf, 1);
6666

67+
Covsqrt = (1/sqrt(ensN - 1)*Af);
68+
Bsqrtf_all = obj.Bsqrt;
6769

6870
NN = ensN - 1;
69-
gamma = min(1, ((NN - 2)/NN * trC2 + tr2C)/((NN + 2)*(trC2 - tr2C/n)));
71+
72+
if iscell(Bsqrtf_all)
73+
74+
Bi = 0;
75+
Uhopt = inf;
76+
77+
for i = 1:numel(Bsqrtf_all)
78+
Bsqrtfi = Bsqrtf_all{i};
79+
s = svd(Bsqrtfi\Covsqrt);
80+
trC = sum(s.^2);
81+
tr2C = trC*trC;
82+
trC2 = sum(s.^4);
83+
84+
% calculate sphericity
85+
Uh = (n*trC2/tr2C - 1)/(n - 1);
86+
87+
if Uh < Uhopt
88+
Uhopt = Uh;
89+
Bi = i;
90+
end
91+
92+
end
93+
Bsqrtf = Bsqrtf_all{Bi};
94+
95+
else
96+
Bsqrtf = Bsqrtf_all;
97+
s = svd(Bsqrtf\Covsqrt);
98+
trC = sum(s.^2);
99+
tr2C = trC*trC;
100+
trC2 = sum(s.^4);
101+
102+
% calculate sphericity
103+
Uhopt = (n*trC2/tr2C - 1)/(n - 1);
104+
end
105+
106+
gamma = min((NN - 2)/(NN*(NN + 2)) + ((n + 1)*NN - 2)/(Uhopt*NN*(NN + 2)*(n - 1)), 1);
107+
108+
if M == 0
109+
gamma = 0;
110+
end
70111
mu = trC/n;
71112

72113
%mu = sum(s1.^2)/sum(s2.^2);

0 commit comments

Comments
 (0)