-
Notifications
You must be signed in to change notification settings - Fork 6
/
BDR_solver.m
58 lines (46 loc) · 1.21 KB
/
BDR_solver.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
function [B,Z] = BDR_solver(X,k,lambda,gamma)
% Written by Canyi Lu ([email protected])
%
% References:
% Canyi Lu, Jiashi Feng, Tao Mei, Zhouchen Lin and Shuicheng Yan
% Subspace Clustering by Block Diagonal Representation,
% IEEE Transactions on Pattern Analysis and Machine Intelligence, 2019
%
% min_{Z,B,W} 0.5*||X-XZ||_F^2+0.5*lambda*||Z-B||_F^2+gamma*<Diag(B1)-B,W>
% s.t. diag(B)=0, B>=0, B=B^T,
% 0<=W<=I, Tr(W)=k.
n = size(X,2);
tol = 1e-3;
maxIter = 1000;
one = ones(n,1);
XtX = X'*X;
I = eye(n);
invXtXI = I/(XtX+lambda*I);
gammaoverlambda = gamma/lambda;
Z = zeros(n);
W = Z;
B = Z;
iter = 0;
while iter < maxIter
iter = iter + 1;
% update Z
Zk = Z;
Z = invXtXI*(XtX+lambda*B);
% update B
Bk = B;
B = Z-gammaoverlambda*(repmat(diag(W),1,n)-W);
B = max(0,(B+B')/2);
B = B-diag(diag(B));
L = diag(B*one)-B;
% update W
[V, D] = eig(L);
D = diag(D);
[~, ind] = sort(D);
W = V(:,ind(1:k))*V(:,ind(1:k))';
diffZ = max(max(abs(Z-Zk)));
diffB = max(max(abs(B-Bk)));
stopC = max([diffZ,diffB]);
if stopC < tol
break;
end
end