-
Notifications
You must be signed in to change notification settings - Fork 0
/
algo_anchor.asv
79 lines (68 loc) · 1.86 KB
/
algo_anchor.asv
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
function [UU,A,Z,iter,obj] = algo_anchor(X,Y,m,lambda_1,lambda,A)
% m : the number of anchor. the size of Z is m*n.
% lambda : the hyper-parameter of regularization term.
% X : n*di
%% initplize
maxIter = 40 ; % the number of iterations
numview = length(X);
numsample = size(Y,1);
k = length(unique(Y));
e = zeros(m,numsample);
w = zeros(m,1);
M = cell(numview,1);
for i = 1:numview
X{i} = mapstd(X{i}',0,1);
end
flag = 1;
iter = 0;
%%
Z_temp = {};
while flag
iter = iter + 1;
%% optimize Z
for p = 1:numview
M{p}=zeros(1,m);
for j = 1:m
M{p}(1,j) = A{p}(:,j)'*A{p}(:,j);
end
end
G = zeros(m,m);
for p=1:numview
G = G + A{p}'*A{p};
end
G = G+lambda * eye(m);
e = zeros(m,numsample);
for i = 1:numsample
for p = 1:numview
e(:,i) = e(:,i) - (X{p}(:,i)'*A{p}- lambda_1 * M{p}*0.5)';
end
end
options = optimset( 'Algorithm','interior-point-convex','Display','off'); % Algorithm 榛樿涓? interior-point-convex
parfor i=1:numsample
Z(:,i) = quadprog(G,e(:,i),[],[],ones(1,m),1,zeros(m,1),ones(m,1),[],options);
end
%% optimize A_i
% for p = 1:numview
% A{p} = X{p}*Z'*pinv(Z*Z'+lambda_1*diag(Z*ones(numsample,1)));
% end
%%
term1 = 0;
for p = 1:numview
sum2 = 0;
temp = (A{p} *Z).^2;
temp2 = X{p}'*A{p};
for i = 1:numsample
sum2 =sum2+lambda_1 * M{p}*Z(:,i) +sum(temp(:,i)) -2 * temp2(i,:)*Z(:,i);
end
term1 = term1 + sum2;
end
for i = 1:numsample
term1 = term1 +lambda*(Z(:,i)'*Z(:,i));
end
obj(iter) = term1;
Z_temp{iter}= Z;
if (iter>9) && (abs((obj(iter-1)-obj(iter))/abs(obj(iter-1)))<1e-3 || iter>maxIter || abs(obj(iter)) < 1e-6)
[UU,~,~]=svd(Z','econ');
flag = 0;
end
end