-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinitialize_nnmf.m
37 lines (37 loc) · 1.11 KB
/
initialize_nnmf.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
function [T,S] = initialize_nnmf(Y,n,opts)
% INITIALIZE_NNMF: algorithm initializes S and T for an nnmf according to
% the parameters in opts.
%
% Input:
% Y... movie
% n... Dimensions of nnmf
% struct opts:
% opts.ini_method Initialization method:
% 'rand' initialize T as smoothed random signal
% and initialize S as S = nnls(Y,T);
% 'pca' initialize T and S as the first 'n' principal
% components
%
% Output:
% T... initial temporal components for nnmf
% S... initial spatial components for nnmf
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if numel(Y) > 1e9
Y = tall(Y);
end
if strcmp(opts.ini_method,'rand')
T=conv2(rand(n,size(Y,2)),ones(1,32),'same');
option=opts;
if ~isfield(opts,'max_iter')
option.max_iter=2000;
end
option.lambda=opts.lamb_spat;
S=LS_nnls(T',Y',option)';
elseif strcmp(opts.ini_method,'pca')
[T,S,~] = pca(Y);
T = abs(T(:,1:n))';
S = abs(S(:,1:n));
end
T = gather(T);
S = gather(S);
end