-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGNMF.m
97 lines (81 loc) · 2.35 KB
/
GNMF.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
function [U_final, V_final, nIter_final, objhistory_final] = GNMF(X, k, W, options, U, V)
% Graph regularized Non-negative Matrix Factorization (GNMF)
%
% where
% X
% Notation:
% X ... (mFea x nSmp) data matrix
% mFea ... number of words (vocabulary size)
% nSmp ... number of documents
% k ... number of hidden factors
% W ... weight matrix of the affinity graph
%
% options ... Structure holding all settings
% options.alpha ... the regularization parameter.
% [default: 100]
% alpha = 0, GNMF boils down to the ordinary NMF.
%
%
% You only need to provide the above four inputs.
%
% X = U*V'
%
% References:
% [1] Deng Cai, Xiaofei He, Xiaoyun Wu, and Jiawei Han. "Non-negative
% Matrix Factorization on Manifold", Proc. 2008 Int. Conf. on Data Mining
% (ICDM'08), Pisa, Italy, Dec. 2008.
%
% [2] Deng Cai, Xiaofei He, Jiawei Han, Thomas Huang. "Graph Regularized
% Non-negative Matrix Factorization for Data Representation", IEEE
% Transactions on Pattern Analysis and Machine Intelligence, , Vol. 33, No.
% 8, pp. 1548-1560, 2011.
%
%
% version 2.0 --April/2009
% version 1.0 --April/2008
%
% Written by Deng Cai (dengcai AT gmail.com)
%
if min(min(X)) < 0
error('Input should be nonnegative!');
end
if ~isfield(options,'error')
options.error = 1e-5;
end
if ~isfield(options, 'maxIter')
options.maxIter = [];
end
if ~isfield(options,'nRepeat')
options.nRepeat = 10;
end
if ~isfield(options,'minIter')
options.minIter = 30;
end
if ~isfield(options,'meanFitRatio')
options.meanFitRatio = 0.1;
end
if ~isfield(options,'alpha')
options.alpha = 100;
end
nSmp = size(X,2);
if isfield(options,'alpha_nSmp') && options.alpha_nSmp
options.alpha = options.alpha*nSmp;
end
if isfield(options,'weight') && strcmpi(options.weight,'NCW')
feaSum = full(sum(X,2));
D_half = X'*feaSum;
X = X*spdiags(D_half.^-.5,0,nSmp,nSmp);
end
if ~isfield(options,'Optimization')
options.Optimization = 'Multiplicative';
end
if ~exist('U','var')
U = [];
V = [];
end
switch lower(options.Optimization)
case {lower('Multiplicative')}
[U_final, V_final, nIter_final, objhistory_final] = GNMF_Multi(X, k, W, options, U, V);
otherwise
error('optimization method does not exist!');
end