| 1 |
/* praat_HMM_init.cpp |
| 2 |
* |
| 3 |
* Copyright (C) 2010-2024,2026 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 3 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 "praatM.h" |
| 20 |
#include "GaussianMixture.h" |
| 21 |
#include "HMM.h" |
| 22 |
#include "Strings_extensions.h" |
| 23 |
#include "TableOfReal.h" |
| 24 |
|
| 25 |
DIRECT (HELP__GaussianMixture_help) { |
| 26 |
HELP (U"GaussianMixture") |
| 27 |
} |
| 28 |
|
| 29 |
FORM (GRAPHICS_EACH__GaussianMixture_drawConcentrationEllipses, U"GaussianMixture: Draw concentration ellipses", U"GaussianMixture: Draw concentration ellipses...") { |
| 30 |
POSITIVE (numberOfSigmas, U"Number of sigmas", U"1.0") |
| 31 |
BOOLEAN (principalComponentPlane, U"Principal component plane", true) |
| 32 |
INTEGER (xDimension, U"X-dimension", U"1") |
| 33 |
INTEGER (yDimension, U"Y-dimension", U"2") |
| 34 |
REAL (xmin, U"left Horizontal range", U"0.0") |
| 35 |
REAL (xmax, U"right Horizontal range", U"0.0") |
| 36 |
REAL (ymin, U"left Vertical range", U"0.0") |
| 37 |
REAL (ymax, U"right Vertical range", U"0.0") |
| 38 |
POSITIVE (labelSize, U"Label size", U"12") |
| 39 |
BOOLEAN (garnish, U"Garnish", true) |
| 40 |
OK |
| 41 |
DO |
| 42 |
GRAPHICS_EACH (GaussianMixture) |
| 43 |
GaussianMixture_drawConcentrationEllipses ( |
| 44 |
me, GRAPHICS, numberOfSigmas, false, nullptr, principalComponentPlane, xDimension, yDimension, |
| 45 |
xmin, xmax, ymin, ymax, labelSize, garnish |
| 46 |
); |
| 47 |
GRAPHICS_EACH_END |
| 48 |
} |
| 49 |
|
| 50 |
FORM (GRAPHICS_ONE_AND_ONE__GaussianMixture_PCA_drawConcentrationEllipses, U"GaussianMixture & PCA: Draw concentration ellipses", U"GaussianMixture & PCA: Draw concentration ellipses...") { |
| 51 |
POSITIVE (numberOfSigmas, U"Number of sigmas", U"1.0") |
| 52 |
INTEGER (xDimension, U"X-dimension", U"1") |
| 53 |
INTEGER (yDimension, U"Y-dimension", U"2") |
| 54 |
REAL (xmin, U"left Horizontal range", U"0.0") |
| 55 |
REAL (xmax, U"right Horizontal range", U"0.0") |
| 56 |
REAL (ymin, U"left Vertical range", U"0.0") |
| 57 |
REAL (ymax, U"right Vertical range", U"0.0") |
| 58 |
POSITIVE (labelSize, U"Label size", U"12") |
| 59 |
BOOLEAN (garnish, U"Garnish", true) |
| 60 |
OK |
| 61 |
DO |
| 62 |
GRAPHICS_ONE_AND_ONE (GaussianMixture, PCA) |
| 63 |
GaussianMixture_PCA_drawConcentrationEllipses ( |
| 64 |
me, you, GRAPHICS, numberOfSigmas, false, nullptr, xDimension, yDimension, xmin, xmax, |
| 65 |
ymin, ymax, labelSize, garnish |
| 66 |
); |
| 67 |
GRAPHICS_ONE_AND_ONE_END |
| 68 |
} |
| 69 |
|
| 70 |
FORM (GRAPHICS_EACH__GaussianMixture_drawMarginalPdf, U"GaussianMixture: Draw marginal pdf", U"GaussianMixture: Draw marginal pdf...") { |
| 71 |
INTEGER (xDimension, U"X-dimension", U"1") |
| 72 |
REAL (xmin, U"left Horizontal range", U"0.0") |
| 73 |
REAL (xmax, U"right Horizontal range", U"0.0") |
| 74 |
REAL (ymin, U"left Vertical range", U"0.0") |
| 75 |
REAL (ymax, U"right Vertical range", U"0.0") |
| 76 |
NATURAL (numberOfPoints, U"Number of points", U"500") |
| 77 |
INTEGER (numberOfBins, U"Number of bins", U"0.0") |
| 78 |
BOOLEAN (garnish, U"Garnish", true) |
| 79 |
OK |
| 80 |
DO |
| 81 |
GRAPHICS_EACH (GaussianMixture) |
| 82 |
GaussianMixture_drawMarginalPdf (me, GRAPHICS, xDimension, xmin, xmax, ymin, ymax, numberOfPoints, numberOfBins, garnish); |
| 83 |
GRAPHICS_EACH_END |
| 84 |
} |
| 85 |
|
| 86 |
DIRECT (QUERY_ONE_FOR_INTEGER__GaussianMixture_getNumberOfComponents) { |
| 87 |
QUERY_ONE_FOR_INTEGER (GaussianMixture) |
| 88 |
const integer result = my numberOfComponents; |
| 89 |
QUERY_ONE_FOR_INTEGER_END (U" components") |
| 90 |
} |
| 91 |
|
| 92 |
DIRECT (QUERY_ONE_FOR_INTEGER__GaussianMixture_getDimensionOfComponent) { |
| 93 |
QUERY_ONE_FOR_INTEGER (GaussianMixture) |
| 94 |
const integer result = my dimension; |
| 95 |
QUERY_ONE_FOR_INTEGER_END (U" (dimension of component)") |
| 96 |
} |
| 97 |
|
| 98 |
FORM (QUERY_ONE_FOR_REAL__GaussianMixture_getProbabilityAtPosition, U"GaussianMixture: Get probability at position", nullptr) { |
| 99 |
SENTENCE (position_string, U"Position", U"100.0 300.0") |
| 100 |
OK |
| 101 |
DO |
| 102 |
QUERY_ONE_FOR_REAL (GaussianMixture) |
| 103 |
const double result = GaussianMixture_getProbabilityAtPosition_string (me, position_string); |
| 104 |
QUERY_ONE_FOR_REAL_END (U" (probability at position ", position_string, U")") |
| 105 |
} |
| 106 |
|
| 107 |
FORM (MODIFY_GaussianMixture_splitComponent, U"GaussianMixture: Split component", U"GaussianMixture: Split component...") { |
| 108 |
NATURAL (component, U"Component", U"1") |
| 109 |
OK |
| 110 |
DO |
| 111 |
MODIFY_EACH (GaussianMixture) |
| 112 |
GaussianMixture_splitComponent (me, component); |
| 113 |
MODIFY_EACH_END |
| 114 |
} |
| 115 |
|
| 116 |
FORM (GRAPHICS_ONE_AND_ONE__GaussianMixture_PCA_drawMarginalPdf, U"GaussianMixture & PCA: Draw pdf function", U"GaussianMixture: Draw marginal pdf...") { |
| 117 |
INTEGER (xDimension, U"X-dimension", U"1") |
| 118 |
REAL (xmin, U"left Horizontal range", U"0.0") |
| 119 |
REAL (xmax, U"right Horizontal range", U"0.0") |
| 120 |
REAL (ymin, U"left Vertical range", U"0.0") |
| 121 |
REAL (ymax, U"right Vertical range", U"0.0") |
| 122 |
NATURAL (numberOfPoints, U"Number of points", U"500") |
| 123 |
INTEGER (numberOfBins, U"Number of bins", U"0.0") |
| 124 |
BOOLEAN (garnish, U"Garnish", true) |
| 125 |
OK |
| 126 |
DO |
| 127 |
GRAPHICS_ONE_AND_ONE (GaussianMixture, PCA) |
| 128 |
GaussianMixture_PCA_drawMarginalPdf (me, you, GRAPHICS, xDimension, xmin, xmax, ymin, ymax, numberOfPoints, numberOfBins, garnish); |
| 129 |
GRAPHICS_ONE_AND_ONE_END |
| 130 |
} |
| 131 |
|
| 132 |
FORM (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_PCA_to_Matrix_density, U"GaussianMixture & PCA: To Matrix density", U"GaussianMixture & PCA: To Matrix (density)...") { |
| 133 |
INTEGER (xDimension, U"X-dimension", U"1") |
| 134 |
INTEGER (yDimension, U"Y-dimension", U"2") |
| 135 |
REAL (xmin, U"left Horizontal range", U"0.0") |
| 136 |
REAL (xmax, U"right Horizontal range", U"0.0") |
| 137 |
NATURAL (numberOfColumns, U"Number of columns", U"100") |
| 138 |
REAL (ymin, U"left Vertical range", U"0.0") |
| 139 |
REAL (ymax, U"right Vertical range", U"0.0") |
| 140 |
NATURAL (numberOfRows, U"Number of rows", U"100") |
| 141 |
OK |
| 142 |
DO |
| 143 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, PCA) |
| 144 |
autoMatrix result = GaussianMixture_PCA_to_Matrix_density ( |
| 145 |
me, you, xDimension, yDimension, xmin, xmax, numberOfColumns, ymin, ymax, numberOfRows |
| 146 |
); |
| 147 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 148 |
} |
| 149 |
|
| 150 |
FORM (CONVERT_EACH_TO_ONE__GaussianMixture_extractComponent, U"GaussianMixture: Extract component", nullptr) { |
| 151 |
NATURAL (component, U"Component", U"1") |
| 152 |
OK |
| 153 |
DO |
| 154 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 155 |
autoCovariance result = GaussianMixture_extractComponent (me, component); |
| 156 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 157 |
} |
| 158 |
|
| 159 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_extractCentroids) { |
| 160 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 161 |
autoTableOfReal result = GaussianMixture_extractCentroids (me); |
| 162 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 163 |
} |
| 164 |
|
| 165 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_extractMixingProbabilities) { |
| 166 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 167 |
autoTableOfReal result = GaussianMixture_extractMixingProbabilities (me); |
| 168 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 169 |
} |
| 170 |
|
| 171 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_to_PCA) { |
| 172 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 173 |
autoPCA result = GaussianMixture_to_PCA (me); |
| 174 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 175 |
} |
| 176 |
|
| 177 |
FORM (CONVERT_EACH_TO_ONE__GaussianMixture_to_TableOfReal_randomSampling, U"GaussianMixture: To TableOfReal (random sampling)", U"GaussianMixture: To TableOfReal (random sampling)...") { |
| 178 |
NATURAL (numberOfPoints, U"Number of data points", U"100") |
| 179 |
OK |
| 180 |
DO |
| 181 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 182 |
autoTableOfReal result = GaussianMixture_to_TableOfReal_randomSampling (me, numberOfPoints); |
| 183 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 184 |
} |
| 185 |
|
| 186 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_between) { |
| 187 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 188 |
autoCovariance result = GaussianMixture_to_Covariance_between (me); |
| 189 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_b") |
| 190 |
} |
| 191 |
|
| 192 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_within) { |
| 193 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 194 |
autoCovariance result = GaussianMixture_to_Covariance_within (me); |
| 195 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_w"); |
| 196 |
} |
| 197 |
|
| 198 |
DIRECT (CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_total) { |
| 199 |
CONVERT_EACH_TO_ONE (GaussianMixture) |
| 200 |
autoCovariance result = GaussianMixture_to_Covariance_total (me); |
| 201 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_t"); |
| 202 |
} |
| 203 |
|
| 204 |
FORM (QUERY_ONE_AND_ONE_FOR_REAL__GaussianMixture_TableOfReal_getLikelihoodValue, U"GaussianMixture & TableOfReal: Get likelihood value", |
| 205 |
U"GaussianMixture & TableOfReal: Get likelihood value...") { |
| 206 |
OPTIONMENU_ENUM (kGaussianMixtureCriterion, criterion, U"Criterion based on", kGaussianMixtureCriterion::DEFAULT) OK |
| 207 |
DO |
| 208 |
QUERY_ONE_AND_ONE_FOR_REAL (GaussianMixture, TableOfReal) |
| 209 |
conststring32 criterionText = GaussianMixture_criterionText (criterion); |
| 210 |
const double lnpdn = GaussianMixture_TableOfReal_getLikelihoodValue (me, you, criterion); |
| 211 |
const double result = lnpdn / you -> numberOfRows; |
| 212 |
QUERY_ONE_AND_ONE_FOR_REAL_END (U" (= ", criterionText, U", n = ", you -> numberOfRows, U")") |
| 213 |
} |
| 214 |
|
| 215 |
DIRECT (HELP__HMM_help) { |
| 216 |
HELP (U"HMM") |
| 217 |
} |
| 218 |
|
| 219 |
FORM (CREATE_ONE__HMM_create, U"Create HMM", nullptr) { |
| 220 |
WORD (name, U"Name", U"hmm") |
| 221 |
BOOLEAN (leftToRightModel, U"Left to right model", false) |
| 222 |
NATURAL (numberOfStates, U"Number of states", U"3") |
| 223 |
NATURAL (numberOfObservations, U"Number of observations", U"3") |
| 224 |
OK |
| 225 |
DO |
| 226 |
CREATE_ONE |
| 227 |
autoHMM result = HMM_create (leftToRightModel, numberOfStates, numberOfObservations); |
| 228 |
CREATE_ONE_END (name) |
| 229 |
} |
| 230 |
|
| 231 |
FORM (CREATE_ONE__HMM_createSimple, U"HMM: Create simple", U"HMM: Create simple HMM...") { |
| 232 |
WORD (name, U"Name", U"weather") |
| 233 |
BOOLEAN (leftToRightModel, U"Left to right model", false) |
| 234 |
SENTENCE (states_string, U"States", U"Rainy Sunny") |
| 235 |
SENTENCE (observations_string, U"Observations", U"Walk Shop Clean") |
| 236 |
OK |
| 237 |
DO |
| 238 |
CREATE_ONE |
| 239 |
autoHMM result = HMM_createSimple (leftToRightModel, states_string, observations_string); |
| 240 |
CREATE_ONE_END (name) |
| 241 |
} |
| 242 |
|
| 243 |
FORM (CREATE_ONE__HMM_createContinuousModel, U"HMM: Create continuous model", nullptr) { |
| 244 |
WORD (name, U"Name", U"cm") |
| 245 |
BOOLEAN (leftToRightModel, U"Left to right model", false) |
| 246 |
NATURAL (numberOfStates, U"Number of states", U"3") |
| 247 |
NATURAL (numberOfSymbols, U"Number of symbols", U"10") |
| 248 |
COMMENT (U"For the Gaussian mixtures:") |
| 249 |
NATURAL (numberOfComponents, U"Number of components", U"3") |
| 250 |
NATURAL (componentDimension, U"Dimension of component", U"39") |
| 251 |
CHOICE_ENUM (kHMMstorage, storage, |
| 252 |
U"Covariance matrices are", kHMMstorage::DEFAULT) |
| 253 |
OK |
| 254 |
DO |
| 255 |
CREATE_ONE |
| 256 |
autoHMM result = HMM_createContinuousModel ( |
| 257 |
leftToRightModel, numberOfStates, numberOfSymbols, numberOfComponents, componentDimension, storage |
| 258 |
); |
| 259 |
CREATE_ONE_END (name) |
| 260 |
} |
| 261 |
|
| 262 |
FORM (CONVERT_EACH_TO_ONE__HMMObservationSequence_to_HMM, U"HMMObservationSequence: To HMM", nullptr) { |
| 263 |
COMMENT (U"(0 states gives a non-hidden model) ") |
| 264 |
INTEGER (numberOfHiddenStates, U"Number of hidden states", U"2") |
| 265 |
BOOLEAN (leftToRightModel, U"Left to right model", false) |
| 266 |
OK |
| 267 |
DO |
| 268 |
CONVERT_EACH_TO_ONE (HMMObservationSequence) |
| 269 |
autoHMM result = HMM_createFromHMMObservationSequence (me, numberOfHiddenStates, leftToRightModel); |
| 270 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_", numberOfHiddenStates) |
| 271 |
} |
| 272 |
|
| 273 |
FORM (GRAPHICS_EACH__HMM_draw, U"HMM: Draw", nullptr) { |
| 274 |
BOOLEAN (garnish, U"Garnish", false) |
| 275 |
OK |
| 276 |
DO |
| 277 |
GRAPHICS_EACH (HMM) |
| 278 |
HMM_draw (me, GRAPHICS, garnish); |
| 279 |
GRAPHICS_EACH_END |
| 280 |
} |
| 281 |
|
| 282 |
FORM (GRAPHICS_ONE_AND_ONE__HMM_HMMStateSequence_drawTrellis, U"HMM & Strings: Draw trellis", nullptr) { |
| 283 |
BOOLEAN (connect, U"Connect", true); |
| 284 |
BOOLEAN (garnish, U"Garnish", true); |
| 285 |
OK |
| 286 |
DO |
| 287 |
GRAPHICS_ONE_AND_ONE (HMM, HMMStateSequence) |
| 288 |
HMM_HMMStateSequence_drawTrellis (me, you, GRAPHICS, connect, garnish); |
| 289 |
GRAPHICS_ONE_AND_ONE_END |
| 290 |
} |
| 291 |
|
| 292 |
DIRECT (GRAPHICS_NONE__HMM_drawForwardProbabilitiesIllustration) { |
| 293 |
GRAPHICS_NONE |
| 294 |
HMM_drawForwardProbabilitiesIllustration (GRAPHICS, true); |
| 295 |
GRAPHICS_NONE_END |
| 296 |
} |
| 297 |
|
| 298 |
DIRECT (GRAPHICS_NONE__HMM_drawBackwardProbabilitiesIllustration) { |
| 299 |
GRAPHICS_NONE |
| 300 |
HMM_drawBackwardProbabilitiesIllustration (GRAPHICS, true); |
| 301 |
GRAPHICS_NONE_END |
| 302 |
} |
| 303 |
|
| 304 |
DIRECT (GRAPHICS_NONE__HMM_drawForwardAndBackwardProbabilitiesIllustration) { |
| 305 |
GRAPHICS_NONE |
| 306 |
HMM_drawForwardAndBackwardProbabilitiesIllustration (GRAPHICS, true); |
| 307 |
GRAPHICS_NONE_END |
| 308 |
} |
| 309 |
|
| 310 |
FORM (QUERY_ONE_FOR_REAL__HMM_getTransitionProbability, U"HMM: Get transition probability", U"HMM: Get transition probability...") { |
| 311 |
NATURAL (fromState, U"From state number", U"1") |
| 312 |
NATURAL (toState, U"To state number", U"1") |
| 313 |
OK |
| 314 |
DO |
| 315 |
QUERY_ONE_FOR_REAL (HMM) |
| 316 |
Melder_require (fromState <= my numberOfStates, |
| 317 |
U"\"From state number\" should not be larger than ", my numberOfStates, U"."); |
| 318 |
Melder_require (toState <= my numberOfStates, |
| 319 |
U"\"To state number\" should not be larger than ", my numberOfStates, U"."); |
| 320 |
const double result = my transitionProbs [fromState] [toState]; |
| 321 |
QUERY_ONE_FOR_REAL_END (U" : [ ", fromState, U", ", toState, U" ]") |
| 322 |
} |
| 323 |
|
| 324 |
FORM (QUERY_ONE_FOR_REAL__HMM_getEmissionProbability, U"HMM: Get emission probability", U"HMM: Get emission probability...") { |
| 325 |
NATURAL (fromState, U"From state number", U"1") |
| 326 |
NATURAL (symbolNumber, U"Symbol number", U"1") |
| 327 |
OK |
| 328 |
DO |
| 329 |
QUERY_ONE_FOR_REAL (HMM) |
| 330 |
Melder_require (fromState <= my numberOfStates, |
| 331 |
U"\"From state number\" should not be larger than ", my numberOfStates, U"."); |
| 332 |
Melder_require (symbolNumber <= my numberOfObservationSymbols, |
| 333 |
U"\"Symbol number\" should not be larger than ", my numberOfObservationSymbols, U"."); |
| 334 |
const double result = my emissionProbs [fromState] [symbolNumber]; |
| 335 |
QUERY_ONE_FOR_REAL_END (U" : [ ", fromState, U", ", symbolNumber, U" ]") |
| 336 |
} |
| 337 |
|
| 338 |
FORM (QUERY_ONE_FOR_REAL__HMM_getStartProbability, U"HMM: Get start probability", U"HMM: Get start probability...") { |
| 339 |
NATURAL (stateNumber, U"State number", U"1") |
| 340 |
OK |
| 341 |
DO |
| 342 |
QUERY_ONE_FOR_REAL (HMM) |
| 343 |
Melder_require (stateNumber <= my numberOfStates, |
| 344 |
U"\"State number\" should not be larger than ", my numberOfStates, U"."); |
| 345 |
const double result = my initialStateProbs [stateNumber]; |
| 346 |
QUERY_ONE_FOR_REAL_END (U" : [ ", stateNumber, U" ]") |
| 347 |
} |
| 348 |
|
| 349 |
FORM (QUERY_ONE_FOR_REAL__HMM_getProbabilityAtTimeBeingInState, U"HMM: Get probability of being in state at time", |
| 350 |
U"HMM: Get p (time, state)...") { |
| 351 |
NATURAL (timeIndex, U"Time index", U"10") |
| 352 |
NATURAL (stateNumber, U"State number", U"1") |
| 353 |
OK |
| 354 |
DO |
| 355 |
QUERY_ONE_FOR_REAL (HMM) |
| 356 |
const double result = HMM_getProbabilityAtTimeBeingInState (me, timeIndex, stateNumber); |
| 357 |
QUERY_ONE_FOR_REAL_END (U" (= ln(p), p = ", Melder_naturalLogarithm (result), U") Being in state ", stateNumber, U" at time ", timeIndex) |
| 358 |
} |
| 359 |
|
| 360 |
FORM (QUERY_ONE_FOR_REAL__HMM_getProbabilityAtTimeBeingInStateEmittingSymbol, U"HMM: get probability being at time in state emitting symbol", U"HMM: Get p (time, state, symbol)...") { |
| 361 |
NATURAL (timeIndex, U"Time index", U"10") |
| 362 |
NATURAL (stateNumber, U"State number", U"1") |
| 363 |
NATURAL (symbolNumber, U"Symbol number", U"1") |
| 364 |
OK |
| 365 |
DO |
| 366 |
QUERY_ONE_FOR_REAL (HMM) |
| 367 |
const double result = HMM_getProbabilityAtTimeBeingInStateEmittingSymbol (me, timeIndex, stateNumber, symbolNumber); |
| 368 |
QUERY_ONE_FOR_REAL_END (U" (= ln(p), p = ", Melder_naturalLogarithm (result), U") Being in state ", stateNumber, |
| 369 |
U" emitting symbol ", symbolNumber, U" at time ", timeIndex) |
| 370 |
} |
| 371 |
|
| 372 |
FORM (QUERY_ONE_FOR_REAL__HMM_getProbabilityOfStayingInState, U"HMM: Get probability of staying in state", U"HMM: Get probability staying in state...") { |
| 373 |
NATURAL (stateNumber, U"State number", U"1") |
| 374 |
NATURAL (numberOfTimeUnits, U"Number of time units", U"2") |
| 375 |
OK |
| 376 |
DO |
| 377 |
QUERY_ONE_FOR_REAL (HMM) |
| 378 |
const double result = HMM_getProbabilityOfStayingInState (me, stateNumber, numberOfTimeUnits); |
| 379 |
QUERY_ONE_FOR_REAL_END (U"(probability of staying in state)") |
| 380 |
} |
| 381 |
|
| 382 |
FORM (QUERY_ONE_FOR_REAL__HMM_getExpectedDurationInState, U"HMM: Get expected value of duration in state", |
| 383 |
U"HMM: Get expected duration in state...") { |
| 384 |
NATURAL (stateNumber, U"State number", U"1") |
| 385 |
OK |
| 386 |
DO |
| 387 |
QUERY_ONE_FOR_REAL (HMM) |
| 388 |
const double result = HMM_getExpectedValueOfDurationInState (me, stateNumber); |
| 389 |
QUERY_ONE_FOR_REAL_END (U" time units") |
| 390 |
} |
| 391 |
|
| 392 |
FORM (QUERY_ONE_FOR_STRING__HMM_getSymbolLabel, U"HMM: Get symbol label", nullptr) { |
| 393 |
NATURAL (symbolNumber, U"Symbol number", U"1") |
| 394 |
OK |
| 395 |
DO |
| 396 |
QUERY_ONE_FOR_STRING (HMM) |
| 397 |
Melder_require (symbolNumber <= my numberOfObservationSymbols, |
| 398 |
U"\"Symbol number\" should not be larger than ", my numberOfObservationSymbols, U"."); |
| 399 |
const HMMObservation observation = my observationSymbols->at [symbolNumber]; |
| 400 |
conststring32 result = observation -> label.get(); |
| 401 |
QUERY_ONE_FOR_STRING_END |
| 402 |
} |
| 403 |
|
| 404 |
FORM (QUERY_ONE_FOR_STRING__HMM_getStateLabel, U"HMM: Get state label", nullptr) { |
| 405 |
NATURAL (stateNumber, U"State number", U"1") |
| 406 |
OK |
| 407 |
DO |
| 408 |
QUERY_ONE_FOR_STRING (HMM) |
| 409 |
Melder_require (stateNumber <= my numberOfStates, |
| 410 |
U"\"State number\" should not be larger than ", my numberOfStates, U"."); |
| 411 |
const HMMState state = my states->at [stateNumber]; |
| 412 |
conststring32 result = state -> label.get(); |
| 413 |
QUERY_ONE_FOR_STRING_END |
| 414 |
} |
| 415 |
|
| 416 |
FORM (QUERY_TWO_FOR_REAL__HMM_HMM_getCrossEntropy, U"HMM & HMM: Get cross-entropy...", U"HMM & HMM: Get cross-entropy...") { |
| 417 |
NATURAL (observationLength, U"Observation length", U"2000") |
| 418 |
BOOLEAN (symmetric, U"Symmetric", true) |
| 419 |
OK |
| 420 |
DO |
| 421 |
QUERY_TWO_FOR_REAL (HMM) |
| 422 |
const double result = HMM_HMM_getCrossEntropy (me, you, observationLength, symmetric); |
| 423 |
QUERY_TWO_FOR_REAL_END (U" (", ( symmetric ? U"symmetric " : U"" ), |
| 424 |
U"cross-entropy between models for observation length ", observationLength, U")") |
| 425 |
} |
| 426 |
|
| 427 |
DIRECT (QUERY_TWO_AND_ONE_FOR_REAL__HMM_HMM_HMMObservationSequence_getCrossEntropy) { |
| 428 |
QUERY_TWO_AND_ONE_FOR_REAL (HMM, HMMObservationSequence) |
| 429 |
const double result = HMM_HMM_HMMObservationSequence_getCrossEntropy (me, you, him); |
| 430 |
QUERY_TWO_AND_ONE_FOR_REAL_END (U" (symmetric cross-entropy between models)") |
| 431 |
} |
| 432 |
|
| 433 |
FORM (CONVERT_EACH_TO_ONE__HMM_to_HMMObservationSequence, U"HMM: To HMMObservationSequence (generate observations)", U"HMM: To HMMObservationSequence...") { |
| 434 |
INTEGER (startState, U"Start state", U"0") |
| 435 |
NATURAL (numberOfObservations, U"Number of observations", U"20") |
| 436 |
OK |
| 437 |
DO |
| 438 |
CONVERT_EACH_TO_ONE (HMM) |
| 439 |
autoHMMObservationSequence result = HMM_to_HMMObservationSequence (me, startState, numberOfObservations); |
| 440 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 441 |
} |
| 442 |
|
| 443 |
DIRECT (QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMStateSequence_getProbability) { |
| 444 |
QUERY_ONE_AND_ONE_FOR_REAL (HMM, HMMStateSequence) |
| 445 |
const double result = HMM_HMMStateSequence_getProbability (me, you); |
| 446 |
QUERY_ONE_AND_ONE_FOR_REAL_END (U" (= ln(p), p = ", Melder_naturalLogarithm (result), U")") |
| 447 |
} |
| 448 |
|
| 449 |
DIRECT (QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getProbability) { |
| 450 |
QUERY_ONE_AND_ONE_FOR_REAL (HMM, HMMObservationSequence) |
| 451 |
const double result = HMM_HMMObservationSequence_getProbability (me, you); |
| 452 |
QUERY_ONE_AND_ONE_FOR_REAL_END (U" (= ln(p), p = ", Melder_naturalLogarithm (result), U")") |
| 453 |
} |
| 454 |
|
| 455 |
DIRECT (QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getCrossEntropy) { |
| 456 |
QUERY_ONE_AND_ONE_FOR_REAL (HMM, HMMObservationSequence) |
| 457 |
const double result = HMM_HMMObservationSequence_getCrossEntropy (me, you); |
| 458 |
QUERY_ONE_AND_ONE_FOR_REAL_END (U" (cross-entropy)") |
| 459 |
} |
| 460 |
|
| 461 |
DIRECT (QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getPerplexity) { |
| 462 |
QUERY_ONE_AND_ONE_FOR_REAL (HMM, HMMObservationSequence) |
| 463 |
const double result = HMM_HMMObservationSequence_getPerplexity (me, you); |
| 464 |
QUERY_ONE_AND_ONE_FOR_REAL_END (U" (perplexity)") |
| 465 |
} |
| 466 |
|
| 467 |
DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMObservationSequence_to_HMMStateSequence) { |
| 468 |
CONVERT_ONE_AND_ONE_TO_ONE (HMM, HMMObservationSequence) |
| 469 |
autoHMMStateSequence result = HMM_HMMObservationSequence_to_HMMStateSequence (me, you); |
| 470 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get(), U"_states") |
| 471 |
} |
| 472 |
|
| 473 |
FORM (MODIFY_FIRST_OF_ONE_AND_ALL__HMM_HMMObservationSequence_learn, U"HMM & HMMObservationSequence: Learn", U"HMM & HMMObservationSequences: Learn...") { |
| 474 |
POSITIVE (relativePrecision_log, U"Relative precision in log(p)", U"0.001") |
| 475 |
REAL (minimumProbability, U"Minimum probability", U"0.00000000001") |
| 476 |
BOOLEAN (showProgress, U"Learning history in Info window", false) |
| 477 |
OK |
| 478 |
DO |
| 479 |
Melder_require (minimumProbability >= 0.0 && minimumProbability < 1.0, |
| 480 |
U"The minimum probability should be in [0, 1)."); |
| 481 |
MODIFY_FIRST_OF_ONE_AND_ALL (HMM, HMMObservationSequence) |
| 482 |
HMM_HMMObservationSequenceBag_learn (me, (HMMObservationSequenceBag) & list, relativePrecision_log, minimumProbability, showProgress); |
| 483 |
MODIFY_FIRST_OF_ONE_AND_ALL_END |
| 484 |
} |
| 485 |
|
| 486 |
FORM (MODIFY_EACH__HMM_setTransitionProbabilities, U"HMM: Set transition probabilities", U"HMM: Set transition probabilities...") { |
| 487 |
NATURAL (stateNumber, U"State number", U"1") |
| 488 |
REALVECTOR (relativeProbabilities, U"Relative probabilities", WHITESPACE_SEPARATED_, U"0.1 0.9") |
| 489 |
OK |
| 490 |
DO |
| 491 |
MODIFY_EACH (HMM) |
| 492 |
HMM_setTransitionProbabilities (me, stateNumber, relativeProbabilities); |
| 493 |
MODIFY_EACH_END |
| 494 |
} |
| 495 |
|
| 496 |
FORM (MODIFY_EACH__HMM_setEmissionProbabilities, U"HMM: Set emission probabilities", U"HMM: Set emission probabilities...") { |
| 497 |
NATURAL (stateNumber, U"State number", U"1") |
| 498 |
REALVECTOR (relativeProbabilities, U"Relative probabilities", WHITESPACE_SEPARATED_, U"0.1 0.7 0.2") |
| 499 |
OK |
| 500 |
DO |
| 501 |
MODIFY_EACH (HMM) |
| 502 |
HMM_setEmissionProbabilities (me, stateNumber, relativeProbabilities); |
| 503 |
MODIFY_EACH_END |
| 504 |
} |
| 505 |
|
| 506 |
FORM (MODIFY_EACH__HMM_setStartProbabilities, U"HMM: Set start probabilities", U"HMM: Set start probabilities...") { |
| 507 |
REALVECTOR (relativeProbabilities, U"Relative probabilities", WHITESPACE_SEPARATED_, U"0.1 0.9") |
| 508 |
OK |
| 509 |
DO |
| 510 |
MODIFY_EACH (HMM) |
| 511 |
HMM_setStartProbabilities (me, relativeProbabilities); |
| 512 |
MODIFY_EACH_END |
| 513 |
} |
| 514 |
|
| 515 |
DIRECT (CONVERT_EACH_TO_ONE__HMM_extractTransitionProbabilities) { |
| 516 |
CONVERT_EACH_TO_ONE (HMM) |
| 517 |
autoTableOfReal result = HMM_extractTransitionProbabilities (me); |
| 518 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_t") |
| 519 |
} |
| 520 |
|
| 521 |
DIRECT (CONVERT_EACH_TO_ONE__HMM_extractEmissionProbabilities) { |
| 522 |
CONVERT_EACH_TO_ONE (HMM) |
| 523 |
autoTableOfReal result = HMM_extractEmissionProbabilities (me); |
| 524 |
CONVERT_EACH_TO_ONE_END (my name.get(), U"_e") |
| 525 |
} |
| 526 |
|
| 527 |
FORM (CONVERT_EACH_TO_ONE__HMMObservationSequence_to_TableOfReal_bigrams, U"HMMObservationSequence: To TableOfReal ", U"HMMObservationSequence: To TableOfReal (bigrams)...") { |
| 528 |
BOOLEAN (asProbabilities, U"As probabilities", true) |
| 529 |
OK |
| 530 |
DO |
| 531 |
CONVERT_EACH_TO_ONE (HMMObservationSequence) |
| 532 |
autoTableOfReal result = HMMObservationSequence_to_TableOfReal_transitions (me, asProbabilities); |
| 533 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 534 |
} |
| 535 |
|
| 536 |
FORM (CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMObservationSequence_to_TableOfReal_bigrams, U"HMM & HMMObservationSequence: To TableOfReal", U"HMM & HMMObservationSequence: To TableOfReal (bigrams)...") { |
| 537 |
BOOLEAN (asProbabilities, U"As probabilities", true) |
| 538 |
OK |
| 539 |
DO |
| 540 |
CONVERT_ONE_AND_ONE_TO_ONE (HMM, HMMObservationSequence) |
| 541 |
autoTableOfReal result = HMM_HMMObservationSequence_to_TableOfReal_transitions (me, you, asProbabilities); |
| 542 |
CONVERT_ONE_AND_ONE_TO_ONE_END (your name.get(), U"_m") |
| 543 |
} |
| 544 |
|
| 545 |
FORM (CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMStateSequence_to_TableOfReal_bigrams, U"HMM & HMMStateSequence: To TableOfReal", nullptr) { |
| 546 |
BOOLEAN (asProbabilities, U"As probabilities", true) |
| 547 |
OK |
| 548 |
DO |
| 549 |
CONVERT_ONE_AND_ONE_TO_ONE (HMM, HMMStateSequence) |
| 550 |
autoTableOfReal result = HMM_HMMStateSequence_to_TableOfReal_transitions (me, you, asProbabilities); |
| 551 |
CONVERT_ONE_AND_ONE_TO_ONE_END (your name.get(), U"_m") |
| 552 |
} |
| 553 |
|
| 554 |
FORM (CONVERT_EACH_TO_ONE__HMMStateSequence_to_TableOfReal_bigrams, U"HMMStateSequence: To TableOfReal", nullptr) { |
| 555 |
BOOLEAN (asProbabilities, U"As probabilities", true) |
| 556 |
OK |
| 557 |
DO |
| 558 |
CONVERT_EACH_TO_ONE (HMMStateSequence) |
| 559 |
autoTableOfReal result = Strings_to_TableOfReal_transitions (me, asProbabilities); |
| 560 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 561 |
} |
| 562 |
|
| 563 |
DIRECT (CONVERT_EACH_TO_ONE__HMMObservationSequence_to_Strings) { |
| 564 |
CONVERT_EACH_TO_ONE (HMMObservationSequence) |
| 565 |
autoStrings result = HMMObservationSequence_to_Strings (me); |
| 566 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 567 |
} |
| 568 |
|
| 569 |
DIRECT (CONVERT_EACH_TO_ONE__Strings_to_HMMObservationSequence) { |
| 570 |
CONVERT_EACH_TO_ONE (Strings) |
| 571 |
autoHMMObservationSequence result = Strings_to_HMMObservationSequence (me); |
| 572 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 573 |
} |
| 574 |
|
| 575 |
DIRECT (CONVERT_EACH_TO_ONE__HMMStateSequence_to_Strings) { |
| 576 |
CONVERT_EACH_TO_ONE (HMMStateSequence) |
| 577 |
autoStrings result = HMMStateSequence_to_Strings (me); |
| 578 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 579 |
} |
| 580 |
|
| 581 |
FORM (CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture_rowlabels, U"TableOfReal: To GaussianMixture from row labels", U"TableOfReal: To GaussianMixture (row labels)...") { |
| 582 |
CHOICE_ENUM (kGaussianMixtureStorage, storage, |
| 583 |
U"Covariance matrices are", kGaussianMixtureStorage::DEFAULT) |
| 584 |
OK |
| 585 |
DO |
| 586 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 587 |
autoGaussianMixture result = TableOfReal_to_GaussianMixture_fromRowLabels (me, storage); |
| 588 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 589 |
} |
| 590 |
|
| 591 |
FORM (CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture, U"TableOfReal: To GaussianMixture (no labels)", U"TableOfReal: To GaussianMixture...") { |
| 592 |
NATURAL (numberOfComponents, U"Number of components", U"2") |
| 593 |
POSITIVE (tolerance, U"Tolerance of minimizer", U"0.001") |
| 594 |
INTEGER (maximumNumberOfIterations, U"Maximum number of iterations", U"200") |
| 595 |
REAL (lambda, U"Stability coefficient lambda", U"0.001") |
| 596 |
CHOICE_ENUM (kGaussianMixtureStorage, storage, |
| 597 |
U"Covariance matrices are", kGaussianMixtureStorage::DEFAULT) |
| 598 |
OPTIONMENU_ENUM (kGaussianMixtureCriterion, criterion, U"Criterion based on", kGaussianMixtureCriterion::DEFAULT) |
| 599 |
OK |
| 600 |
DO |
| 601 |
Melder_require (lambda >= 0.0 && lambda < 1.0, |
| 602 |
U"Lambda should be in the interval [0, 1)."); |
| 603 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 604 |
autoGaussianMixture result = TableOfReal_to_GaussianMixture ( |
| 605 |
me, numberOfComponents, tolerance, maximumNumberOfIterations, lambda, storage, criterion |
| 606 |
); |
| 607 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 608 |
} |
| 609 |
|
| 610 |
FORM (CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture_CEMM, U"TableOfReal: To GaussianMixture (CEMM)", U"TableOfReal: To GaussianMixture (CEMM)...") { |
| 611 |
INTEGER (minimumNumberOfComponents, U"Minimum number of components", U"1") |
| 612 |
INTEGER (maximumNumberOfComponents, U"Maximum number of components", U"10") |
| 613 |
CHOICE_ENUM (kGaussianMixtureStorage, storage, |
| 614 |
U"Covariance matrices are", kGaussianMixtureStorage::DEFAULT) |
| 615 |
INTEGER (maximumNumberOfIterations, U"Maximum number of iterations", U"200") |
| 616 |
POSITIVE (tolerance, U"Tolerance of minimizer", U"0.00001") |
| 617 |
BOOLEAN (info, U"Info", false) |
| 618 |
OK |
| 619 |
DO |
| 620 |
CONVERT_EACH_TO_ONE (TableOfReal) |
| 621 |
autoGaussianMixture result = TableOfReal_to_GaussianMixture_CEMM ( |
| 622 |
me, minimumNumberOfComponents, maximumNumberOfComponents, storage, maximumNumberOfIterations, tolerance, info |
| 623 |
); |
| 624 |
CONVERT_EACH_TO_ONE_END (my name.get()) |
| 625 |
} |
| 626 |
|
| 627 |
FORM (MODIFY_FIRST_OF_ONE_AND_ONE__GaussianMixture_TableOfReal_improveLikelihood, U"GaussianMixture & TableOfReal: Improve likelihood", U"GaussianMixture & TableOfReal: Improve likelihood...") { |
| 628 |
POSITIVE (tolerance, U"Tolerance of minimizer", U"0.001") |
| 629 |
NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"200") |
| 630 |
REAL (lambda, U"Stability coefficient lambda", U"0.001") |
| 631 |
OPTIONMENU_ENUM (kGaussianMixtureCriterion, criterion, U"Criterion based on", kGaussianMixtureCriterion::DEFAULT) |
| 632 |
OK |
| 633 |
DO |
| 634 |
Melder_require (lambda >= 0.0 && lambda < 1.0, |
| 635 |
U"Lambda should be in the interval [0, 1)."); |
| 636 |
MODIFY_FIRST_OF_ONE_AND_ONE (GaussianMixture, TableOfReal) |
| 637 |
GaussianMixture_TableOfReal_improveLikelihood (me, you, tolerance, maximumNumberOfIterations, lambda, criterion); |
| 638 |
MODIFY_FIRST_OF_ONE_AND_ONE_END |
| 639 |
} |
| 640 |
|
| 641 |
FORM (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_GaussianMixture_CEMM, U"GaussianMixture & TableOfReal: To GaussianMixture (CEMM)", U"GaussianMixture & TableOfReal: To GaussianMixture (CEMM)...") { |
| 642 |
INTEGER (minimumNumberOfComponents, U"Minimum number of components", U"1") |
| 643 |
POSITIVE (tolerance, U"Tolerance of minimizer", U"0.001") |
| 644 |
NATURAL (maximumNumberOfIterations, U"Maximum number of iterations", U"200") |
| 645 |
BOOLEAN (info, U"Info", false) |
| 646 |
OK |
| 647 |
DO |
| 648 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 649 |
autoGaussianMixture result = GaussianMixture_TableOfReal_to_GaussianMixture_CEMM ( |
| 650 |
me, you, minimumNumberOfComponents, maximumNumberOfIterations, tolerance, info |
| 651 |
); |
| 652 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get()) |
| 653 |
} |
| 654 |
|
| 655 |
DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_ClassificationTable) { |
| 656 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 657 |
autoClassificationTable result = GaussianMixture_TableOfReal_to_ClassificationTable (me, you); |
| 658 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 659 |
} |
| 660 |
|
| 661 |
DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_TableOfReal_probabilities) { |
| 662 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 663 |
autoTableOfReal result = GaussianMixture_TableOfReal_to_TableOfReal_probabilities (me, you); |
| 664 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 665 |
} |
| 666 |
|
| 667 |
DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_TableOfReal_responsibilities) { |
| 668 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 669 |
autoTableOfReal result = GaussianMixture_TableOfReal_to_TableOfReal_responsibilities (me, you); |
| 670 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 671 |
} |
| 672 |
|
| 673 |
DIRECT (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_Correlation) { |
| 674 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 675 |
autoCorrelation result = GaussianMixture_TableOfReal_to_Correlation (me, you); |
| 676 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 677 |
} |
| 678 |
|
| 679 |
FORM (CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_Table_BHEPNormalityTests, U"GaussianMixture & TableOfReal: To Table (BHEP normality tests)", U"GaussianMixture & TableOfReal: To Table (BHEP normality tests)...") { |
| 680 |
REAL (smoothingParameter, U"Smoothing parameter", U"1.41") |
| 681 |
OK |
| 682 |
DO |
| 683 |
CONVERT_ONE_AND_ONE_TO_ONE (GaussianMixture, TableOfReal) |
| 684 |
autoTable result = GaussianMixture_TableOfReal_to_Table_BHEPNormalityTests (me, you, smoothingParameter); |
| 685 |
CONVERT_ONE_AND_ONE_TO_ONE_END (my name.get(), U"_", your name.get()) |
| 686 |
} |
| 687 |
|
| 688 |
void praat_HMM_init (); |
| 689 |
void praat_HMM_init () { |
| 690 |
Thing_recognizeClassesByName (classHMM, classHMMState, classHMMObservation, classHMMObservationSequence, classHMMStateSequence, classGaussianMixture); |
| 691 |
|
| 692 |
praat_addMenuCommand (U"Objects", U"New", U"Markov models", nullptr, GuiMenu_HIDDEN, nullptr); |
| 693 |
praat_addMenuCommand (U"Objects", U"New", U"Create HMM...", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 694 |
CREATE_ONE__HMM_create); |
| 695 |
praat_addMenuCommand (U"Objects", U"New", U"Create simple HMM...", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 696 |
CREATE_ONE__HMM_createSimple); |
| 697 |
praat_addMenuCommand (U"Objects", U"New", U"Create continuous HMM...", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 698 |
CREATE_ONE__HMM_createContinuousModel); |
| 699 |
praat_addMenuCommand (U"Objects", U"New", U"--drawings--", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, nullptr); |
| 700 |
praat_addMenuCommand (U"Objects", U"New", U"Draw forward probabilities illustration", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 701 |
GRAPHICS_NONE__HMM_drawForwardProbabilitiesIllustration); |
| 702 |
praat_addMenuCommand (U"Objects", U"New", U"Draw backward probabilities illustration", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 703 |
GRAPHICS_NONE__HMM_drawBackwardProbabilitiesIllustration); |
| 704 |
praat_addMenuCommand (U"Objects", U"New", U"Draw forward and backward probabilities illustration", nullptr, GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 705 |
GRAPHICS_NONE__HMM_drawForwardAndBackwardProbabilitiesIllustration); |
| 706 |
|
| 707 |
praat_addAction1 (classGaussianMixture, 0, U"GaussianMixture help", nullptr, 0, |
| 708 |
HELP__GaussianMixture_help); |
| 709 |
praat_addAction1 (classGaussianMixture, 0, U"Draw concentration ellipses...", nullptr, 0, |
| 710 |
GRAPHICS_EACH__GaussianMixture_drawConcentrationEllipses); |
| 711 |
praat_addAction1 (classGaussianMixture, 0, U"Draw marginal pdf...", nullptr, 0, |
| 712 |
GRAPHICS_EACH__GaussianMixture_drawMarginalPdf); |
| 713 |
praat_addAction1 (classGaussianMixture, 0, U"Query -", nullptr, 0, nullptr); |
| 714 |
praat_addAction1 (classGaussianMixture, 1, U"Get number of components", nullptr, 1, |
| 715 |
QUERY_ONE_FOR_INTEGER__GaussianMixture_getNumberOfComponents); |
| 716 |
praat_addAction1 (classGaussianMixture, 1, U"Get dimension of component", nullptr, 1, |
| 717 |
QUERY_ONE_FOR_INTEGER__GaussianMixture_getDimensionOfComponent); |
| 718 |
praat_addAction1 (classGaussianMixture, 1, U"Get probability at position...", nullptr, 1, |
| 719 |
QUERY_ONE_FOR_REAL__GaussianMixture_getProbabilityAtPosition); |
| 720 |
praat_addAction1 (classGaussianMixture, 0, U"Modify -", nullptr, 0, nullptr); |
| 721 |
praat_addAction1 (classGaussianMixture, 1, U"Split component...", nullptr, 1, |
| 722 |
MODIFY_GaussianMixture_splitComponent); |
| 723 |
praat_addAction1 (classGaussianMixture, 0, U"Extract -", nullptr, 0, nullptr); |
| 724 |
praat_addAction1 (classGaussianMixture, 0, U"Extract mixing probabilities", nullptr, 1, |
| 725 |
CONVERT_EACH_TO_ONE__GaussianMixture_extractMixingProbabilities); |
| 726 |
praat_addAction1 (classGaussianMixture, 0, U"Extract component...", nullptr, 1, |
| 727 |
CONVERT_EACH_TO_ONE__GaussianMixture_extractComponent); |
| 728 |
praat_addAction1 (classGaussianMixture, 0, U"Extract centroids", nullptr, 1, |
| 729 |
CONVERT_EACH_TO_ONE__GaussianMixture_extractCentroids); |
| 730 |
praat_addAction1 (classGaussianMixture, 0, U"To Covariance (between)", nullptr, 0, |
| 731 |
CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_between); |
| 732 |
praat_addAction1 (classGaussianMixture, 0, U"To Covariance (within)", nullptr, 0, |
| 733 |
CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_within); |
| 734 |
praat_addAction1 (classGaussianMixture, 0, U"To Covariance (total)", nullptr, 0, |
| 735 |
CONVERT_EACH_TO_ONE__GaussianMixture_to_Covariance_total); |
| 736 |
praat_addAction1 (classGaussianMixture, 0, U"To PCA", nullptr, 0, |
| 737 |
CONVERT_EACH_TO_ONE__GaussianMixture_to_PCA); |
| 738 |
praat_addAction1 (classGaussianMixture, 0, U"To TableOfReal (random sampling)...", nullptr, 0, |
| 739 |
CONVERT_EACH_TO_ONE__GaussianMixture_to_TableOfReal_randomSampling); |
| 740 |
|
| 741 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"Get likelihood value...", nullptr, 0, |
| 742 |
QUERY_ONE_AND_ONE_FOR_REAL__GaussianMixture_TableOfReal_getLikelihoodValue); |
| 743 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"Improve likelihood...", nullptr, 0, |
| 744 |
MODIFY_FIRST_OF_ONE_AND_ONE__GaussianMixture_TableOfReal_improveLikelihood); |
| 745 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To GaussianMixture (CEMM)...", nullptr, 0, |
| 746 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_GaussianMixture_CEMM); |
| 747 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To TableOfReal (probabilities)", nullptr, 0, |
| 748 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_TableOfReal_probabilities); |
| 749 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To TableOfReal (responsibilities)", nullptr, 0, |
| 750 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_TableOfReal_responsibilities); |
| 751 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To ClassificationTable", nullptr, 0, |
| 752 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_ClassificationTable); |
| 753 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To Correlation", nullptr, 0, |
| 754 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_Correlation); |
| 755 |
praat_addAction2 (classGaussianMixture, 1, classTableOfReal, 1, U"To Table (BHEP normality tests)...", nullptr, 0, |
| 756 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_TableOfReal_to_Table_BHEPNormalityTests); |
| 757 |
|
| 758 |
praat_addAction2 (classGaussianMixture, 1, classPCA, 1, U"Draw concentration ellipses...", nullptr, 0, |
| 759 |
GRAPHICS_ONE_AND_ONE__GaussianMixture_PCA_drawConcentrationEllipses); |
| 760 |
praat_addAction2 (classGaussianMixture, 1, classPCA, 1, U"Draw marginal pdf...", nullptr, 0, |
| 761 |
GRAPHICS_ONE_AND_ONE__GaussianMixture_PCA_drawMarginalPdf); |
| 762 |
praat_addAction2 (classGaussianMixture, 1, classPCA, 1, U"To Matrix (density)...", nullptr, 0, |
| 763 |
CONVERT_ONE_AND_ONE_TO_ONE__GaussianMixture_PCA_to_Matrix_density); |
| 764 |
|
| 765 |
praat_addAction1 (classHMM, 0, U"HMM help ", nullptr, 0, |
| 766 |
HELP__HMM_help); |
| 767 |
praat_addAction1 (classHMM, 0, U"Draw...", nullptr, 0, |
| 768 |
GRAPHICS_EACH__HMM_draw); |
| 769 |
praat_addAction1 (classHMM, 0, U"Query -", nullptr, 0, nullptr); |
| 770 |
praat_addAction1 (classHMM, 1, U"Get transition probability...", nullptr, 1, |
| 771 |
QUERY_ONE_FOR_REAL__HMM_getTransitionProbability); |
| 772 |
praat_addAction1 (classHMM, 1, U"Get emission probability...", nullptr, 1, |
| 773 |
QUERY_ONE_FOR_REAL__HMM_getEmissionProbability); |
| 774 |
praat_addAction1 (classHMM, 1, U"Get start probability...", nullptr, 1, |
| 775 |
QUERY_ONE_FOR_REAL__HMM_getStartProbability); |
| 776 |
praat_addAction1 (classHMM, 1, U"Get p (time, state)...", nullptr, 1, |
| 777 |
QUERY_ONE_FOR_REAL__HMM_getProbabilityAtTimeBeingInState); |
| 778 |
praat_addAction1 (classHMM, 1, U"Get p (time, state, symbol)...", nullptr, 1, |
| 779 |
QUERY_ONE_FOR_REAL__HMM_getProbabilityAtTimeBeingInStateEmittingSymbol); |
| 780 |
praat_addAction1 (classHMM, 1, U"Get probability staying in state...", nullptr, 1, |
| 781 |
QUERY_ONE_FOR_REAL__HMM_getProbabilityOfStayingInState); |
| 782 |
praat_addAction1 (classHMM, 1, U"Get expected duration in state...", nullptr, 1, |
| 783 |
QUERY_ONE_FOR_REAL__HMM_getExpectedDurationInState); |
| 784 |
praat_addAction1 (classHMM, 1, U"---- states / symbols -----", nullptr, 1, nullptr); |
| 785 |
praat_addAction1 (classHMM, 1, U"Get state label...", nullptr, 1, |
| 786 |
QUERY_ONE_FOR_STRING__HMM_getStateLabel); |
| 787 |
praat_addAction1 (classHMM, 1, U"Get symbol label...", nullptr, 1, |
| 788 |
QUERY_ONE_FOR_STRING__HMM_getSymbolLabel); |
| 789 |
praat_addAction1 (classHMM, 0, U"--- multiple HMMs ----", nullptr, 1, nullptr); |
| 790 |
praat_addAction1 (classHMM, 2, U"Get cross-entropy...", nullptr, 1, |
| 791 |
QUERY_TWO_FOR_REAL__HMM_HMM_getCrossEntropy); |
| 792 |
|
| 793 |
praat_addAction1 (classHMM, 0, U"Modify -", nullptr, 0, nullptr); |
| 794 |
praat_addAction1 (classHMM, 1, U"Set transition probabilities...", nullptr, 1, |
| 795 |
MODIFY_EACH__HMM_setTransitionProbabilities); |
| 796 |
praat_addAction1 (classHMM, 1, U"Set emission probabilities...", nullptr, 1, |
| 797 |
MODIFY_EACH__HMM_setEmissionProbabilities); |
| 798 |
praat_addAction1 (classHMM, 1, U"Set start probabilities...", nullptr, 1, |
| 799 |
MODIFY_EACH__HMM_setStartProbabilities); |
| 800 |
|
| 801 |
praat_addAction1 (classHMM, 0, U"Extract -", nullptr, 0, nullptr); |
| 802 |
praat_addAction1 (classHMM, 0, U"Extract transition probabilities", nullptr, 1, |
| 803 |
CONVERT_EACH_TO_ONE__HMM_extractTransitionProbabilities); |
| 804 |
praat_addAction1 (classHMM, 0, U"Extract emission probabilities", nullptr, 1, |
| 805 |
CONVERT_EACH_TO_ONE__HMM_extractEmissionProbabilities); |
| 806 |
|
| 807 |
praat_addAction1 (classHMM, 0, U"To HMMObservationSequence...", nullptr, 0, |
| 808 |
CONVERT_EACH_TO_ONE__HMM_to_HMMObservationSequence); |
| 809 |
praat_addAction2 (classHMM, 1, classHMMStateSequence, 1, U"Draw trellis...", nullptr, 0, |
| 810 |
GRAPHICS_ONE_AND_ONE__HMM_HMMStateSequence_drawTrellis); |
| 811 |
praat_addAction2 (classHMM, 1, classHMMStateSequence, 1, U"Get probability", nullptr, 0, |
| 812 |
QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMStateSequence_getProbability); |
| 813 |
praat_addAction2 (classHMM, 1, classHMMStateSequence, 1, U"To TableOfReal (bigrams)...", nullptr, 0, |
| 814 |
CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMStateSequence_to_TableOfReal_bigrams); |
| 815 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 1, U"Get probability", nullptr, 0, |
| 816 |
QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getProbability); |
| 817 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 1, U"Get cross-entropy", nullptr, 0, |
| 818 |
QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getCrossEntropy); |
| 819 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 1, U"Get perplexity", nullptr, 0, |
| 820 |
QUERY_ONE_AND_ONE_FOR_REAL__HMM_HMMObservationSequence_getPerplexity); |
| 821 |
|
| 822 |
|
| 823 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 1, U"To HMMStateSequence", nullptr, 0, |
| 824 |
CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMObservationSequence_to_HMMStateSequence); |
| 825 |
praat_addAction2 (classHMM, 2, classHMMObservationSequence, 1, U"Get cross-entropy", nullptr, 0, |
| 826 |
QUERY_TWO_AND_ONE_FOR_REAL__HMM_HMM_HMMObservationSequence_getCrossEntropy); |
| 827 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 1, U"To TableOfReal (bigrams)...", nullptr, 0, |
| 828 |
CONVERT_ONE_AND_ONE_TO_ONE__HMM_HMMObservationSequence_to_TableOfReal_bigrams); |
| 829 |
praat_addAction2 (classHMM, 1, classHMMObservationSequence, 0, U"Learn...", nullptr, 0, |
| 830 |
MODIFY_FIRST_OF_ONE_AND_ALL__HMM_HMMObservationSequence_learn); |
| 831 |
|
| 832 |
praat_addAction1 (classHMMObservationSequence, 0, U"To TableOfReal (bigrams)...", nullptr, 0, |
| 833 |
CONVERT_EACH_TO_ONE__HMMObservationSequence_to_TableOfReal_bigrams); |
| 834 |
praat_addAction1 (classHMMObservationSequence, 0, U"To Strings", nullptr, 0, |
| 835 |
CONVERT_EACH_TO_ONE__HMMObservationSequence_to_Strings); |
| 836 |
praat_addAction1 (classHMMStateSequence, 0, U"To TableOfReal (bigrams)...", nullptr, 0, |
| 837 |
CONVERT_EACH_TO_ONE__HMMStateSequence_to_TableOfReal_bigrams); |
| 838 |
praat_addAction1 (classHMMStateSequence, 0, U"To Strings", nullptr, 0, |
| 839 |
CONVERT_EACH_TO_ONE__HMMStateSequence_to_Strings); |
| 840 |
|
| 841 |
praat_addAction1 (classHMMObservationSequence, 0, U"To HMM...", nullptr, 1, |
| 842 |
CONVERT_EACH_TO_ONE__HMMObservationSequence_to_HMM); |
| 843 |
|
| 844 |
praat_addAction1 (classStrings, 0, U"To HMMObservationSequence", nullptr, GuiMenu_HIDDEN, |
| 845 |
CONVERT_EACH_TO_ONE__Strings_to_HMMObservationSequence); |
| 846 |
praat_addAction1 (classTableOfReal, 0, U"To GaussianMixture (row labels)...", U"To Covariance", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 847 |
CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture_rowlabels); |
| 848 |
praat_addAction1 (classTableOfReal, 0, U"To GaussianMixture...", U"To Covariance", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 849 |
CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture); |
| 850 |
praat_addAction1 (classTableOfReal, 0, U"To GaussianMixture (CEMM)...", U"To GaussianMixture...", GuiMenu_DEPTH_1 | GuiMenu_HIDDEN, |
| 851 |
CONVERT_EACH_TO_ONE__TableOfReal_to_GaussianMixture_CEMM); |
| 852 |
INCLUDE_MANPAGES (manual_HMM) |
| 853 |
} |
| 854 |
|
| 855 |
/* End of file praat_HMM_init.cpp */ |