-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfun_CDL_Train.m
55 lines (42 loc) · 1.07 KB
/
fun_CDL_Train.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
function [eigvector, eigvalue, elapse] = fun_CDL_Train(options,gnd,data)
options.ReguAlpha = 0.01;
K = data;
clear data;
K = max(K,K');
% ====== Initialization
nSmp = size(K,1);%得到的结果是150
if length(gnd) ~= nSmp
error('gnd and data mismatch!');
end
classLabel = unique(gnd);
nClass = length(classLabel);
Dim = nClass - 1;
K_orig = K;
sumK = sum(K,2);
H = repmat(sumK./nSmp,1,nSmp);
K = K - H - H' + sum(sumK)/(nSmp^2);
K = max(K,K');
clear H;
%======================================
% SVD奇异值分解
%======================================
Hb = zeros(nClass,nSmp);
for i = 1:nClass,
index = find(gnd==classLabel(i));
classMean = mean(K(index,:),1);
Hb (i,:) = sqrt(length(index))*classMean;
end
B = Hb'*Hb;
T = K*K;
for i=1:size(T,1)
T(i,i) = T(i,i) + options.ReguAlpha;
end
B = double(B);
T = double(T);
B = max(B,B');
T = max(T,T');
option = struct('disp',0);
[eigvector, eigvalue] = eigs(B,T,Dim,'la',option);
eigvalue = diag(eigvalue);
tmpNorm = sqrt(sum((eigvector'*K_orig).*eigvector',2));
eigvector = eigvector./repmat(tmpNorm',size(eigvector,1),1);