| 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_cxx . . $ `dwsys/NMF.h:20:9`! |
| 21 | |
| 22 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 23 | #include "Data.h"cxx . . $ `<file>/sys/Data.h`/ |
| 24 | #include "NMF_enums.h"cxx . . $ `<file>/dwsys/NMF_enums.h`/ |
| 25 | |
| 26 | #include "NMF_def.h"cxx . . $ `<file>/dwsys/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_paintFeaturescxx . . $ NMF_paintFeatures(e9a7224347f8c843). (NMFcxx . . $ NMF# me, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# fromFeature, integercxx . . $ integer# toFeature, integercxx . . $ integer# fromRow, integercxx . . $ integer# toRow, double minimum, double maximum, int amplitudeScale, int scaling, bool garnish); |
| 34 | |
| 35 | void NMF_paintWeightscxx . . $ NMF_paintWeights(e9a7224347f8c843). (NMFcxx . . $ NMF# me, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# fromWeight, integercxx . . $ integer# toWeight, integercxx . . $ integer# fromRow, integercxx . . $ integer# toRow, double minimum, double maximum, int amplitudeScale, int scaling, bool garnish); |
| 36 | |
| 37 | autoNMFcxx . . $ autoNMF# NMF_createcxx . . $ NMF_create(469663068419cdf5). (integercxx . . $ integer# numberOfRows, integercxx . . $ integer# numberOfColumns, integercxx . . $ integer# numberOfFeatures); |
| 38 | |
| 39 | autoNMFcxx . . $ autoNMF# NMF_createFromGeneralMatrixcxx . . $ NMF_createFromGeneralMatrix(9956bb3a75238519). (constMATVUcxx . . $ constMATVU# const& data, integercxx . . $ integer# numberOfFeatures); |
| 40 | |
| 41 | void NMF_initializeFactorizationcxx . . $ NMF_initializeFactorization(e9c21b33eb6b997f). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data, kNMF_Initializationcxx . . $ 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_mucxx . . $ NMF_improveFactorization_mu(89a9c7e72f7c3f16). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data, integercxx . . $ 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_alscxx . . $ NMF_improveFactorization_als(89a9c7e72f7c3f16). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data, integercxx . . $ 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_iscxx . . $ NMF_improveFactorization_is(89a9c7e72f7c3f16). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data, integercxx . . $ integer# maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info); |
| 75 | |
| 76 | autoMATcxx . . $ autoMAT# NMF_synthesizecxx . . $ NMF_synthesize(6203de67d1c8b2d). (NMFcxx . . $ NMF# me); // result = features * weights |
| 77 | |
| 78 | double NMF_getEuclideanDistancecxx . . $ NMF_getEuclideanDistance(70542c4bab143328). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data); // sqrt (||data - features*weights||²) |
| 79 | |
| 80 | double NMF_getItakuraSaitoDivergencecxx . . $ NMF_getItakuraSaitoDivergence(70542c4bab143328). (NMFcxx . . $ NMF# me, constMATVUcxx . . $ constMATVU# const& data); |
| 81 | |
| 82 | #endif /* _NMF_h_ */ |