| 1 |
/* NMF.h |
| 2 |
* |
| 3 |
* Copyright (C) 2019 David Weenink |
| 4 |
* |
| 5 |
* This code is free software; you can redistribute it and/or modify |
| 6 |
* it under the terms of the GNU General Public License as published by |
| 7 |
* the Free Software Foundation; either version 2 of the License, or (at |
| 8 |
* your option) any later version. |
| 9 |
* |
| 10 |
* This code is distributed in the hope that it will be useful, but |
| 11 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 |
* General Public License for more details. |
| 14 |
* |
| 15 |
* You should have received a copy of the GNU General Public License |
| 16 |
* along with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef _NMF_h_ |
| 20 |
#define _NMF_h_ |
| 21 |
|
| 22 |
#include "NUM2.h" |
| 23 |
#include "Data.h" |
| 24 |
#include "NMF_enums.h" |
| 25 |
|
| 26 |
#include "NMF_def.h" |
| 27 |
|
| 28 |
/* |
| 29 |
Non-negative Matrix Factorization. I.e. we try to factorize a non-negative nrow x ncol matrix M as H*W, |
| 30 |
where H and W are non-negative nrow x k and k x ncol matrices, respectively. |
| 31 |
*/ |
| 32 |
|
| 33 |
void NMF_paintFeatures (NMF me, Graphics g, integer fromFeature, integer toFeature, integer fromRow, integer toRow, double minimum, double maximum, int amplitudeScale, int scaling, bool garnish); |
| 34 |
|
| 35 |
void NMF_paintWeights (NMF me, Graphics g, integer fromWeight, integer toWeight, integer fromRow, integer toRow, double minimum, double maximum, int amplitudeScale, int scaling, bool garnish); |
| 36 |
|
| 37 |
autoNMF NMF_create (integer numberOfRows, integer numberOfColumns, integer numberOfFeatures); |
| 38 |
|
| 39 |
autoNMF NMF_createFromGeneralMatrix (constMATVU const& data, integer numberOfFeatures); |
| 40 |
|
| 41 |
void NMF_initializeFactorization (NMF me, constMATVU const& data, kNMF_Initialization initializationMethod); |
| 42 |
|
| 43 |
/* |
| 44 |
Factorize D as F*W, where D, F and W >= 0 |
| 45 |
|
| 46 |
initialize F and W; |
| 47 |
for iter to maxiter |
| 48 |
W(n+1) = W(n).(F(n)'*D) / (F(n)'*F(n))*W(n) + eps) |
| 49 |
F(n+1) = F(n).(D*W(n+1)') / (F(n)*(W(n+1)*W(n+1)') + eps) |
| 50 |
endfor |
| 51 |
*/ |
| 52 |
void NMF_improveFactorization_mu (NMF me, constMATVU const& data, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info); |
| 53 |
|
| 54 |
/* |
| 55 |
Factorize D as F*W, where D, F and W >= 0 |
| 56 |
|
| 57 |
initialize F; |
| 58 |
for iter to maxiter |
| 59 |
W is solution of F´*F*W = F'*D. |
| 60 |
Set all negative elements in W to 0. |
| 61 |
F is solution of W*W'*F' = W*D' . |
| 62 |
Set all negative elements in F to 0. |
| 63 |
endfor |
| 64 |
*/ |
| 65 |
void NMF_improveFactorization_als (NMF me, constMATVU const& data, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info); |
| 66 |
|
| 67 |
|
| 68 |
/* |
| 69 |
Factorize D as F*W, where D, F and W >= 0. |
| 70 |
|
| 71 |
C. Févotte, N. Berin & J.-L. Durrieu (2009), Nonnegative matrix facorization with the Itakura-Saito divergene: with |
| 72 |
applications to music analysis, Neural Computation 21, 793--830. |
| 73 |
*/ |
| 74 |
void NMF_improveFactorization_is (NMF me, constMATVU const& data, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info); |
| 75 |
|
| 76 |
autoMAT NMF_synthesize (NMF me); // result = features * weights |
| 77 |
|
| 78 |
double NMF_getEuclideanDistance (NMF me, constMATVU const& data); // sqrt (||data - features*weights||²) |
| 79 |
|
| 80 |
double NMF_getItakuraSaitoDivergence (NMF me, constMATVU const& data); |
| 81 |
|
| 82 |
#endif /* _NMF_h_ */ |