forked from hiroyuki-kasai/NMFLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_seminmf.m
73 lines (52 loc) · 2.45 KB
/
test_seminmf.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
function test_various_nmf()
%
% demonstration file for NMFLibrary.
%
% This file illustrates how to use this library.
%
% This file is part of NMFLibrary.
%
% Created by H.Kasai on July 21, 2017
clc;
clear;
close all;
%% generate synthetic data of (mxn) matrix
m = 500;
n = 100;
V = rand(m,n);
%% Initialize of rank to be factorized
rank = 5;
%% Initialize of W and H
options = [];
[x_init.W, x_init.H] = NNDSVD(abs(V), rank, 0);
options.x_init = x_init;
options.verbose = 2;
%% perform factroization
% NMF-MU
[w_nmf_mu, infos_nmf_mu] = nmf_mu(V, rank, options);
% Semi-NMF
[w_seminmf, infos_seminmf] = semi_nmf(V, rank, options);
% nsNMF
options.theta = 0; % decides the degree in [0,1] of nonsmoothing (use 0 for standard NMF)
options.cost = 'EUC'; %- what cost function to use; 'eucl' (default) or 'kl'
[w_nsnmf, infos_nsnmf] = ns_nmf(V, rank, options);
% SparseNMF
options.lambda = 1; % decides the degree in [0,1] of nonsmoothing (use 0 for standard NMF)
options.cost = 'EUC'; %- what cost function to use; 'eucl' (default) or 'kl'
[w_sparsenmf, infos_sparsenmf] = sparse_nmf(V, rank, options);
% SparseNMF
options.lambda = 1; % decides the degree in [0,1] of nonsmoothing (use 0 for standard NMF)
options.cost = 'EUC'; %- what cost function to use; 'eucl' (default) or 'kl'
[w_nmfsc, infos_nmfsc] = nmf_sc(V, rank, options);
% Ne-NMF
%[W,H,it,ela,HIS]=NeNMF(V,reducedDim,'TYPE','L1R');
%[W,H,it,ela,HIS]=NeNMF(V,reducedDim,'TYPE','L2R');
%[W,H,it,ela,HIS]=NeNMF(V,reducedDim,'TYPE','MR','S_MTX',S);
%[w_nenmf, infos_nenmf] = NeNMF(V, rank);
% Hierarchical ALS
options.alg = 'hals';
[w_nmf_hals, infos_nmf_hals] = nmf_als(V, rank, options);
%% plot
display_graph('epoch','cost', {'NMF-MU', 'Semi-NMF', 'nsNMF', 'Sparse NMF', 'NMFsc', 'HALS'}, {w_nmf_mu, w_seminmf, w_nsnmf, w_sparsenmf, w_nmfsc, w_nmf_hals}, {infos_nmf_mu, infos_seminmf, infos_nsnmf, infos_sparsenmf, infos_nmfsc, infos_nmf_hals});
display_graph('time','cost', {'NMF-MU','Semi-NMF', 'nsNMF', 'Sparse NMF', 'NMFsc', 'HALS'}, {w_nmf_mu, w_seminmf, w_nsnmf, w_sparsenmf, w_nmfsc, w_nmf_hals}, {infos_nmf_mu, infos_seminmf, infos_nsnmf, infos_sparsenmf, infos_nmfsc, infos_nmf_hals});
end