-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDR_nmf.m
32 lines (31 loc) · 879 Bytes
/
DR_nmf.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
function [P,Z] = DR_nmf(X,k,maxiter)
%%%%%%% objective
% min{P,Z}||X-PZ||^2, P,Z>=0
% You only need to provide the above three inputs.
% Notation:
% X ... (m x n) Normalized scRNA-seq data matrix
% Winit ... Initial value of P
% Hinit ... Initial value of Z
% maxiter ... The maximum number of iterations
%%%%Output:
% P ... Project matrix
% Z ... Feature matrix
tol1=1e-5;
iter = 0;
converged = 0;
%% Initialization
[U,vV,D]=svds(X,k);
P=abs(U*sqrt(vV));
Z=abs(sqrt(vV)*D');
while ~converged && iter < maxiter
iter = iter + 1;
%%%%%%%===========Update variables P,Z by iteration================
P=P.*((X*Z')./(P*Z*Z'+eps));
Z=Z.*((P'*X)./(P'*P*Z+eps));
%%%%%%%%%%%%%%%===========Error===========
temp1 = norm((X - P*Z),'fro');
if temp1 < tol1
converged = 1;
end
end
end