Debian Codegraph @

dwtools/Matrix_and_NMF.cpp

raw symbols SCIP
1 /* Matrix_and_NMF.cpp
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 #include "Matrix_and_NMF.h"
20 #include "NUM2.h"
21
22 autoNMF Matrix_to_NMF_mu (Matrix me, integer numberOfFeatures, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, kNMF_Initialization initializationMethod, bool info) {
23 try {
24 autoNMF thee = NMF_createFromGeneralMatrix (my z.get(), numberOfFeatures);
25 NMF_initializeFactorization (thee.get(), my z.get(), initializationMethod);
26 NMF_improveFactorization_mu (thee.get(), my z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
27 return thee;
28 } catch (MelderError) {
29 Melder_throw (me, U": NMF cannot be created.");
30 }
31 }
32
33 autoNMF Matrix_to_NMF_als (Matrix me, integer numberOfFeatures, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, kNMF_Initialization initializationMethod, bool info) {
34 try {
35 autoNMF thee = NMF_createFromGeneralMatrix (my z.get(), numberOfFeatures);
36 NMF_initializeFactorization (thee.get(), my z.get(), initializationMethod);
37 NMF_improveFactorization_als (thee.get(), my z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
38 return thee;
39 } catch (MelderError) {
40 Melder_throw (me, U": NMF cannot be created.");
41 }
42 }
43
44 autoNMF Matrix_to_NMF_is (Matrix me, integer numberOfFeatures, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, kNMF_Initialization initializationMethod, bool info) {
45 try {
46 autoNMF thee = NMF_createFromGeneralMatrix (my z.get(), numberOfFeatures);
47 NMF_initializeFactorization (thee.get(), my z.get(), initializationMethod);
48 NMF_improveFactorization_is (thee.get(), my z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
49 return thee;
50 } catch (MelderError) {
51 Melder_throw (me, U": NMF cannot be created.");
52 }
53 }
54
55 autoMatrix NMF_to_Matrix (NMF me) {
56 try {
57 autoMatrix thee = Matrix_createSimple (my numberOfRows, my numberOfColumns);
58 autoMAT result = NMF_synthesize (me);
59 thy z.all() <<= result.all();
60 return thee;
61 } catch (MelderError) {
62 Melder_throw (me, U": Matrix not created.");
63 }
64 }
65
66 void NMF_Matrix_improveFactorization_mu (NMF me, Matrix thee, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info) {
67 Melder_require (my numberOfRows == thy ny && my numberOfColumns == thy nx,
68 U"The dimensions of the NMF and the Matrix must match.");
69 NMF_improveFactorization_mu (me, thy z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
70 }
71
72 void NMF_Matrix_improveFactorization_als (NMF me, Matrix thee, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info) {
73 Melder_require (my numberOfRows == thy ny && my numberOfColumns == thy nx,
74 U"The dimensions of the NMF and the Matrix must match.");
75 NMF_improveFactorization_als (me, thy z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
76 }
77
78 void NMF_Matrix_improveFactorization_is (NMF me, Matrix thee, integer maximumNumberOfIterations, double changeTolerance, double approximationTolerance, bool info) {
79 Melder_require (my numberOfRows == thy ny && my numberOfColumns == thy nx,
80 U"The dimensions of the NMF and the Matrix must match.");
81 NMF_improveFactorization_is (me, thy z.get(), maximumNumberOfIterations, changeTolerance, approximationTolerance, info);
82 }
83
84 /* End of file Matrix_and_NMF.cpp */