-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathhyperNmfMDC.m
More file actions
82 lines (72 loc) · 2.28 KB
/
hyperNmfMDC.m
File metadata and controls
82 lines (72 loc) · 2.28 KB
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
%% Minimum distant constraint for
% nonnegative matrix factorization
function [ W, H, H_r, E] = hyperNmfMDC(...
V, N, W_I, H_I, ...
lamda0, lamda1,...
Tolerance, IterMax)
% W,H: output for factorized matrixs
% V: original lined hyper data with some bands
% N: endmember number
% alpha0: distance constraint factor
% alpha1: sum to 1 constraint factor
% Tolerance: max error when to stop iteration
% InterMax: max interation number for stop iteration
%% start process
M = eye(N);
M(N, :) = [1, zeros(1, N-1)];
P = M' + M;
I = eye(N);
[ row_V, col_V ] = size( V );
V = [ V, lamda1*ones(row_V, 1) ];
W = W_I;
% sum_W = sum(W, 2);
% for i = 1:row_V
% W(i, :) = W(i, :) ./ sum_W(i);
% end
H = H_I;
H = [ H lamda1*ones(N,1) ];
% record iteration for H
H_record = zeros(N, IterMax, col_V);
% calculate linear least square error
E = zeros(1, IterMax);
e = (V - (W * H));
e_sum = sum( sum( e.^2 ) );
iter_cur = 1;
E(1, iter_cur) = e_sum;
for i = 1:N
H_record(i, iter_cur, :) = H(i, 1:col_V);
end
% start iteration
while( e_sum > Tolerance )
if( iter_cur == IterMax )
break;
end
% update H
normi = (W' * V) + (lamda0 * P * H);
denormi = ( (W' * W) + (2*lamda0 * I) ) * H;
update_factor = normi ./ denormi;
H = H .* update_factor;
H( :,col_V+1 ) = lamda1 * ones( N, 1 );
% update W
normi = V * H';
denormi = W * H * H';
update_factor = normi ./ denormi;
W = W .* update_factor;
% calculate error
e = (V - ( W * H ));
e_sum = sum( sum( e.^2 ) );
disp_str = [ '[' num2str(iter_cur), ']', ...
' Loss: ' num2str(e_sum), ...
' Initial Distance: ' num2str( norm(H_I - M*H_I, 'fro') ), ...
' Estimate Distance: ' num2str( norm(H - M*H, 'fro') ) ];
disp(disp_str);
iter_cur = iter_cur + 1;
E(1, iter_cur) = e_sum;
for i = 1:N
H_record(i, iter_cur, :) = H(i, 1:col_V);
end
end
H = H( :,1:col_V );
H_r = H_record(:, 1:iter_cur, :);
E = E(1, 1:iter_cur);
end