-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorzNPLDA.m
More file actions
54 lines (47 loc) · 1.25 KB
/
orzNPLDA.m
File metadata and controls
54 lines (47 loc) · 1.25 KB
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
function [T] = orzNPLDA(X,nK,nA)
% nK = 3;
% nA = 2;
[nDim,nNum,nClass] = size(X);
SW = zeros(nDim,nDim,nClass);
for iClass1 = 1:nClass
X1 = X(:,:,iClass1);
SW(:,:,iClass1) = cov(X1',1);
end
SW = mean(SW,3);
[B C] = eig(SW);
G = sqrt(inv(C))*B';
X = orzTransform(G,X);
W = zeros(nClass,nNum);
for iClass1 = 1:nClass
X1 = X(:,:,iClass1);
D = orzL2Distance(X1,X1);
[S ind] = sort(D,'ascend');
N = ind(2:nK+1,:);
M = squeeze(mean(reshape(X(:,N),nDim,nK,nNum),2));
Y = X1-M;
W(iClass1,:) = sqrt(sum(Y.^2,1));
end
SB = zeros(nDim,nDim);
for iClass1 = 1:nClass
iClass1
for iClass2 = 1:nClass
if iClass1 ~= iClass2
X1 = X(:,:,iClass1);
X2 = X(:,:,iClass2);
D = orzL2Distance(X1,X2);
[S ind] = sort(D,'ascend');
N = ind(1:nK,:);
M = squeeze(mean(reshape(X(:,N),nDim,nK,nNum),2));
Y = X1-M;
B = sqrt(sum(Y.^2,1));
WW = W(iClass1,:).^nA;
BB = B.^nA;
Y = Y*diag(min([WW;BB])./(WW+BB));
SB = SB + Y*Y'/nNum;
end
end
end
[E F] = eig(SB);
[F,ind] = sort(diag(F),'descend');
E = E(:,ind);
T = (E'*G)';