-
Notifications
You must be signed in to change notification settings - Fork 0
/
SNMF.m
48 lines (41 loc) · 1016 Bytes
/
SNMF.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
function [ H,objj ] = SNMF(X, K, H_init, maxIter, epsilon)
% Symmetric Non-Negtive Matrix Factorization
% INPUT:
% X: the adjacency matrix of a network
% K: the number of hidden factors
% maxIter: the maximal number of iterations for alternating minimization
% epsilon: the convergence parameter
%
% OUTPUT:
% H: the factor matirx
% objj: the value of objective function
%
% Peizhuo Wang (wangpeizhuo_37@163.com)
%% Normalize the network
X = X/sqrt(trace(X'*X));
%% Initializaiton
N = size(X,1);
if isempty(H_init)
H = rand(N,K);
else
H = H_init;
end
H = H/sqrt(trace(H'*H));
obj_old = norm(X - H*H', 'fro')^2;
beta = 0.5;
objj = obj_old;
%% Alternating update
for iter = 1:maxIter
temp_1 = X*H;
temp_2 = (H')*H;
temp_2 = H*temp_2;
H = H.*(1 - beta + beta*(temp_1./(temp_2+eps)));
obj = norm(X - H*H', 'fro')^2;
Delta = obj_old - obj;
obj_old = obj;
objj = [objj, obj];
if Delta < epsilon
break;
end
end
end