the-xiaohuichen
/
Statistically-Optimal--means-Clustering-via-Nonnegative-Low-rank-Semidefinite-Programming.
Public
forked from Yubo02/Statistically-Optimal-K-means-Clustering-via-Nonnegative-Low-rank-Semidefinite-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NNMF_cluster.m
44 lines (29 loc) · 807 Bytes
/
NNMF_cluster.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
function U_out = NNMF_cluster(X,K)
%% Initialization
n = size(X,2); % Sample size
nmX = norm(X,'fro'); % Norm of matrix X
r = 2*K; % Rank of the matrix in NNMF
alpha = 1e-6; % Step size
tol = 1e-6; % Tolerance of stopping criteria
maxiter = 50000; % Maximum of iterations
% Projection operator
proj = @(V) max(V,0) ;
%% Gradient of function
grad = @(U) -4*X'*(X*U) + 4*U*(U'*U);
%% Implement algorithm
U_p = abs(randn(n,r)); U = U_p/norm(U_p,'fro')*nmX; % Random intialization
for iter = 1:maxiter
G = grad(U);
Unew = proj(U - alpha*G);
% Evaluate iterate
rdiff = norm(Unew - U,'fro')/norm(U,'fro');
% Update the variable
U = Unew;
% Stopping criteria
if rdiff<tol
break
end
end
% Output matrix
U_out = U;
end