Debian Codegraph @

dwtools/HMM.h

raw
1 #ifndef _HMM_h_
2 #define _HMM_h_
3 /* HMM.h
4 *
5 * Copyright (C) 2010-2019, 2023 David Weenink
6 *
7 * This code is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This code is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this work. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "Strings_extensions.h"
22 #include "TableOfReal.h"
23 #include "Collection.h"
24 #include "GaussianMixture.h"
25 #include "SSCP.h"
26 #include "Index.h"
27
28
29 Thing_declare (HMMStateList);
30 Thing_declare (HMMObservationList);
31
32 #include "HMM_enums.h"
33
34 #include "HMM_def.h"
35
36 /********** class HMMStateList **********/
37
38 Collection_define (HMMStateList, OrderedOf, HMMState) {
39 };
40
41 /********** class HMMObservationList **********/
42
43 Collection_define (HMMObservationList, OrderedOf, HMMObservation) {
44 };
45
46 /********** class HMMBaumWelch **********/
47
48 Thing_define (HMMBaumWelch, Daata) {
49 integer capacity;
50 integer numberOfTimes;
51 integer totalNumberOfSequences;
52 integer numberOfStates;
53 integer numberOfSymbols;
54 double lnProb;
55 double minProb;
56 autoMAT alpha;
57 autoMAT beta;
58 autoVEC scale;
59 autoMAT gamma;
60 autoTEN3 xi;
61 autoVEC aij_num_p0;
62 autoMAT aij_num;
63 autoVEC aij_denom_p0;
64 autoMAT aij_denom;
65 autoMAT bik_num;
66 autoMAT bik_denom;
67 };
68
69 Thing_define (HMMStateSequence, Strings) {
70 };
71
72 Thing_define (HMMObservationSequence, Table) {
73 };
74 // First column is always a symbol, if only 1 column then symbols only
75
76 Collection_define (HMMObservationSequenceBag, CollectionOf, HMMObservationSequence) {
77 };
78
79 autoHMMObservationSequence HMMObservationSequence_create (integer numberOfItems, integer dataLength);
80
81 void HMMObservationSequence_removeObservation (HMMObservationSequence me, integer index);
82
83 autoStrings HMMObservationSequence_to_Strings (HMMObservationSequence me);
84
85 autoHMMObservationSequence Strings_to_HMMObservationSequence (Strings me);
86
87 autoStringsIndex HMMObservationSequence_to_StringsIndex (HMMObservationSequence me);
88
89 autoStringsIndex HMM_HMMObservationSequence_to_StringsIndex (HMM me, HMMObservationSequence thee);
90
91 autoTableOfReal HMMObservationSequence_to_TableOfReal_transitions (HMMObservationSequence me, int probabilities);
92
93 autoTableOfReal HMM_HMMObservationSequence_to_TableOfReal_transitions (HMM me, HMMObservationSequence thee, int probabilities);
94
95 integer HMMObservationSequence_getNumberOfObservations (HMMObservationSequence me);
96
97 integer HMMObservationSequenceBag_getLongestSequence (HMMObservationSequenceBag me);
98
99 autoTableOfReal HMMStateSequence_to_TableOfReal_transitions (HMMStateSequence me);
100
101 autoTableOfReal HMM_HMMStateSequence_to_TableOfReal_transitions (HMM me, HMMStateSequence thee, int probabilities);
102
103 autoHMMStateSequence HMMStateSequence_create (integer numberOfItems);
104
105 autoStrings HMMStateSequence_to_Strings (HMMStateSequence me);
106
107 void HMMState_setLabel (HMMState me, char32 *label);
108
109
110 autoHMM HMM_create (int leftToRight, integer numberOfStates, integer numberOfObservationSymbols);
111
112 autoHMM HMM_createSimple (int leftToRight, conststring32 states_string, conststring32 symbols_string);
113
114 autoHMM HMM_createContinuousModel (int leftToRight, integer numberOfStates, integer numberOfObservationSymbols,
115 integer numberOfMixtureComponentsPerSymbol, integer componentDimension, kHMMstorage componentStorage);
116
117 autoHMM HMM_createFullContinuousModel (int leftToRight, integer numberOfStates, integer numberOfObservationSymbols,
118 integer numberOfFeatureStreams, integer *dimensionOfStream, integer *numberOfGaussiansforStream);
119
120 autoHMM HMM_createFromHMMObservationSequence (HMMObservationSequence me, integer numberOfStates, int leftToRight);
121
122 void HMM_draw (HMM me, Graphics g, bool garnish);
123
124 void HMM_drawBackwardProbabilitiesIllustration (Graphics g, bool garnish);
125
126 void HMM_drawForwardProbabilitiesIllustration (Graphics g, bool garnish);
127
128 void HMM_drawForwardAndBackwardProbabilitiesIllustration (Graphics g, bool garnish);
129
130 void HMM_addObservation_move (HMM me, autoHMMObservation thee);
131
132 void HMM_addState_move (HMM me, autoHMMState thee);
133
134 void HMM_setDefaultStates (HMM me);
135
136 void HMM_setDefaultObservations (HMM me);
137
138 void HMM_setDefaultTransitionProbs (HMM me);
139
140 void HMM_setDefaultInitialStateProbs (HMM me);
141
142 void HMM_setDefaultEmissionProbs (HMM me);
143
144 void HMM_setDefaultMixingProbabilities (HMM me);
145
146 void HMM_unExpandPCA (HMM me);
147 /* Unexpand all the PCA's in the gaussian mixtures */
148
149
150
151 /*
152 Set the probabilities. A probability zero value indicates that this p cannot be changed during training/learning.
153 */
154 void HMM_setTransitionProbabilities (HMM me, integer state_number, constVECVU const& relativeProbabilities);
155
156 void HMM_setEmissionProbabilities (HMM me, integer state_number, constVECVU const& relativeProbabilities);
157
158 void HMM_setStartProbabilities (HMM me, constVECVU const& relativeProbabilities);
159
160
161 double HMM_getProbabilityAtTimeBeingInState (HMM me, integer itime, integer istate);
162
163 double HMM_getProbabilityAtTimeBeingInStateEmittingSymbol (HMM me, integer itime, integer istate, integer isymbol);
164
165 double HMM_getExpectedValueOfDurationInState (HMM me, integer istate);
166
167 double HMM_getProbabilityOfStayingInState (HMM me, integer istate, integer numberOfTimeUnits);
168
169 double HMM_HMM_getCrossEntropy (HMM me, HMM thee, integer observationLength, int symmetric);
170
171 double HMM_HMM_HMMObservationSequence_getCrossEntropy (HMM me, HMM thee, HMMObservationSequence him);
172
173 autoTableOfReal HMM_extractTransitionProbabilities (HMM me);
174
175 autoTableOfReal HMM_extractEmissionProbabilities (HMM me);
176
177 /* HMM & HMMObservationSequence ****/
178
179 autoHMMObservationSequence HMM_to_HMMObservationSequence (HMM me, integer initialState, integer numberOfItems);
180
181 autoHMMStateSequence HMM_HMMObservationSequence_to_HMMStateSequence (HMM me, HMMObservationSequence thee);
182
183 double HMM_HMMStateSequence_getProbability (HMM me, HMMStateSequence thee);
184
185 void HMM_HMMObservationSequenceBag_learn (HMM me, HMMObservationSequenceBag thee, double delta_lnp, double minProb, int info);
186
187 void HMM_HMMStateSequence_drawTrellis (HMM me, HMMStateSequence thee, Graphics g, bool connect, bool garnish);
188
189 double HMM_HMMObservationSequence_getProbability (HMM me, HMMObservationSequence thee);
190
191 double HMM_HMMObservationSequence_getCrossEntropy (HMM me, HMMObservationSequence thee);
192
193 double HMM_HMMObservationSequence_getPerplexity (HMM me, HMMObservationSequence thee);
194
195 // somewhere else
196 void MelderInfo_lnp (double logp);
197 autoTableOfReal Strings_to_TableOfReal_transitions (Strings me, int probabilities);
198
199 #endif /* _HMM_h_ */