| 1 | /* HMM.cpp |
| 2 | * |
| 3 | * Copyright (C) 2010-2023 David Weenink, 2015,2017 Paul Boersma |
| 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 | djmw 20110304 Thing_new |
| 20 | */ |
| 21 | |
| 22 | #include "Distributions_and_Strings.h"cxx . . $ `<file>/stat/Distributions_and_Strings.h`/ |
| 23 | #include "HMM.h"cxx . . $ `<file>/dwtools/HMM.h`/ |
| 24 | #include "Index.h"cxx . . $ `<file>/dwsys/Index.h`/ |
| 25 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 26 | #include "Strings_extensions.h"cxx . . $ `<file>/dwtools/Strings_extensions.h`/ |
| 27 | |
| 28 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 29 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 30 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 31 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 32 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 33 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 34 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 35 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 36 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 37 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 38 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 39 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 40 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 41 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 42 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 43 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 44 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 45 | #include "HMM_def.h"cxx . . $ `<file>/dwtools/HMM_def.h`/ |
| 46 | |
| 47 | |
| 48 | #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/ |
| 49 | #include "HMM_enums.h"cxx . . $ `<file>/dwtools/HMM_enums.h`/ |
| 50 | #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/ |
| 51 | #include "HMM_enums.h"cxx . . $ `<file>/dwtools/HMM_enums.h`/ |
| 52 | |
| 53 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMM, Daata, 2); |
| 54 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMState, Daata, 0); |
| 55 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMStateList, Ordered, 0); |
| 56 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMObservation, Daata, 0); |
| 57 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMObservationList, Ordered, 0); |
| 58 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMBaumWelch, Daata, 0); |
| 59 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMViterbi, Daata, 0); |
| 60 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMObservationSequence, Table, 0); |
| 61 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMObservationSequenceBag, Collection, 0); |
| 62 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (HMMStateSequence, Strings, 0); |
| 63 | |
| 64 | /* |
| 65 | Whenever a routine returns ln(p), the result for p=0 is -INFINITY. |
| 66 | On IEEE floating point hardware this number behaves reasonably. |
| 67 | This means that when the variable q equals INFINITY, q + a -> INFINITY, |
| 68 | where a is a finite number. |
| 69 | */ |
| 70 | |
| 71 | // helpers |
| 72 | autoHMMObservation HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (conststring32cxx . . $ conststring32# label, integercxx . . $ integer# numberOfComponents, integercxx . . $ integer# dimension, kHMMstorage storage); |
| 73 | |
| 74 | integercxx . . $ integer# HMM_HMMObservationSequence_getLongestSequencecxx . . $ HMM_HMMObservationSequence_getLongestSequence(e11513b56c8cdb0b). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee, integercxx . . $ integer# symbolNumber); |
| 75 | integercxx . . $ integer# StringsIndex_getLongestSequencecxx . . $ StringsIndex_getLongestSequence(c25990de11b4d906). (StringsIndexcxx . . $ StringsIndex# me, integercxx . . $ integer# index, integercxx . . $ integer# *out_pos); |
| 76 | integercxx . . $ integer# Strings_getLongestSequencecxx . . $ Strings_getLongestSequence(9b3b26d5be5f1af5). (Stringscxx . . $ Strings# me, char32cxx . . $ char32# *string, integercxx . . $ integer# *out_pos); |
| 77 | autoHMMState HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (conststring32cxx . . $ conststring32# label); |
| 78 | |
| 79 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# HMMBaumWelch_createcxx . . $ HMMBaumWelch_create(a9645a0ad7322db7). (integercxx . . $ integer# nstates, integercxx . . $ integer# nsymbols, integercxx . . $ integer# capacity); |
| 80 | void HMMBaumWelch_getGammacxx . . $ HMMBaumWelch_getGamma(5b8f7ffbd72becf8). (HMMBaumWelchcxx . . $ HMMBaumWelch# me); |
| 81 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# HMM_forwardcxx . . $ HMM_forward(1c565d6cf11da809). (HMM me, constINTVECcxx . . $ constINTVEC# obs); |
| 82 | void HMMBaumWelch_reInitcxx . . $ HMMBaumWelch_reInit(5b8f7ffbd72becf8). (HMMBaumWelchcxx . . $ HMMBaumWelch# me); |
| 83 | void HMM_HMMBaumWelch_getXicxx . . $ HMM_HMMBaumWelch_getXi(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs); |
| 84 | void HMM_HMMBaumWelch_reestimatecxx . . $ HMM_HMMBaumWelch_reestimate(5e4dd3b7e148addf). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee); |
| 85 | void HMM_HMMBaumWelch_addEstimatecxx . . $ HMM_HMMBaumWelch_addEstimate(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs); |
| 86 | void HMM_HMMBaumWelch_forwardcxx . . $ HMM_HMMBaumWelch_forward(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs); |
| 87 | void HMM_HMMBaumWelch_backwardcxx . . $ HMM_HMMBaumWelch_backward(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs); |
| 88 | void HMM_HMMViterbi_decodecxx . . $ HMM_HMMViterbi_decode(f8c11026b00d51af). (HMM me, HMMViterbi thee, constINTVECcxx . . $ constINTVEC# obs); |
| 89 | double HMM_getProbabilityOfObservationscxx . . $ HMM_getProbabilityOfObservations(dc3ed4315d2b41a8). (HMM me, constINTVECcxx . . $ constINTVEC# obs); |
| 90 | autoTableOfRealcxx . . $ autoTableOfReal# StringsIndex_to_TableOfReal_transitionscxx . . $ StringsIndex_to_TableOfReal_transitions(baf5dc16ade1e25b). (StringsIndexcxx . . $ StringsIndex# me, int probabilities); |
| 91 | autoStringsIndexcxx . . $ autoStringsIndex# HMM_HMMStateSequence_to_StringsIndexcxx . . $ HMM_HMMStateSequence_to_StringsIndex(c40a092f418921de). (HMM me, HMMStateSequencecxx . . $ HMMStateSequence# thee); |
| 92 | |
| 93 | |
| 94 | autoHMMViterbi HMMViterbi_createcxx . . $ HMMViterbi_create(15b93c76f9bd1b11). (integercxx . . $ integer# nstates, integercxx . . $ integer# ntimes); |
| 95 | |
| 96 | #if 0 |
| 97 | static integer NUMget_line_intersection_with_circle (double xc, double yc, double r, double a, double b, double *out_x1, double *out_y1, double *out_x2, double *out_y2) { |
| 98 | const double ca = a * a + 1.0, bmyc = (b - yc); |
| 99 | const double cb = 2.0 * (a * bmyc - xc); |
| 100 | const double cc = bmyc * bmyc + xc * xc - r * r; |
| 101 | double x1, x2, y1, y2; |
| 102 | const integer nroots = NUMsolveQuadraticEquation (ca, cb, cc, & x1, & x2); |
| 103 | if (nroots == 1) { |
| 104 | y1 = a * x1 + b; |
| 105 | x2 = x1; |
| 106 | y2 = y1; |
| 107 | } else if (nroots == 2) { |
| 108 | if (x1 > x2) |
| 109 | std::swap (x1, x2); |
| 110 | y1 = x1 * a + b; |
| 111 | y2 = x2 * a + b; |
| 112 | } |
| 113 | if (out_x1) |
| 114 | *out_x1 = x1; |
| 115 | if (out_x2) |
| 116 | *out_x2 = x2; |
| 117 | if (out_y1) |
| 118 | *out_y1 = y1; |
| 119 | if (out_y2) |
| 120 | *out_y2 = y2; |
| 121 | return nroots; |
| 122 | } |
| 123 | #endif |
| 124 | |
| 125 | // D(l_1,l_2)=1/n( log p(O_2|l_1) - log p(O_2|l_2) |
| 126 | static double HMM_HMM_getCrossEntropy_asymcxx . . $ HMM_HMM_getCrossEntropy_asym(69e294df27e76719). (HMM me, HMM thee, integercxx . . $ integer# observationLength) { |
| 127 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# os = HMM_to_HMMObservationSequencecxx . . $ HMM_to_HMMObservationSequence(d1c4b4e14e520387). (thee, 0, observationLength); |
| 128 | const double ce = HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (me, os.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 129 | if (isundefcxx . . $ isundef(f8197d536af80c96). (ce)) |
| 130 | return ce; |
| 131 | const double ce2 = HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (thee, os.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 132 | if (isundefcxx . . $ isundef(f8197d536af80c96). (ce2)) |
| 133 | return ce2; |
| 134 | return ce - ce2; |
| 135 | } |
| 136 | |
| 137 | /**************** HMMObservation ******************************/ |
| 138 | |
| 139 | static void HMMObservation_initcxx . . $ HMMObservation_init(5393132eb3b6533e). (HMMObservation me, conststring32cxx . . $ conststring32# label, integercxx . . $ integer# numberOfComponents, integercxx . . $ integer# dimension, kHMMstorage storage) { |
| 140 | mycxx . . $ `melder/melder.h:44:9`! label =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (label); |
| 141 | mycxx . . $ `melder/melder.h:44:9`! gm =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). GaussianMixture_createcxx . . $ GaussianMixture_create(261625e4cf0d6340). (numberOfComponents, dimension, storage == kHMMstorage::DIAGONALS ? |
| 142 | kGaussianMixtureStoragecxx . . $ kGaussianMixtureStorage#::DIAGONALScxx . . $ kGaussianMixtureStorage#DIAGONALS. : kGaussianMixtureStoragecxx . . $ kGaussianMixtureStorage#::COMPLETEcxx . . $ kGaussianMixtureStorage#COMPLETE.); |
| 143 | } |
| 144 | |
| 145 | autoHMMObservation HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (conststring32cxx . . $ conststring32# label, integercxx . . $ integer# numberOfComponents, integercxx . . $ integer# dimension, kHMMstorage storage) { |
| 146 | try { |
| 147 | autoHMMObservation me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMObservation); |
| 148 | HMMObservation_initcxx . . $ HMMObservation_init(5393132eb3b6533e). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), label, numberOfComponents, dimension, storage); |
| 149 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 150 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 151 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMObservation not created."); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | integercxx . . $ integer# Strings_getLongestSequencecxx . . $ Strings_getLongestSequence(9b3b26d5be5f1af5). (Stringscxx . . $ Strings# me, char32cxx . . $ char32# *string, integercxx . . $ integer# *out_pos) { |
| 156 | integercxx . . $ integer# length = 0, longest = 0, lpos = 0, pos = 0; |
| 157 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; i ++) { |
| 158 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), string)) { |
| 159 | if (length == 0) { |
| 160 | lpos = i; |
| 161 | } |
| 162 | length ++; |
| 163 | } else { |
| 164 | if (length > 0) { |
| 165 | if (length > longest) { |
| 166 | longest = length; |
| 167 | pos = lpos; |
| 168 | } |
| 169 | length = 0; |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | if (out_pos) |
| 174 | *out_pos = pos; |
| 175 | return length; |
| 176 | } |
| 177 | |
| 178 | integercxx . . $ integer# StringsIndex_getLongestSequencecxx . . $ StringsIndex_getLongestSequence(c25990de11b4d906). (StringsIndexcxx . . $ StringsIndex# me, integercxx . . $ integer# index, integercxx . . $ integer# *out_pos) { |
| 179 | integercxx . . $ integer# length = 0, longest = 0, lpos = 0, pos = 0; |
| 180 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfItemscxx . . $ structIndex#numberOfItems.; i ++) { |
| 181 | if (mycxx . . $ `melder/melder.h:44:9`! classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] == index) { |
| 182 | if (length == 0) |
| 183 | lpos = i; |
| 184 | length ++; |
| 185 | } else { |
| 186 | if (length > 0) { |
| 187 | if (length > longest) { |
| 188 | longest = length; |
| 189 | pos = lpos; |
| 190 | } |
| 191 | length = 0; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | if (out_pos) |
| 196 | *out_pos = pos; |
| 197 | return length; |
| 198 | } |
| 199 | |
| 200 | /**************** HMMState ******************************/ |
| 201 | |
| 202 | static void HMMState_initcxx . . $ HMMState_init(d71b64c2b068f543). (HMMState me, conststring32cxx . . $ conststring32# label) { |
| 203 | mycxx . . $ `melder/melder.h:44:9`! label =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (label); |
| 204 | } |
| 205 | |
| 206 | autoHMMState HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (conststring32cxx . . $ conststring32# label) { |
| 207 | try { |
| 208 | autoHMMState me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMState); |
| 209 | HMMState_initcxx . . $ HMMState_init(d71b64c2b068f543). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), label); |
| 210 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 211 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 212 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMState not created."); |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | void HMMState_setLabelcxx . . $ HMMState_setLabel(32a0f6995fb3042f). (HMMState me, char32cxx . . $ char32# *label) { |
| 217 | mycxx . . $ `melder/melder.h:44:9`! label =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (label); |
| 218 | } |
| 219 | |
| 220 | /**************** HMMBaumWelch ******************************/ |
| 221 | |
| 222 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# HMMBaumWelch_createcxx . . $ HMMBaumWelch_create(a9645a0ad7322db7). (integercxx . . $ integer# nstates, integercxx . . $ integer# nsymbols, integercxx . . $ integer# capacity) { |
| 223 | try { |
| 224 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMBaumWelch); |
| 225 | mycxx . . $ `melder/melder.h:44:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. = mycxx . . $ `melder/melder.h:44:9`! capacitycxx . . $ structHMMBaumWelch#capacity. = capacity; |
| 226 | mycxx . . $ `melder/melder.h:44:9`! numberOfStatescxx . . $ structHMMBaumWelch#numberOfStates. = nstates; |
| 227 | mycxx . . $ `melder/melder.h:44:9`! numberOfSymbolscxx . . $ structHMMBaumWelch#numberOfSymbols. = nsymbols; |
| 228 | mycxx . . $ `melder/melder.h:44:9`! alphacxx . . $ structHMMBaumWelch#alpha. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, capacity); |
| 229 | mycxx . . $ `melder/melder.h:44:9`! betacxx . . $ structHMMBaumWelch#beta. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, capacity); |
| 230 | mycxx . . $ `melder/melder.h:44:9`! scalecxx . . $ structHMMBaumWelch#scale. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (capacity); |
| 231 | mycxx . . $ `melder/melder.h:44:9`! xicxx . . $ structHMMBaumWelch#xi. =cxx . . $ autotensor3#`operator=`(843cdf2ecfc42744). zero_TEN3cxx . . $ zero_TEN3(80a4e4dae4df97ba). (capacity, nstates, nstates); // TEN3 |
| 232 | mycxx . . $ `melder/melder.h:44:9`! aij_num_p0cxx . . $ structHMMBaumWelch#aij_num_p0. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (nstates + 1); |
| 233 | mycxx . . $ `melder/melder.h:44:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, nstates + 1); |
| 234 | mycxx . . $ `melder/melder.h:44:9`! aij_denom_p0cxx . . $ structHMMBaumWelch#aij_denom_p0. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (nstates + 1); |
| 235 | mycxx . . $ `melder/melder.h:44:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, nstates + 1); |
| 236 | mycxx . . $ `melder/melder.h:44:9`! bik_numcxx . . $ structHMMBaumWelch#bik_num. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, nsymbols); |
| 237 | mycxx . . $ `melder/melder.h:44:9`! bik_denomcxx . . $ structHMMBaumWelch#bik_denom. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, nsymbols); |
| 238 | mycxx . . $ `melder/melder.h:44:9`! gammacxx . . $ structHMMBaumWelch#gamma. =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, capacity); |
| 239 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 240 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 241 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMBaumWelch not created."); |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | void HMMBaumWelch_getGammacxx . . $ HMMBaumWelch_getGamma(5b8f7ffbd72becf8). (HMMBaumWelchcxx . . $ HMMBaumWelch# me) { |
| 246 | for (integercxx . . $ integer# it = 1; it <= mycxx . . $ `melder/melder.h:44:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.; it ++) { |
| 247 | mycxx . . $ `melder/melder.h:44:9`! gammacxx . . $ structHMMBaumWelch#gamma..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (it) <<=cxx . . $ `operator<<=`(74defdd9e9be7864). mycxx . . $ `melder/melder.h:44:9`! alphacxx . . $ structHMMBaumWelch#alpha..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (it) *cxx . . $ `operator*`(8a83e1da43fd4c40). mycxx . . $ `melder/melder.h:44:9`! betacxx . . $ structHMMBaumWelch#beta..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (it); |
| 248 | mycxx . . $ `melder/melder.h:44:9`! gammacxx . . $ structHMMBaumWelch#gamma..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (it) /=cxx . . $ `operator/=`(c555d170d72ff256). NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (mycxx . . $ `melder/melder.h:44:9`! gammacxx . . $ structHMMBaumWelch#gamma..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (it)); |
| 249 | } |
| 250 | } |
| 251 | |
| 252 | /**************** HMMViterbi ******************************/ |
| 253 | |
| 254 | autoHMMViterbi HMMViterbi_createcxx . . $ HMMViterbi_create(15b93c76f9bd1b11). (integercxx . . $ integer# nstates, integercxx . . $ integer# ntimes) { |
| 255 | try { |
| 256 | autoHMMViterbi me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMViterbi); |
| 257 | mycxx . . $ `melder/melder.h:44:9`! numberOfTimes = ntimes; |
| 258 | mycxx . . $ `melder/melder.h:44:9`! numberOfStates = nstates; |
| 259 | mycxx . . $ `melder/melder.h:44:9`! viterbi =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (nstates, ntimes); |
| 260 | mycxx . . $ `melder/melder.h:44:9`! bp =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_INTMATcxx . . $ zero_INTMAT(4cdd710bd00a100c). (nstates, ntimes); |
| 261 | mycxx . . $ `melder/melder.h:44:9`! path =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (ntimes); |
| 262 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 263 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 264 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMViterbi not created."); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /******************* HMMObservationSequence & HMMStateSequence ***/ |
| 269 | |
| 270 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# HMMObservationSequence_createcxx . . $ HMMObservationSequence_create(bdb3e019206155cd). (integercxx . . $ integer# numberOfItems, integercxx . . $ integer# dataLength) { |
| 271 | try { |
| 272 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMObservationSequence); |
| 273 | Table_initWithoutColumnNamescxx . . $ Table_initWithoutColumnNames(20f8c83fcf38073c). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfItems, dataLength + 1); |
| 274 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 275 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 276 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMObservationSequence not created."); |
| 277 | } |
| 278 | } |
| 279 | |
| 280 | integercxx . . $ integer# HMMObservationSequence_getNumberOfObservationscxx . . $ HMMObservationSequence_getNumberOfObservations(60f64ad3800af0f2). (HMMObservationSequencecxx . . $ HMMObservationSequence# me) { |
| 281 | return mycxx . . $ `melder/melder.h:44:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; |
| 282 | } |
| 283 | |
| 284 | void HMMObservationSequence_removeObservationcxx . . $ HMMObservationSequence_removeObservation(349f1e54c771e9c9). (HMMObservationSequencecxx . . $ HMMObservationSequence# me, integercxx . . $ integer# index) { |
| 285 | Table_removeRowcxx . . $ Table_removeRow(305df77d18352539). (me, index); |
| 286 | } |
| 287 | |
| 288 | autoStringscxx . . $ autoStrings# HMMObservationSequence_to_Stringscxx . . $ HMMObservationSequence_to_Strings(96468204c8f86caf). (HMMObservationSequencecxx . . $ HMMObservationSequence# me) { |
| 289 | try { |
| 290 | const integercxx . . $ integer# numberOfStrings = mycxx . . $ `melder/melder.h:44:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; |
| 291 | autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 292 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (numberOfStrings); |
| 293 | for (integercxx . . $ integer# i = 1; i <= numberOfStrings; i ++) |
| 294 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (Table_getStringValue_acxx . . $ Table_getStringValue_a(cfd7ed372be58fba). (me, i, 1)); |
| 295 | thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = numberOfStrings; |
| 296 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 297 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 298 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Strings created."); |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# Strings_to_HMMObservationSequencecxx . . $ Strings_to_HMMObservationSequence(f78a6c939a57c1f9). (Stringscxx . . $ Strings# me) { |
| 303 | try { |
| 304 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# thee = HMMObservationSequence_createcxx . . $ HMMObservationSequence_create(bdb3e019206155cd). (mycxx . . $ `melder/melder.h:44:9`! numberOfStringscxx . . $ structStrings#numberOfStrings., 0); |
| 305 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; i ++) |
| 306 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, 1, mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 307 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 308 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 309 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no HMMObservationSequence created."); |
| 310 | } |
| 311 | } |
| 312 | |
| 313 | autoStringsIndexcxx . . $ autoStringsIndex# HMMObservationSequence_to_StringsIndexcxx . . $ HMMObservationSequence_to_StringsIndex(4732b0865f9e9dd7). (HMMObservationSequencecxx . . $ HMMObservationSequence# me) { |
| 314 | try { |
| 315 | autoStringscxx . . $ autoStrings# s = HMMObservationSequence_to_Stringscxx . . $ HMMObservationSequence_to_Strings(96468204c8f86caf). (me); |
| 316 | autoStringsIndexcxx . . $ autoStringsIndex# thee = Strings_to_StringsIndexcxx . . $ Strings_to_StringsIndex(786a22033bf23ced). (s.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), kStrings_sortingcxx . . $ kStrings_sorting#::NUMBER_AWAREcxx . . $ kStrings_sorting#NUMBER_AWARE.); |
| 317 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 318 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 319 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no StringsIndex created."); |
| 320 | } |
| 321 | } |
| 322 | |
| 323 | integercxx . . $ integer# HMM_HMMObservationSequence_getLongestSequencecxx . . $ HMM_HMMObservationSequence_getLongestSequence(e11513b56c8cdb0b). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee, integercxx . . $ integer# symbolNumber) { |
| 324 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (me, thee); |
| 325 | // TODO |
| 326 | (void) symbolNumber; |
| 327 | return 1; |
| 328 | } |
| 329 | |
| 330 | integercxx . . $ integer# HMMObservationSequenceBag_getLongestSequencecxx . . $ HMMObservationSequenceBag_getLongestSequence(79cdb932a9531ff3). (HMMObservationSequenceBagcxx . . $ HMMObservationSequenceBag# me) { |
| 331 | integercxx . . $ integer# longest = 0; |
| 332 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! sizecxx . . $ CollectionOf#size.; i ++) { |
| 333 | HMMObservationSequencecxx . . $ HMMObservationSequence# thee = mycxx . . $ `melder/melder.h:44:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 334 | if (thycxx . . $ `melder/melder.h:45:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size. > longest) |
| 335 | longest = thycxx . . $ `melder/melder.h:45:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; |
| 336 | } |
| 337 | return longest; |
| 338 | } |
| 339 | |
| 340 | autoHMMStateSequencecxx . . $ autoHMMStateSequence# HMMStateSequence_createcxx . . $ HMMStateSequence_create(9c2f169a35e53358). (integercxx . . $ integer# numberOfItems) { |
| 341 | try { |
| 342 | autoHMMStateSequencecxx . . $ autoHMMStateSequence# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMMStateSequence); |
| 343 | mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (numberOfItems); |
| 344 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 345 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 346 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMMStateSequence not created."); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | autoStringscxx . . $ autoStrings# HMMStateSequence_to_Stringscxx . . $ HMMStateSequence_to_Strings(ba26850bc1662146). (HMMStateSequencecxx . . $ HMMStateSequence# me) { |
| 351 | try { |
| 352 | autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 353 | mycxx . . $ `melder/melder.h:44:9`! structStringscxx . . $ structStrings# :: v1_copycxx . . $ structStrings#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 354 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 355 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 356 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no Strings created."); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | |
| 361 | /**************** HMM ******************************/ |
| 362 | |
| 363 | void structHMM :: v1_info () { |
| 364 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 365 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of states: ", numberOfStates); |
| 366 | for (integercxx . . $ integer# i = 1; i <= numberOfStates; i ++) { |
| 367 | const HMMState hmms = ourcxx . . $ `melder/melder.h:42:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 368 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" ", hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 369 | } |
| 370 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of symbols: ", numberOfObservationSymbols); |
| 371 | for (integercxx . . $ integer# i = 1; i <= numberOfObservationSymbols; i ++) { |
| 372 | const HMMObservation hmms = ourcxx . . $ `melder/melder.h:42:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 373 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" ", hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | static void HMM_initcxx . . $ HMM_init(251b2de7ddb14373). (HMM me, integercxx . . $ integer# numberOfStates, integercxx . . $ integer# numberOfObservationSymbols, int leftToRight) { |
| 378 | mycxx . . $ `melder/melder.h:44:9`! numberOfStates = numberOfStates; |
| 379 | mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols = numberOfObservationSymbols; |
| 380 | mycxx . . $ `melder/melder.h:44:9`! componentStorage = kHMMstorage::DIAGONALS; |
| 381 | mycxx . . $ `melder/melder.h:44:9`! leftToRight = leftToRight; |
| 382 | mycxx . . $ `melder/melder.h:44:9`! states =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). HMMStateList_createcxx . . $ HMMStateList_create(979835337f2e871a). (); |
| 383 | mycxx . . $ `melder/melder.h:44:9`! observationSymbols =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). HMMObservationList_createcxx . . $ HMMObservationList_create(58a4effd1b6cf74c). (); |
| 384 | mycxx . . $ `melder/melder.h:44:9`! initialStateProbs =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (numberOfStates); |
| 385 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (numberOfStates, numberOfStates + 1); |
| 386 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs =cxx . . $ automatrix#`operator=`(a0f46581f260c488). zero_MATcxx . . $ zero_MAT(3d09731056d2b97d). (numberOfStates, numberOfObservationSymbols); |
| 387 | HMM_setDefaultInitialStateProbscxx . . $ HMM_setDefaultInitialStateProbs(6efb248da18d5537). (me); |
| 388 | HMM_setDefaultTransitionProbscxx . . $ HMM_setDefaultTransitionProbs(6efb248da18d5537). (me); |
| 389 | HMM_setDefaultEmissionProbscxx . . $ HMM_setDefaultEmissionProbs(6efb248da18d5537). (me); |
| 390 | } |
| 391 | |
| 392 | autoHMM HMM_createcxx . . $ HMM_create(cf580d37068cbc4f). (int leftToRight, integercxx . . $ integer# numberOfStates, integercxx . . $ integer# numberOfObservationSymbols) { |
| 393 | try { |
| 394 | autoHMM me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMM); |
| 395 | HMM_initcxx . . $ HMM_init(251b2de7ddb14373). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfStates, numberOfObservationSymbols, leftToRight); |
| 396 | HMM_setDefaultStatescxx . . $ HMM_setDefaultStates(6efb248da18d5537). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 397 | HMM_setDefaultObservationscxx . . $ HMM_setDefaultObservations(6efb248da18d5537). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 398 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 399 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 400 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"HMM not created."); |
| 401 | } |
| 402 | } |
| 403 | |
| 404 | void HMM_setDefaultStatescxx . . $ HMM_setDefaultStates(6efb248da18d5537). (HMM me) { |
| 405 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; i ++) { |
| 406 | autoHMMState hmms = HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"S", i)); |
| 407 | HMM_addState_movecxx . . $ HMM_addState_move(a47c88543731af7f). (me, hmmscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | autoHMM HMM_createFullContinuousModelcxx . . $ HMM_createFullContinuousModel(ebd09483673e14f6). (int leftToRight, integercxx . . $ integer# numberOfStates, integercxx . . $ integer# numberOfObservationSymbols, integercxx . . $ integer# numberOfFeatureStreams, integercxx . . $ integer# *dimensionOfStream, integercxx . . $ integer# *numberOfGaussiansforStream) { |
| 412 | (void) leftToRight; |
| 413 | (void) numberOfStates; |
| 414 | (void) numberOfObservationSymbols; |
| 415 | (void) numberOfFeatureStreams; |
| 416 | (void) dimensionOfStream; |
| 417 | (void) numberOfGaussiansforStream; |
| 418 | return autoHMMcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(); |
| 419 | } |
| 420 | |
| 421 | autoHMM HMM_createContinuousModelcxx . . $ HMM_createContinuousModel(4b9844b0026e562). (int leftToRight, integercxx . . $ integer# numberOfStates, integercxx . . $ integer# numberOfObservationSymbols, integercxx . . $ integer# numberOfMixtureComponentsPerSymbol, integercxx . . $ integer# componentDimension, kHMMstorage componentStorage) { |
| 422 | try { |
| 423 | autoHMM me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMM); |
| 424 | HMM_initcxx . . $ HMM_init(251b2de7ddb14373). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfStates, numberOfObservationSymbols, leftToRight); |
| 425 | mycxx . . $ `melder/melder.h:44:9`! numberOfMixtureComponents = numberOfMixtureComponentsPerSymbol; |
| 426 | mycxx . . $ `melder/melder.h:44:9`! componentDimension = componentDimension; |
| 427 | mycxx . . $ `melder/melder.h:44:9`! componentStorage = componentStorage; |
| 428 | for (integercxx . . $ integer# i = 1; i <= numberOfStates; i ++) { |
| 429 | autoHMMState state = HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"S", i)); |
| 430 | HMM_addState_movecxx . . $ HMM_addState_move(a47c88543731af7f). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), statecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 431 | } |
| 432 | for (integercxx . . $ integer# j = 1; j <= numberOfObservationSymbols; j ++) { |
| 433 | autoHMMObservation obs = HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"s", j), numberOfMixtureComponentsPerSymbol, componentDimension, componentStorage); |
| 434 | HMM_addObservation_movecxx . . $ HMM_addObservation_move(146d2ca70b877b86). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 435 | } |
| 436 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 437 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 438 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Continuous model HMM not created."); |
| 439 | } |
| 440 | } |
| 441 | |
| 442 | // for a simple non-hidden model leave either states empty or symbols empty !!! |
| 443 | autoHMM HMM_createSimplecxx . . $ HMM_createSimple(2c3c45445b5abe78). (int leftToRight, conststring32cxx . . $ conststring32# states_string, conststring32cxx . . $ conststring32# symbols_string) { |
| 444 | try { |
| 445 | autoSTRVECcxx . . $ autoSTRVEC# states = splitByWhitespace_STRVECcxx . . $ splitByWhitespace_STRVEC(d3c03a92d990d008). (states_string); |
| 446 | autoSTRVECcxx . . $ autoSTRVEC# symbols = splitByWhitespace_STRVECcxx . . $ splitByWhitespace_STRVEC(d3c03a92d990d008). (symbols_string); |
| 447 | autoHMM me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMM); |
| 448 | |
| 449 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (states.size > 0 || symbols.size > 0, |
| 450 | U"The states and symbols should not both be empty."); |
| 451 | |
| 452 | if (symbols.sizecxx . . $ _autostringautovector#size. == 0) { |
| 453 | symbols =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). copy_STRVECcxx . . $ copy_STRVEC(cfa8029879abedac). (statescxx . . $ _conststringvector#_conststringvector(93d9e701af42cb0d)..getcxx . . $ _autostringautovector#get(9d56076a9ef7dd02).()); |
| 454 | mycxx . . $ `melder/melder.h:44:9`! notHidden = 1; |
| 455 | } |
| 456 | if (states.sizecxx . . $ _autostringautovector#size. == 0) { |
| 457 | states =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). copy_STRVECcxx . . $ copy_STRVEC(cfa8029879abedac). (symbolscxx . . $ _conststringvector#_conststringvector(93d9e701af42cb0d)..getcxx . . $ _autostringautovector#get(9d56076a9ef7dd02).()); |
| 458 | mycxx . . $ `melder/melder.h:44:9`! notHidden = 1; |
| 459 | } |
| 460 | |
| 461 | HMM_initcxx . . $ HMM_init(251b2de7ddb14373). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), states.sizecxx . . $ _autostringautovector#size., symbols.sizecxx . . $ _autostringautovector#size., leftToRight); |
| 462 | |
| 463 | for (integercxx . . $ integer# istate = 1; istate <= states.sizecxx . . $ _autostringautovector#size.; istate ++) { |
| 464 | autoHMMState state = HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (states [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).istate].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 465 | HMM_addState_movecxx . . $ HMM_addState_move(a47c88543731af7f). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), statecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 466 | } |
| 467 | for (integercxx . . $ integer# isymbol = 1; isymbol <= symbols.sizecxx . . $ _autostringautovector#size.; isymbol ++) { |
| 468 | autoHMMObservation symbol = HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (symbols [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).isymbol].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0, 0, kHMMstorage::DIAGONALS); |
| 469 | HMM_addObservation_movecxx . . $ HMM_addObservation_move(146d2ca70b877b86). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), symbolcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 470 | } |
| 471 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 472 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 473 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Simple HMM not created."); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | void HMM_setDefaultObservationscxx . . $ HMM_setDefaultObservations(6efb248da18d5537). (HMM me) { |
| 478 | const conststring32cxx . . $ conststring32# def = ( mycxx . . $ `melder/melder.h:44:9`! notHidden ? U"S" : U"s" ); |
| 479 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; i ++) { |
| 480 | autoHMMObservation hmms = HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (def, i), 0, 0, kHMMstorage::DIAGONALS); |
| 481 | HMM_addObservation_movecxx . . $ HMM_addObservation_move(146d2ca70b877b86). (me, hmmscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | void HMM_setDefaultTransitionProbscxx . . $ HMM_setDefaultTransitionProbs(6efb248da18d5537). (HMM me) { |
| 486 | if (mycxx . . $ `melder/melder.h:44:9`! leftToRight) { |
| 487 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; irow ++) { |
| 488 | const double p = 1.0 / (mycxx . . $ `melder/melder.h:44:9`! numberOfStates - irow + 1.0); |
| 489 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (irow).partcxx . . $ vector#part(ae267db9e2c04be7). (irow, mycxx . . $ `melder/melder.h:44:9`! numberOfStates) <<=cxx . . $ `operator<<=`(c555d170d72ff256). p; |
| 490 | } |
| 491 | // leftToRight must have end state! |
| 492 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).mycxx . . $ `melder/melder.h:44:9`! numberOfStates] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates] = |
| 493 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).mycxx . . $ `melder/melder.h:44:9`! numberOfStates] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] = 0.5; |
| 494 | } else { |
| 495 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs.partcxx . . $ automatrix#part(5c23e73480cfacfb). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates, 1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates) <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 1.0 / mycxx . . $ `melder/melder.h:44:9`! numberOfStates; |
| 496 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs.columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1) <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 497 | } |
| 498 | } |
| 499 | |
| 500 | void HMM_setDefaultInitialStateProbscxx . . $ HMM_setDefaultInitialStateProbs(6efb248da18d5537). (HMM me) { |
| 501 | mycxx . . $ `melder/melder.h:44:9`! initialStateProbs.getcxx . . $ autovector#get(e8d1da7fe68a6585). () <<=cxx . . $ `operator<<=`(c555d170d72ff256). 1.0 / mycxx . . $ `melder/melder.h:44:9`! numberOfStates; |
| 502 | } |
| 503 | |
| 504 | void HMM_setDefaultEmissionProbscxx . . $ HMM_setDefaultEmissionProbs(6efb248da18d5537). (HMM me) { |
| 505 | if (mycxx . . $ `melder/melder.h:44:9`! notHidden) { |
| 506 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs.getcxx . . $ automatrix#get(b2b81450b5bdda66).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 507 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs.diagonalcxx . . $ automatrix#diagonal(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). 1.0; |
| 508 | } else |
| 509 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs.partcxx . . $ automatrix#part(5c23e73480cfacfb). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates, 1, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols) <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 1.0 / mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; |
| 510 | } |
| 511 | |
| 512 | void HMM_setDefaultMixingProbabilitiescxx . . $ HMM_setDefaultMixingProbabilities(6efb248da18d5537). (HMM me) { |
| 513 | const double mp = 1.0 / mycxx . . $ `melder/melder.h:44:9`! numberOfMixtureComponents; |
| 514 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; is ++) { |
| 515 | HMMObservation hmmo = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 516 | hmmo -> gm ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). mixingProbabilitiescxx . . $ structGaussianMixture#mixingProbabilities..allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). mp; |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | // evaluate the numbers given to probabilities |
| 521 | static autoVECcxx . . $ autoVEC# normalizeProbabilities_VECcxx . . $ normalizeProbabilities_VEC(51d4ef5c83ed04c5). (constVECVUcxx . . $ constVECVU# const& relativeProbabilities, integercxx . . $ integer# nwanted) { |
| 522 | if (relativeProbabilities.sizecxx . . $ constvectorview#size. != nwanted) |
| 523 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"You supplied ", relativeProbabilities.size, U" numbers, whereas we need ", nwanted, U" numbers."); |
| 524 | for (integercxx . . $ integer# i = 1; i <= relativeProbabilities.sizecxx . . $ constvectorview#size.; i ++) |
| 525 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (relativeProbabilities [i] >= 0.0, |
| 526 | U"Relative probabilities have to be non-negative."); |
| 527 | const double sum = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (relativeProbabilities); |
| 528 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (sum > 0.0, |
| 529 | U"All probabilities cannot be zero."); |
| 530 | autoVECcxx . . $ autoVEC# absoluteProbabilities = copy_VECcxx . . $ copy_VEC(d4415e68b25283a8). (relativeProbabilities); |
| 531 | absoluteProbabilities.allcxx . . $ autovector#all(a26726dad87555bb).() /=cxx . . $ `operator/=`(c555d170d72ff256). sum; |
| 532 | return absoluteProbabilitiescxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 533 | } |
| 534 | |
| 535 | void HMM_setStartProbabilitiescxx . . $ HMM_setStartProbabilities(201a3d0dac5ab6fa). (HMM me, constVECVUcxx . . $ constVECVU# const& relativeProbabilities) { |
| 536 | try { |
| 537 | autoVECcxx . . $ autoVEC# absoluteProbabilities = normalizeProbabilities_VECcxx . . $ normalizeProbabilities_VEC(51d4ef5c83ed04c5). (relativeProbabilities, mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 538 | mycxx . . $ `melder/melder.h:44:9`! initialStateProbs.allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(adea042513329390). absoluteProbabilitiescxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 539 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 540 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no start probabilities set."); |
| 541 | } |
| 542 | } |
| 543 | |
| 544 | void HMM_setTransitionProbabilitiescxx . . $ HMM_setTransitionProbabilities(825fcdb86698f8a6). (HMM me, integercxx . . $ integer# state_number, constVECVUcxx . . $ constVECVU# const& relativeProbabilities) { |
| 545 | try { |
| 546 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (state_number <= mycxx . . $ `melder/melder.h:44:9`! states->size, |
| 547 | U"State number should not exceed ", mycxx . . $ `melder/melder.h:44:9`! states->size, U"."); |
| 548 | autoVECcxx . . $ autoVEC# absoluteProbabilities = normalizeProbabilities_VECcxx . . $ normalizeProbabilities_VEC(51d4ef5c83ed04c5). (relativeProbabilities, mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 549 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (state_number).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates) <<=cxx . . $ `operator<<=`(adea042513329390). absoluteProbabilitiescxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 550 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 551 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition probabilities set."); |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | void HMM_setEmissionProbabilitiescxx . . $ HMM_setEmissionProbabilities(825fcdb86698f8a6). (HMM me, integercxx . . $ integer# state_number, constVECVUcxx . . $ constVECVU# const& relativeProbabilities) { |
| 556 | try { |
| 557 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (state_number <= mycxx . . $ `melder/melder.h:44:9`! states->size, |
| 558 | U"State number should not exceed ", mycxx . . $ `melder/melder.h:44:9`! states->size, U"."); |
| 559 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (! mycxx . . $ `melder/melder.h:44:9`! notHidden, |
| 560 | U"The emission probabilities of this model are fixed."); |
| 561 | autoVECcxx . . $ autoVEC# absoluteProbabilities = normalizeProbabilities_VECcxx . . $ normalizeProbabilities_VEC(51d4ef5c83ed04c5). (relativeProbabilities, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols); |
| 562 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (state_number).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols) <<=cxx . . $ `operator<<=`(adea042513329390). absoluteProbabilitiescxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 563 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 564 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no emission probabilities set."); |
| 565 | } |
| 566 | } |
| 567 | |
| 568 | void HMM_addObservation_movecxx . . $ HMM_addObservation_move(146d2ca70b877b86). (HMM me, autoHMMObservation thee) { |
| 569 | const integercxx . . $ integer# ns = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size. + 1; |
| 570 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (ns <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols, U"Observation list is full."); |
| 571 | mycxx . . $ `melder/melder.h:44:9`! observationSymbols ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), ns); |
| 572 | } |
| 573 | |
| 574 | void HMM_addState_movecxx . . $ HMM_addState_move(a47c88543731af7f). (HMM me, autoHMMState thee) { |
| 575 | const integercxx . . $ integer# ns = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size. + 1; |
| 576 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (ns <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates, U"States list is full."); |
| 577 | mycxx . . $ `melder/melder.h:44:9`! states ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), ns); |
| 578 | } |
| 579 | |
| 580 | autoTableOfRealcxx . . $ autoTableOfReal# HMM_extractTransitionProbabilitiescxx . . $ HMM_extractTransitionProbabilities(fc64821279f9062c). (HMM me) { |
| 581 | try { |
| 582 | autoTableOfRealcxx . . $ autoTableOfReal# thee = TableOfReal_createcxx . . $ TableOfReal_create(e573ed3514e79d3). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1); |
| 583 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! initialStateProbs.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 584 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 585 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 586 | TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), is + 1, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 587 | TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), is, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 588 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (is + 1).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates) <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (is).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 589 | } |
| 590 | TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, U"START"); |
| 591 | TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1, U"END"); |
| 592 | //thy data.column (my numberOfStates + 1).part (2, my numberOfStates) <<= my transitionProbs.column (my numberOfStates + 1 ); |
| 593 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 594 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] = mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1]; |
| 595 | } |
| 596 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 597 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 598 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition probabilities extracted."); |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | autoTableOfRealcxx . . $ autoTableOfReal# HMM_extractEmissionProbabilitiescxx . . $ HMM_extractEmissionProbabilities(fc64821279f9062c). (HMM me) { |
| 603 | try { |
| 604 | autoTableOfRealcxx . . $ autoTableOfReal# thee = TableOfReal_createcxx . . $ TableOfReal_create(e573ed3514e79d3). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols); |
| 605 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; js ++) { |
| 606 | const HMMObservation hmms = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).js]; |
| 607 | TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), js, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 608 | } |
| 609 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 610 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 611 | TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), is, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 612 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; js ++) |
| 613 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] = mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js]; |
| 614 | } |
| 615 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 616 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 617 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no emission probabilities extracted."); |
| 618 | }; |
| 619 | } |
| 620 | |
| 621 | double HMM_getExpectedValueOfDurationInStatecxx . . $ HMM_getExpectedValueOfDurationInState(b5d3b510bb3a6f4a). (HMM me, integercxx . . $ integer# istate) { |
| 622 | if (istate < 0 || istate > mycxx . . $ `melder/melder.h:44:9`! numberOfStates) |
| 623 | return undefinedcxx . . $ undefined.; |
| 624 | return 1.0 / (1.0 - mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).istate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).istate]); |
| 625 | } |
| 626 | |
| 627 | double HMM_getProbabilityOfStayingInStatecxx . . $ HMM_getProbabilityOfStayingInState(a5dc8f3f179118c1). (HMM me, integercxx . . $ integer# istate, integercxx . . $ integer# numberOfTimeUnits) { |
| 628 | if (istate < 0 || istate > mycxx . . $ `melder/melder.h:44:9`! numberOfStates) |
| 629 | return undefinedcxx . . $ undefined.; |
| 630 | return powcxx . . $ pow(b71928d39fde4295). (mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).istate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).istate], numberOfTimeUnits - 1.0) * (1.0 - mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).istate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).istate]); |
| 631 | } |
| 632 | |
| 633 | double HMM_HMM_getCrossEntropycxx . . $ HMM_HMM_getCrossEntropy(e83ce15ac0166a82). (HMM me, HMM thee, integercxx . . $ integer# observationLength, int symmetric) { |
| 634 | const double ce1 = HMM_HMM_getCrossEntropy_asymcxx . . $ HMM_HMM_getCrossEntropy_asym(69e294df27e76719). (me, thee, observationLength); |
| 635 | if (! symmetric || isundefcxx . . $ isundef(f8197d536af80c96). (ce1)) |
| 636 | return ce1; |
| 637 | const double ce2 = HMM_HMM_getCrossEntropy_asymcxx . . $ HMM_HMM_getCrossEntropy_asym(69e294df27e76719). (thee, me, observationLength); |
| 638 | if (isundefcxx . . $ isundef(f8197d536af80c96). (ce2)) |
| 639 | return ce2; |
| 640 | return (ce1 + ce2) / 2.0; |
| 641 | } |
| 642 | |
| 643 | double HMM_HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMM_HMMObservationSequence_getCrossEntropy(704f2298e8fb2cba). (HMM me, HMM thee, HMMObservationSequencecxx . . $ HMMObservationSequence# him) { |
| 644 | const double ce1 = HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (me, him); |
| 645 | if (isundefcxx . . $ isundef(f8197d536af80c96). (ce1)) |
| 646 | return ce1; |
| 647 | const double ce2 = HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (thee, him); |
| 648 | if (isundefcxx . . $ isundef(f8197d536af80c96). (ce2)) |
| 649 | return ce2; |
| 650 | return (ce1 + ce2) / 2.0; |
| 651 | } |
| 652 | |
| 653 | void HMM_drawcxx . . $ HMM_draw(9b70ab1338808ba2). (HMM me, Graphicscxx . . $ Graphics# g, bool garnish) { |
| 654 | const double xwidth = sqrtcxx . . $ sqrt(7759b11ec49fe502). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 655 | const double rstate = 0.3 / xwidth, r = xwidth / 3.0; |
| 656 | const double xmax = 1.2 * xwidth / 2.0, xmin = -xmax, ymin = xmin, ymax = xmax; |
| 657 | |
| 658 | autoVECcxx . . $ autoVEC# xs = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 659 | autoVECcxx . . $ autoVEC# ys = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 660 | |
| 661 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 662 | // heuristic: all states on a circle until we have a better graph drawing algorithm. |
| 663 | xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = 0.0; |
| 664 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfStates > 1) { |
| 665 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 666 | const double alpha = - NUMpicxx . . $ NUMpi. + NUMpicxx . . $ NUMpi. * 2.0 * (is - 1) / mycxx . . $ `melder/melder.h:44:9`! numberOfStates; |
| 667 | xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] = r * coscxx . . $ cos(fee4f1d22bc8e617). (alpha); ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] = r * sincxx . . $ sin(fee4f1d22bc8e617). (alpha); |
| 668 | } |
| 669 | } |
| 670 | // reorder the positions such that state number 1 is most left and last state number is right. |
| 671 | // if > 5 may be one in the middle with the most connections |
| 672 | // ... |
| 673 | // find fontsize |
| 674 | const double fontSize = Graphics_inqFontSizecxx . . $ Graphics_inqFontSize(f906975acce41a59). (g); |
| 675 | conststring32cxx . . $ conststring32# widest_label = U""; |
| 676 | double max_width = 0.0; |
| 677 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 678 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 679 | const double w = ( hmms -> label ? Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : 0.0 ); |
| 680 | if (w > max_width) { |
| 681 | widest_label = hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 682 | max_width = w; |
| 683 | } |
| 684 | } |
| 685 | double new_fontSize = fontSize; |
| 686 | while (max_width > 2.0 * rstate && new_fontSize > 4) { |
| 687 | new_fontSize --; |
| 688 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, new_fontSize); |
| 689 | max_width = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, widest_label); |
| 690 | } |
| 691 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, new_fontSize); |
| 692 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 693 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 694 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 695 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is], ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is], rstate); |
| 696 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is], ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is], hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 697 | } |
| 698 | |
| 699 | // draw connections from is to js |
| 700 | // 1 -> 2 / 2-> : increase / decrease angle between 1 and 2 with pi /10 |
| 701 | // use cos(a+b) and cos(a -b) rules |
| 702 | const double cosb = coscxx . . $ cos(fee4f1d22bc8e617). (NUMpicxx . . $ NUMpi. / 10.0), sinb = sincxx . . $ sin(fee4f1d22bc8e617). (NUMpicxx . . $ NUMpi. / 10.0); |
| 703 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 704 | const double x1 = xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is], y1 = ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is]; |
| 705 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 706 | if (mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] > 0.0 && is != js) { |
| 707 | const double x2 = xs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js], y2 = ys [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js]; |
| 708 | const double dx = x2 - x1, dy = y2 - y1, h = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (dx * dx + dy * dy), cosa = dx / h, sina = dy / h; |
| 709 | const double cosabp = cosa * cosb - sina * sinb, cosabm = cosa * cosb + sina * sinb; |
| 710 | const double sinabp = cosa * sinb + sina * cosb, sinabm = -cosa * sinb + sina * cosb; |
| 711 | Graphics_arrowcxx . . $ Graphics_arrow(72bdb7937dbb13da). (g, x1 + rstate * cosabp, y1 + rstate * sinabp, x2 - rstate * cosabm, y2 - rstate * sinabm); |
| 712 | } |
| 713 | if (is == js) { |
| 714 | const double dx = - x1, dy = - y1, h = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (dx * dx + dy * dy), cosa = dx / h, sina = dy / h; |
| 715 | Graphics_doubleArrowcxx . . $ Graphics_doubleArrow(72bdb7937dbb13da). (g, x1 - rstate * cosa, y1 - rstate * sina, x1 - 1.4 * rstate * cosa, y1 - 1.4 * rstate * sina); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | if (garnish) { |
| 720 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 721 | } |
| 722 | } |
| 723 | |
| 724 | void HMM_unExpandPCAcxx . . $ HMM_unExpandPCA(6efb248da18d5537). (HMM me) { |
| 725 | if (mycxx . . $ `melder/melder.h:44:9`! componentDimension <= 0) |
| 726 | return; // nothing to do |
| 727 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; is ++) { |
| 728 | const HMMObservation s = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 729 | GaussianMixture_unExpandPCAcxx . . $ GaussianMixture_unExpandPCA(a29c70c932200d85). (s -> gm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 730 | } |
| 731 | } |
| 732 | |
| 733 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# HMM_to_HMMObservationSequencecxx . . $ HMM_to_HMMObservationSequence(d1c4b4e14e520387). (HMM me, integercxx . . $ integer# startState, integercxx . . $ integer# numberOfItems) { |
| 734 | try { |
| 735 | autoHMMObservationSequencecxx . . $ autoHMMObservationSequence# thee = HMMObservationSequence_createcxx . . $ HMMObservationSequence_create(bdb3e019206155cd). (numberOfItems, mycxx . . $ `melder/melder.h:44:9`! componentDimension); |
| 736 | integercxx . . $ integer# istate = ( startState == 0 ? NUMgetIndexFromProbabilitycxx . . $ NUMgetIndexFromProbability(38981f9d60616ce2). (mycxx . . $ `melder/melder.h:44:9`! initialStateProbs.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0)) : startState ); |
| 737 | if (mycxx . . $ `melder/melder.h:44:9`! componentDimension > 0) { |
| 738 | autoVECcxx . . $ autoVEC# obs = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! componentDimension); |
| 739 | autoVECcxx . . $ autoVEC# buf = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! componentDimension); |
| 740 | for (integercxx . . $ integer# i = 1; i <= numberOfItems; i ++) { |
| 741 | // Emit a symbol from istate |
| 742 | |
| 743 | const integercxx . . $ integer# isymbol = NUMgetIndexFromProbabilitycxx . . $ NUMgetIndexFromProbability(38981f9d60616ce2). (mycxx . . $ `melder/melder.h:44:9`! emissionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (istate), NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0)); |
| 744 | const HMMObservation s = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isymbol]; |
| 745 | GaussianMixture_generateOneVector_inlinecxx . . $ GaussianMixture_generateOneVector_inline(baab5f7d4314310c). (s -> gm.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obs.getcxx . . $ autovector#get(e8d1da7fe68a6585).(), nullptr, buf.getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 746 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! componentDimension; j ++) |
| 747 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, 1 + j, obs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]); |
| 748 | |
| 749 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, 1, s -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 750 | |
| 751 | // get next state |
| 752 | |
| 753 | istate = NUMgetIndexFromProbabilitycxx . . $ NUMgetIndexFromProbability(38981f9d60616ce2). (mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (istate).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates), NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0)); |
| 754 | if (istate == mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1) { // final state |
| 755 | for (integercxx . . $ integer# j = numberOfItems; j > i; j --) |
| 756 | HMMObservationSequence_removeObservationcxx . . $ HMMObservationSequence_removeObservation(349f1e54c771e9c9). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), j); |
| 757 | break; |
| 758 | } |
| 759 | } |
| 760 | } else { |
| 761 | for (integercxx . . $ integer# i = 1; i <= numberOfItems; i ++) { |
| 762 | // Emit a symbol from istate |
| 763 | |
| 764 | const integercxx . . $ integer# isymbol = NUMgetIndexFromProbabilitycxx . . $ NUMgetIndexFromProbability(38981f9d60616ce2). (mycxx . . $ `melder/melder.h:44:9`! emissionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (istate), NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0)); |
| 765 | HMMObservation s = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).isymbol]; |
| 766 | |
| 767 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, 1, s -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 768 | |
| 769 | // get next state |
| 770 | |
| 771 | istate = NUMgetIndexFromProbabilitycxx . . $ NUMgetIndexFromProbability(38981f9d60616ce2). (mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (istate).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates), NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0)); |
| 772 | if (istate == mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1) { // final state |
| 773 | for (integercxx . . $ integer# j = numberOfItems; j > i; j --) |
| 774 | HMMObservationSequence_removeObservationcxx . . $ HMMObservationSequence_removeObservation(349f1e54c771e9c9). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), j); |
| 775 | break; |
| 776 | } |
| 777 | } |
| 778 | } |
| 779 | |
| 780 | HMM_unExpandPCAcxx . . $ HMM_unExpandPCA(6efb248da18d5537). (me); |
| 781 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 782 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 783 | HMM_unExpandPCAcxx . . $ HMM_unExpandPCA(6efb248da18d5537). (me); |
| 784 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U":no HMMObservationSequence created."); |
| 785 | } |
| 786 | } |
| 787 | |
| 788 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# HMM_forwardcxx . . $ HMM_forward(1c565d6cf11da809). (HMM me, constINTVECcxx . . $ constINTVEC# obs) { |
| 789 | try { |
| 790 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# thee = HMMBaumWelch_createcxx . . $ HMMBaumWelch_create(a9645a0ad7322db7). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols, obs.sizecxx . . $ constvector#size.); |
| 791 | HMM_HMMBaumWelch_forwardcxx . . $ HMM_HMMBaumWelch_forward(997908ed33d9aa40). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obs); |
| 792 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 793 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 794 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no HMMBaumWelch created."); |
| 795 | } |
| 796 | } |
| 797 | |
| 798 | static autoHMMViterbi HMM_to_HMMViterbicxx . . $ HMM_to_HMMViterbi(63cc62d0703e50cd). (HMM me, constINTVECcxx . . $ constINTVEC# obs) { |
| 799 | try { |
| 800 | autoHMMViterbi thee = HMMViterbi_createcxx . . $ HMMViterbi_create(15b93c76f9bd1b11). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates, obs.sizecxx . . $ constvector#size.); |
| 801 | HMM_HMMViterbi_decodecxx . . $ HMM_HMMViterbi_decode(f8c11026b00d51af). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obs); |
| 802 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 803 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 804 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no HMMViterbi created."); |
| 805 | } |
| 806 | } |
| 807 | |
| 808 | void HMMBaumWelch_reInitcxx . . $ HMMBaumWelch_reInit(5b8f7ffbd72becf8). (HMMBaumWelchcxx . . $ HMMBaumWelch# me) { |
| 809 | mycxx . . $ `melder/melder.h:44:9`! totalNumberOfSequencescxx . . $ structHMMBaumWelch#totalNumberOfSequences. = 0; |
| 810 | mycxx . . $ `melder/melder.h:44:9`! lnProbcxx . . $ structHMMBaumWelch#lnProb. = 0.0; |
| 811 | |
| 812 | /* |
| 813 | The _num and _denum matrices are assigned as += in the iteration loop and therefore need to be zeroed |
| 814 | at the start of each new iteration. |
| 815 | The elements of alpha, beta, scale, gamma & xi are always calculated directly and need not be |
| 816 | initialised. |
| 817 | */ |
| 818 | mycxx . . $ `melder/melder.h:44:9`! aij_num_p0cxx . . $ structHMMBaumWelch#aij_num_p0..allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 819 | mycxx . . $ `melder/melder.h:44:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 820 | mycxx . . $ `melder/melder.h:44:9`! aij_denom_p0cxx . . $ structHMMBaumWelch#aij_denom_p0..allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(c555d170d72ff256). 0.0; |
| 821 | mycxx . . $ `melder/melder.h:44:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 822 | mycxx . . $ `melder/melder.h:44:9`! bik_numcxx . . $ structHMMBaumWelch#bik_num..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 823 | mycxx . . $ `melder/melder.h:44:9`! bik_denomcxx . . $ structHMMBaumWelch#bik_denom..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 824 | } |
| 825 | |
| 826 | static integercxx . . $ integer# HMM_getState_notHiddencxx . . $ HMM_getState_notHidden(2b56c0b6f1e7c864). (HMM me, conststring32cxx . . $ conststring32# stateLabel) { |
| 827 | for (integercxx . . $ integer# istate = 1; istate <= mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size.; istate ++) |
| 828 | if (Melder_cmpcxx . . $ Melder_cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! states ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).istate] -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), stateLabel) == 0) |
| 829 | return istate; |
| 830 | return 0; |
| 831 | } |
| 832 | |
| 833 | /* |
| 834 | Translate the observation sequences to a number of state sequences for not continuous markov models. |
| 835 | A 0 state number signals the start of a new observation sequence. |
| 836 | */ |
| 837 | static autoINTVECcxx . . $ autoINTVEC# HMM_HMMObservationSequenceBag_getStateSequencescxx . . $ HMM_HMMObservationSequenceBag_getStateSequences(53213b70b5adb41c). (HMM me, HMMObservationSequenceBagcxx . . $ HMMObservationSequenceBag# thee) { |
| 838 | /* |
| 839 | Calculate storage needed for state sequence numbers. |
| 840 | */ |
| 841 | integercxx . . $ integer# numberOfElements = 0; |
| 842 | for (integercxx . . $ integer# iseq = 1; iseq <= thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size.; iseq ++) { |
| 843 | const HMMObservationSequencecxx . . $ HMMObservationSequence# hmm_os = thycxx . . $ `melder/melder.h:45:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iseq]; |
| 844 | numberOfElements += hmm_os -> rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size. + 1; // 1 extra for 0 state |
| 845 | } |
| 846 | /* |
| 847 | Get state sequence numbers. |
| 848 | */ |
| 849 | autoINTVECcxx . . $ autoINTVEC# stateSequenceNumbers = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (numberOfElements); |
| 850 | integercxx . . $ integer# numberOfElements2 = 0; |
| 851 | for (integercxx . . $ integer# iseq = 1; iseq <= thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size.; iseq ++) { |
| 852 | const HMMObservationSequencecxx . . $ HMMObservationSequence# hmm_os = thycxx . . $ `melder/melder.h:45:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iseq]; |
| 853 | for (integercxx . . $ integer# islabel = 1; islabel <= hmm_os -> rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; islabel ++) { |
| 854 | const conststring32cxx . . $ conststring32# label = Table_getStringValue_acxx . . $ Table_getStringValue_a(cfd7ed372be58fba). (hmm_os, islabel, 1); |
| 855 | const integercxx . . $ integer# stateNumber = HMM_getState_notHiddencxx . . $ HMM_getState_notHidden(2b56c0b6f1e7c864). (me, label); |
| 856 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (stateNumber > 0, |
| 857 | U"The ", islabel, U"th observation of sequence ", iseq, U" labeled", label, U" is not a valid state."); |
| 858 | stateSequenceNumbers [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ numberOfElements2] = stateNumber; |
| 859 | } |
| 860 | stateSequenceNumbers [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ numberOfElements2] = 0; // signal transition to another observation sequence |
| 861 | } |
| 862 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (numberOfElements == numberOfElements2); |
| 863 | return stateSequenceNumberscxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 864 | } |
| 865 | #if 0 |
| 866 | static void HMM_smoothInitialStateProbs_naive (HMM me, double minProb) { |
| 867 | for (integer is = 1; is <= my numberOfStates; is ++) |
| 868 | my initialStateProbs [is] = std::max (my initialStateProbs [is], minProb ); |
| 869 | /* |
| 870 | Normalize again as probabilities |
| 871 | */ |
| 872 | VECnormalize_inplace (my initialStateProbs.get(), 1.0, 1.0); |
| 873 | } |
| 874 | |
| 875 | static void HMM_smoothTransitionProbs_naive (HMM me, double minProb) { |
| 876 | for (integer irow = 1; irow <= my numberOfStates; irow ++) |
| 877 | for (integer icol = 1; icol <= my numberOfStates; icol ++) |
| 878 | my transitionProbs [irow] [icol] = std::max (my transitionProbs [irow] [icol], minProb); |
| 879 | /* |
| 880 | Normalize again as probabilities |
| 881 | */ |
| 882 | for (integer irow = 1; irow <= my numberOfStates; irow ++) |
| 883 | VECnormalize_inplace (my transitionProbs.row (irow).part (1, my numberOfStates), 1.0, 1.0); |
| 884 | } |
| 885 | |
| 886 | static void HMM_smoothEmissionProbs_naive (HMM me, double minProb) { |
| 887 | for (integer is = 1; is <= my numberOfStates; is ++) |
| 888 | for (integer k = 1; k <= my numberOfObservationSymbols; k ++) |
| 889 | my emissionProbs [is] [k] = std::max (my emissionProbs [is] [k], minProb); |
| 890 | for (integer irow = 1; irow <= my numberOfStates; irow ++) |
| 891 | VECnormalize_inplace (my emissionProbs.row (irow).part (1, my numberOfStates), 1.0, 1.0); |
| 892 | } |
| 893 | #endif |
| 894 | /* |
| 895 | For a not hidden markov model there is an analytical solution for the state transition probabilities |
| 896 | */ |
| 897 | |
| 898 | static void HMM_HMMObservationSequenceBag_learn_notHiddencxx . . $ HMM_HMMObservationSequenceBag_learn_notHidden(c9e5502ed41cf7db). (HMM me, HMMObservationSequenceBagcxx . . $ HMMObservationSequenceBag# thee, double minProb) { |
| 899 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! notHidden); |
| 900 | autoINTVECcxx . . $ autoINTVEC# stateSequenceNumbers = HMM_HMMObservationSequenceBag_getStateSequencescxx . . $ HMM_HMMObservationSequenceBag_getStateSequences(53213b70b5adb41c). (me, thee); |
| 901 | if (stateSequenceNumbers.sizecxx . . $ autovector#size. < 2) |
| 902 | return; |
| 903 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs.allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(50b469ae42a42f64). 0.0; |
| 904 | integercxx . . $ integer# inum = 2; |
| 905 | integercxx . . $ integer# stateNumber = stateSequenceNumbers [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 906 | while (inum < stateSequenceNumbers.sizecxx . . $ autovector#size.) { |
| 907 | const integercxx . . $ integer# stateNumberTo = stateSequenceNumbers [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inum ++]; |
| 908 | if (stateNumberTo != 0) { |
| 909 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).stateNumber] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).stateNumberTo] += 1.0; |
| 910 | stateNumber = stateNumberTo; |
| 911 | } else { |
| 912 | if (inum == stateSequenceNumbers.sizecxx . . $ autovector#size.) |
| 913 | break; |
| 914 | stateNumber = stateSequenceNumbers [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inum ++]; |
| 915 | } |
| 916 | } |
| 917 | /* |
| 918 | Normalize as probabilities |
| 919 | */ |
| 920 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; irow ++) |
| 921 | VECnormalize_inplacecxx . . $ VECnormalize_inplace(963991e5268b1933). (mycxx . . $ `melder/melder.h:44:9`! transitionProbs.rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (irow).partcxx . . $ vector#part(ae267db9e2c04be7). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfStates), 1.0, 1.0); |
| 922 | /* No need to set minimum probabilities */ |
| 923 | } |
| 924 | |
| 925 | |
| 926 | void HMM_HMMObservationSequenceBag_learncxx . . $ HMM_HMMObservationSequenceBag_learn(ff8bd6789787a46c). (HMM me, HMMObservationSequenceBagcxx . . $ HMMObservationSequenceBag# thee, double delta_lnp, double minProb, int info) { |
| 927 | try { |
| 928 | if (mycxx . . $ `melder/melder.h:44:9`! notHidden) { |
| 929 | // For a not hidden markov model there is an analytical solution for the state transition probabilities |
| 930 | HMM_HMMObservationSequenceBag_learn_notHiddencxx . . $ HMM_HMMObservationSequenceBag_learn_notHidden(c9e5502ed41cf7db). (me, thee, minProb); |
| 931 | return; |
| 932 | } |
| 933 | // act as if all observation sequences are in memory |
| 934 | const integercxx . . $ integer# capacity = HMMObservationSequenceBag_getLongestSequencecxx . . $ HMMObservationSequenceBag_getLongestSequence(79cdb932a9531ff3). (thee); |
| 935 | autoHMMBaumWelchcxx . . $ autoHMMBaumWelch# bw = HMMBaumWelch_createcxx . . $ HMMBaumWelch_create(a9645a0ad7322db7). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates, mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols, capacity); |
| 936 | bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). minProbcxx . . $ structHMMBaumWelch#minProb. = minProb; |
| 937 | if (info) |
| 938 | MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). (); |
| 939 | integercxx . . $ integer# iter = 0; |
| 940 | double lnp; |
| 941 | do { |
| 942 | lnp = bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lnProbcxx . . $ structHMMBaumWelch#lnProb.; |
| 943 | HMMBaumWelch_reInitcxx . . $ HMMBaumWelch_reInit(5b8f7ffbd72becf8). (bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 944 | for (integercxx . . $ integer# iseq = 1; iseq <= thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size.; iseq ++) { |
| 945 | const HMMObservationSequencecxx . . $ HMMObservationSequence# hmm_os = thycxx . . $ `melder/melder.h:45:9`! atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iseq]; |
| 946 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (me, hmm_os); // TODO outside the loop or more efficiently |
| 947 | INTVECcxx . . $ INTVEC# obs = si ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex..getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 948 | const integercxx . . $ integer# nobs = si ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfItemscxx . . $ structIndex#numberOfItems.; // convenience |
| 949 | |
| 950 | // Interpretation of unknowns: end of sequence |
| 951 | |
| 952 | integercxx . . $ integer# istart = 1, iend = nobs; |
| 953 | while (istart <= nobs) { |
| 954 | while (istart <= nobs && obs [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).istart] == 0) |
| 955 | istart ++; |
| 956 | if (istart > nobs) break; |
| 957 | |
| 958 | iend = istart + 1; |
| 959 | while (iend <= nobs && obs [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).iend] != 0) |
| 960 | iend ++; |
| 961 | iend --; |
| 962 | bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. = iend - istart + 1; |
| 963 | bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). totalNumberOfSequencescxx . . $ structHMMBaumWelch#totalNumberOfSequences. ++; |
| 964 | HMM_HMMBaumWelch_forwardcxx . . $ HMM_HMMBaumWelch_forward(997908ed33d9aa40). (me, bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obscxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..partcxx . . $ vector#part(ae267db9e2c04be7). (istart, nobs)); // get new alphas |
| 965 | HMM_HMMBaumWelch_backwardcxx . . $ HMM_HMMBaumWelch_backward(997908ed33d9aa40). (me, bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obscxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..partcxx . . $ vector#part(ae267db9e2c04be7). (istart, nobs)); // get new betas |
| 966 | HMMBaumWelch_getGammacxx . . $ HMMBaumWelch_getGamma(5b8f7ffbd72becf8). (bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 967 | HMM_HMMBaumWelch_getXicxx . . $ HMM_HMMBaumWelch_getXi(997908ed33d9aa40). (me, bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obscxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..partcxx . . $ vector#part(ae267db9e2c04be7). (istart, nobs)); |
| 968 | HMM_HMMBaumWelch_addEstimatecxx . . $ HMM_HMMBaumWelch_addEstimate(997908ed33d9aa40). (me, bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), obscxx . . $ constvector#constvector(eac9d6ec4c4bfecd)..partcxx . . $ vector#part(ae267db9e2c04be7). (istart, nobs)); |
| 969 | istart = iend + 1; |
| 970 | } |
| 971 | } |
| 972 | // we have processed all observation sequences, now it is time to estimate new probabilities. |
| 973 | iter ++; |
| 974 | HMM_HMMBaumWelch_reestimatecxx . . $ HMM_HMMBaumWelch_reestimate(5e4dd3b7e148addf). (me, bw.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 975 | if (info) |
| 976 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Iteration: ", iter, U" ln(prob): ", bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lnProbcxx . . $ structHMMBaumWelch#lnProb.); |
| 977 | } while (fabscxx . . $ fabs(fee4f1d22bc8e617). (lnp - bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lnProbcxx . . $ structHMMBaumWelch#lnProb.) > stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (fabscxx . . $ fabs(fee4f1d22bc8e617). (delta_lnp * bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lnProbcxx . . $ structHMMBaumWelch#lnProb.), NUMepscxx . . $ `dwsys/NUM2.h:36:9`!)); |
| 978 | if (info) { |
| 979 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"******** Learning summary *********"); |
| 980 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Processed ", thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size., U" sequence", ( thycxx . . $ `melder/melder.h:45:9`! sizecxx . . $ CollectionOf#size. > 1 ? U"s," : U"," )); |
| 981 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" consisting of ", bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). totalNumberOfSequencescxx . . $ structHMMBaumWelch#totalNumberOfSequences., U" observation sequence", |
| 982 | ( bw ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). totalNumberOfSequencescxx . . $ structHMMBaumWelch#totalNumberOfSequences. > 1 ? U"s." : U"." )); |
| 983 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" Longest observation sequence had ", capacity, U" items."); |
| 984 | MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8).(); |
| 985 | } |
| 986 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 987 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": not learned."); |
| 988 | } |
| 989 | } |
| 990 | |
| 991 | |
| 992 | // xc1 < xc2 |
| 993 | void HMM_HMMStateSequence_drawTrelliscxx . . $ HMM_HMMStateSequence_drawTrellis(91c6c1c881ad593). (HMM me, HMMStateSequencecxx . . $ HMMStateSequence# thee, Graphicscxx . . $ Graphics# g, bool connect, bool garnish) { |
| 994 | const integercxx . . $ integer# numberOfTimes = thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; |
| 995 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMStateSequence_to_StringsIndexcxx . . $ HMM_HMMStateSequence_to_StringsIndex(c40a092f418921de). (me, thee); |
| 996 | const double xmin = 0.0, xmax = numberOfTimes + 1.0, ymin = 0.5, ymax = mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 0.5; |
| 997 | |
| 998 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 999 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 1000 | |
| 1001 | const double r = 0.2 / ( numberOfTimes > mycxx . . $ `melder/melder.h:44:9`! numberOfStates ? numberOfTimes : mycxx . . $ `melder/melder.h:44:9`! numberOfStates ); |
| 1002 | |
| 1003 | for (integercxx . . $ integer# it = 1; it <= numberOfTimes; it ++) { |
| 1004 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1005 | const double xc = it, yc = js, x2 = it, y2 = js; |
| 1006 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, xc, yc, r); |
| 1007 | if (it > 1) { |
| 1008 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1009 | const bool indexedConnection = si ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it - 1] == is && si ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] == js; |
| 1010 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, ( indexedConnection ? 2.0 : 1.0 )); |
| 1011 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, ( indexedConnection ? Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`! : Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`! )); |
| 1012 | const double x1 = it - 1, y1 = is; |
| 1013 | if (connect || indexedConnection) { |
| 1014 | const double a = (y1 - y2) / (x1 - x2), b = y1 - a * x1; |
| 1015 | // double xs11 = x1 - r / (a * a + 1), ys11 = a * xs11 + b; |
| 1016 | const double xs12 = x1 + r / (a * a + 1), ys12 = a * xs12 + b; |
| 1017 | const double xs21 = x2 - r / (a * a + 1), ys21 = a * xs21 + b; |
| 1018 | // double xs22 = x2 + r / (a * a + 1), ys22 = a * xs22 + b; |
| 1019 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, xs12, ys12, xs21, ys21); |
| 1020 | } |
| 1021 | } |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 1026 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 1.0); |
| 1027 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!); |
| 1028 | if (garnish) { |
| 1029 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 1030 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1031 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).js]; |
| 1032 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, js, false, false, false, hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1033 | } |
| 1034 | Graphics_marksBottomEverycxx . . $ Graphics_marksBottomEvery(d1b58b4f93ec67ea). (g, 1.0, 1.0, true, true, false); |
| 1035 | Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"Time index"); |
| 1036 | } |
| 1037 | } |
| 1038 | |
| 1039 | void HMM_drawBackwardProbabilitiesIllustrationcxx . . $ HMM_drawBackwardProbabilitiesIllustration(b5ae742079ad918c). (Graphicscxx . . $ Graphics# g, bool garnish) { |
| 1040 | const double xmin = 0.0, xmax = 1.0, ymin = 0.0, ymax = 1.0; |
| 1041 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 1042 | const double xleft = 0.1, xright = 0.9, r = 0.03; |
| 1043 | const integercxx . . $ integer# np = 6; |
| 1044 | const double dy = (1.0 - 0.3) / (np - 1); |
| 1045 | const double x0 = xleft, y0 = 0.5; |
| 1046 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 1047 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, x0, y0, r); |
| 1048 | const double x = xright; |
| 1049 | double y = 0.9; |
| 1050 | for (integercxx . . $ integer# i = 1; i <= np; i ++) { |
| 1051 | if (i < 4 or i == np) { |
| 1052 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, x, y, r); |
| 1053 | const double xx = x0 - x, yy = y - y0; |
| 1054 | const double c = hypotcxx . . $ hypot(b71928d39fde4295). (xx, yy); |
| 1055 | const double cosa = xx / c, sina = yy / c; |
| 1056 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x0 - r * cosa, y0 + r * sina, x + r * cosa, y - r * sina); |
| 1057 | } else if (i == 4) { |
| 1058 | const double ddy = 3.0 * dy / 4.0; |
| 1059 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - ddy, 0.5 * r); |
| 1060 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - 2.0 * ddy, 0.5 * r); |
| 1061 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - 3.0 * ddy, 0.5 * r); |
| 1062 | } |
| 1063 | y -= dy; |
| 1064 | } |
| 1065 | if (garnish) { |
| 1066 | const double x1 = xright + 1.5 * r, x2 = x1 - 0.2; |
| 1067 | double y1 = 0.9; |
| 1068 | |
| 1069 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1070 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y1, U"%s__1_"); |
| 1071 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1072 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y1, U"%a__%i1_"); |
| 1073 | |
| 1074 | y1 = 0.9 - dy; |
| 1075 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1076 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y1, U"%s__2_"); |
| 1077 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1078 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y1, U"%a__%i2_"); |
| 1079 | |
| 1080 | y1 = 0.9 - (np - 1) * dy; |
| 1081 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1082 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y1, U"%s__%N_"); |
| 1083 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1084 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y1, U"%a__%%iN%_"); |
| 1085 | |
| 1086 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1087 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0 - 1.5 * r, y0, U"%s__%i_"); |
| 1088 | |
| 1089 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1090 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0, 0.0, U"%t"); |
| 1091 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, 0.0, U"%t+1"); |
| 1092 | |
| 1093 | const double y3 = 0.10; |
| 1094 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1095 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0, y3, U"%\\be__%t_(%i)%"); |
| 1096 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, y3, U"%\\be__%t+1_(%j)"); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | void HMM_drawForwardProbabilitiesIllustrationcxx . . $ HMM_drawForwardProbabilitiesIllustration(b5ae742079ad918c). (Graphicscxx . . $ Graphics# g, bool garnish) { |
| 1101 | constexpr double xmin = 0.0, xmax = 1.0, ymin = 0.0, ymax = 1.0; |
| 1102 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 1103 | const double xleft = 0.1, xright = 0.9, r = 0.03; |
| 1104 | constexpr integercxx . . $ integer# np = 6; |
| 1105 | const double dy = (1.0 - 0.3) / (np - 1); |
| 1106 | const double x0 = xright, y0 = 0.5; |
| 1107 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 1108 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, x0, y0, r); |
| 1109 | const double x = xleft; |
| 1110 | double y = 0.9; |
| 1111 | for (integercxx . . $ integer# i = 1; i <= np; i ++) { |
| 1112 | if (i < 4 or i == np) { |
| 1113 | Graphics_circlecxx . . $ Graphics_circle(8752bb7a78272ca7). (g, x, y, r); |
| 1114 | const double xx = x0 - x, yy = y - y0; |
| 1115 | const double c = hypotcxx . . $ hypot(b71928d39fde4295). (xx, yy); |
| 1116 | const double cosa = xx / c, sina = yy / c; |
| 1117 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x0 - r * cosa, y0 + r * sina, x + r * cosa, y - r * sina); |
| 1118 | } else if (i == 4) { |
| 1119 | const double ddy = 3.0 * dy / 4.0; |
| 1120 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - ddy, 0.5 * r); |
| 1121 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - 2.0 * ddy, 0.5 * r); |
| 1122 | Graphics_fillCirclecxx . . $ Graphics_fillCircle(8752bb7a78272ca7). (g, x, y + dy - 3.0 * ddy, 0.5 * r); |
| 1123 | } |
| 1124 | y -= dy; |
| 1125 | } |
| 1126 | if (garnish) { |
| 1127 | const double x1 = xleft - 1.5 * r, x2 = x1 + 0.2, y1 = 0.9; |
| 1128 | |
| 1129 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1130 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y1, U"%s__1_"); |
| 1131 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1132 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y1, U"%a__1%j_"); |
| 1133 | |
| 1134 | const double y2 = 0.9 - dy; |
| 1135 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1136 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y2, U"%s__2_"); |
| 1137 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1138 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y2, U"%a__2%j_"); |
| 1139 | |
| 1140 | const double y3 = 0.9 - (np - 1) * dy; |
| 1141 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1142 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x1, y3, U"%s__%N_"); |
| 1143 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1144 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x2, y3, U"%a__%%Nj%_"); |
| 1145 | |
| 1146 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1147 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0 + 1.5 * r, y0, U"%s__%j_"); |
| 1148 | |
| 1149 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1150 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, 0.0, U"%t"); |
| 1151 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0, 0.0, U"%t+1"); |
| 1152 | |
| 1153 | const double y4 = 0.10; |
| 1154 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1155 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, y4, U"%\\al__%t_(%i)%"); |
| 1156 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x0, y4, U"%\\al__%t+1_(%j)"); |
| 1157 | } |
| 1158 | } |
| 1159 | |
| 1160 | void HMM_drawForwardAndBackwardProbabilitiesIllustrationcxx . . $ HMM_drawForwardAndBackwardProbabilitiesIllustration(b5ae742079ad918c). (Graphicscxx . . $ Graphics# g, bool garnish) { |
| 1161 | const double xfrac = 0.1, xs = 1.0 / (0.5 - xfrac), r = 0.03; |
| 1162 | Graphics_Viewportcxx . . $ Graphics_Viewport# vp = Graphics_insetViewportcxx . . $ Graphics_insetViewport(b48873d7bfae0d92). (g, 0.0, 0.5-xfrac, 0.0, 1.0); |
| 1163 | HMM_drawForwardProbabilitiesIllustrationcxx . . $ HMM_drawForwardProbabilitiesIllustration(b5ae742079ad918c). (g, false); |
| 1164 | Graphics_resetViewportcxx . . $ Graphics_resetViewport(620f27fff4cd4a03). (g, vp); |
| 1165 | Graphics_insetViewportcxx . . $ Graphics_insetViewport(b48873d7bfae0d92). (g, 0.5 + xfrac, 1.0, 0.0, 1.0); |
| 1166 | HMM_drawBackwardProbabilitiesIllustrationcxx . . $ HMM_drawBackwardProbabilitiesIllustration(b5ae742079ad918c). (g, false); |
| 1167 | Graphics_resetViewportcxx . . $ Graphics_resetViewport(620f27fff4cd4a03). (g, vp); |
| 1168 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, 0.0, xs, 0.0, 1.0); |
| 1169 | if (garnish) { |
| 1170 | const double rx1 = 1.0 + xs * 2.0 * xfrac + 0.1, rx2 = rx1 + 0.9 - 0.1, y1 = 0.1; |
| 1171 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, 0.9 + r, 0.5, rx1 - r, 0.5); |
| 1172 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1173 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 0.9, 0.5 + r, U"%s__%i_"); |
| 1174 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, rx1, 0.5 + r, U"%s__%j_"); |
| 1175 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!); |
| 1176 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 1.0 + xfrac * xs, 0.5, U"%a__%%ij%_%b__%j_(O__%t+1_)"); |
| 1177 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, kGraphics_horizontalAlignmentcxx . . $ kGraphics_horizontalAlignment#::CENTREcxx . . $ kGraphics_horizontalAlignment#CENTRE., Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1178 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 0.1, 0.0, U"%t-1"); |
| 1179 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 0.9, 0.0, U"%t"); |
| 1180 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, rx1, 0.0, U"%t+1"); |
| 1181 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, rx2, 0.0, U"%t+2"); |
| 1182 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DASHEDcxx . . $ `sys/Graphics.h:289:9`!); |
| 1183 | const double x4 = rx1 - 0.06, x3 = 0.9 + 0.06; |
| 1184 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x3, 0.7, x3, 0.0); |
| 1185 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x4, 0.7, x4, 0.0); |
| 1186 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!); |
| 1187 | Graphics_arrowcxx . . $ Graphics_arrow(72bdb7937dbb13da). (g, x4, y1, x4 + 0.2, y1); |
| 1188 | Graphics_arrowcxx . . $ Graphics_arrow(72bdb7937dbb13da). (g, x3, y1, x3 - 0.2, y1); |
| 1189 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1190 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x3 - 0.01, y1, U"\\al__%t_(i)"); |
| 1191 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1192 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x4 + 0.01, y1, U"\\be__%t+1_(j)"); |
| 1193 | } |
| 1194 | } |
| 1195 | |
| 1196 | void HMM_HMMBaumWelch_getXicxx . . $ HMM_HMMBaumWelch_getXi(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs) { |
| 1197 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (obs.size == thycxx . . $ `melder/melder.h:45:9`! numberOfTimes); |
| 1198 | for (integercxx . . $ integer# it = 1; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. - 1; it ++) { |
| 1199 | longdoublecxx . . $ longdouble# sum = 0.0; |
| 1200 | MATVUcxx . . $ MATVU# xi_it = thycxx . . $ `melder/melder.h:45:9`! xicxx . . $ structHMMBaumWelch#xi. [cxx . . $ tensor3#`operator[]`(7cecab99a14fb313).it]; |
| 1201 | for (integercxx . . $ integer# is = 1; is <= thycxx . . $ `melder/melder.h:45:9`! numberOfStatescxx . . $ structHMMBaumWelch#numberOfStates.; is ++) { |
| 1202 | for (integercxx . . $ integer# js = 1; js <= thycxx . . $ `melder/melder.h:45:9`! numberOfStatescxx . . $ structHMMBaumWelch#numberOfStates.; js ++) { |
| 1203 | xi_it [cxx . . $ matrixview#`operator[]`(a8b9553e85c2b1fc).is] [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).js] = thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] * thycxx . . $ `melder/melder.h:45:9`! betacxx . . $ structHMMBaumWelch#beta. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it + 1] * |
| 1204 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1). obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it + 1] ]; |
| 1205 | sum += xi_it [cxx . . $ matrixview#`operator[]`(a8b9553e85c2b1fc).is] [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).js]; |
| 1206 | } |
| 1207 | } |
| 1208 | xi_it /=cxx . . $ `operator/=`(50b469ae42a42f64). double (sum); |
| 1209 | } |
| 1210 | } |
| 1211 | |
| 1212 | void HMM_HMMBaumWelch_addEstimatecxx . . $ HMM_HMMBaumWelch_addEstimate(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs) { |
| 1213 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (obs.size == thycxx . . $ `melder/melder.h:45:9`! numberOfTimes); |
| 1214 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1215 | // only for valid start states with p > 0 |
| 1216 | if (mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] > 0.0) { |
| 1217 | thycxx . . $ `melder/melder.h:45:9`! aij_num_p0cxx . . $ structHMMBaumWelch#aij_num_p0. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] += thycxx . . $ `melder/melder.h:45:9`! gammacxx . . $ structHMMBaumWelch#gamma. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]; |
| 1218 | thycxx . . $ `melder/melder.h:45:9`! aij_denom_p0cxx . . $ structHMMBaumWelch#aij_denom_p0. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] += 1.0; |
| 1219 | } |
| 1220 | } |
| 1221 | |
| 1222 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1223 | double gammasum = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (thycxx . . $ `melder/melder.h:45:9`! gammacxx . . $ structHMMBaumWelch#gamma..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (is).partcxx . . $ vector#part(ae267db9e2c04be7). (1, thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. - 1)); |
| 1224 | |
| 1225 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1226 | longdoublecxx . . $ longdouble# xisum = 0.0; |
| 1227 | for (integercxx . . $ integer# it = 1; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. - 1; it ++) |
| 1228 | xisum += thycxx . . $ `melder/melder.h:45:9`! xicxx . . $ structHMMBaumWelch#xi. [cxx . . $ tensor3#`operator[]`(7cecab99a14fb313).it] [cxx . . $ matrixview#`operator[]`(a8b9553e85c2b1fc).is] [cxx . . $ vectorview#`operator[]`(8a4599b8835d1ce1).js]; |
| 1229 | // zero probs signal invalid connections, don't reestimate |
| 1230 | if (mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] > 0.0) { |
| 1231 | thycxx . . $ `melder/melder.h:45:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] += double (xisum); |
| 1232 | thycxx . . $ `melder/melder.h:45:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] += gammasum; |
| 1233 | } |
| 1234 | } |
| 1235 | |
| 1236 | /* |
| 1237 | Only reestimate the emissionProbs for a hidden markov model. |
| 1238 | A not hidden model is emulated with fixed emissionProbs. |
| 1239 | */ |
| 1240 | if (! mycxx . . $ `melder/melder.h:44:9`! notHidden) { |
| 1241 | gammasum += thycxx . . $ `melder/melder.h:45:9`! gammacxx . . $ structHMMBaumWelch#gamma. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.]; // now sum all, add last term |
| 1242 | for (integercxx . . $ integer# k = 1; k <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; k ++) { |
| 1243 | longdoublecxx . . $ longdouble# gammasum_k = 0.0; |
| 1244 | for (integercxx . . $ integer# it = 1; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.; it ++) |
| 1245 | if (obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it] == k) |
| 1246 | gammasum_k += thycxx . . $ `melder/melder.h:45:9`! gammacxx . . $ structHMMBaumWelch#gamma. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1247 | // only reestimate probs > 0 ! |
| 1248 | if (mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] > 0.0) { |
| 1249 | thycxx . . $ `melder/melder.h:45:9`! bik_numcxx . . $ structHMMBaumWelch#bik_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] += double (gammasum_k); |
| 1250 | thycxx . . $ `melder/melder.h:45:9`! bik_denomcxx . . $ structHMMBaumWelch#bik_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] += gammasum; |
| 1251 | } |
| 1252 | } |
| 1253 | } |
| 1254 | // For a left-to-right model the final state determines the transition prob to go to the END state |
| 1255 | if (mycxx . . $ `melder/melder.h:44:9`! leftToRight) { |
| 1256 | thycxx . . $ `melder/melder.h:45:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] += thycxx . . $ `melder/melder.h:45:9`! gammacxx . . $ structHMMBaumWelch#gamma. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.]; |
| 1257 | thycxx . . $ `melder/melder.h:45:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] += 1.0; |
| 1258 | } |
| 1259 | } |
| 1260 | } |
| 1261 | |
| 1262 | void HMM_HMMBaumWelch_reestimatecxx . . $ HMM_HMMBaumWelch_reestimate(5e4dd3b7e148addf). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee) { |
| 1263 | double p; |
| 1264 | /* |
| 1265 | If we only have a couple of training sequences and they all happen to start with the same symbol, |
| 1266 | one or more starting probabilities can be zero. |
| 1267 | |
| 1268 | What to do with the P_k (see Rabiner formulas 109-110)? |
| 1269 | */ |
| 1270 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1271 | /* |
| 1272 | If we have not enough observation sequences it can happen that some probabilities |
| 1273 | become zero. This means that for some future observation sequences the probability evaluation |
| 1274 | returns p=0 for sequences where these transitions turn up. This makes recognition impossible and |
| 1275 | also comparisons between models are difficult. |
| 1276 | We can prevent this from happening by asumimg a minimal probability for valid transitions |
| 1277 | i.e. which have initially p > 0. |
| 1278 | */ |
| 1279 | if (mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] > 0.0) { |
| 1280 | p = thycxx . . $ `melder/melder.h:45:9`! aij_num_p0cxx . . $ structHMMBaumWelch#aij_num_p0. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] / thycxx . . $ `melder/melder.h:45:9`! aij_denom_p0cxx . . $ structHMMBaumWelch#aij_denom_p0. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is]; |
| 1281 | mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] = ( p > 0.0 ? p : thycxx . . $ `melder/melder.h:45:9`! minProbcxx . . $ structHMMBaumWelch#minProb. ); |
| 1282 | } |
| 1283 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1284 | if (mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] > 0.0) { |
| 1285 | p = thycxx . . $ `melder/melder.h:45:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] / thycxx . . $ `melder/melder.h:45:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1286 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] = ( p > 0.0 ? p : thycxx . . $ `melder/melder.h:45:9`! minProbcxx . . $ structHMMBaumWelch#minProb. ); |
| 1287 | } |
| 1288 | } |
| 1289 | if (! mycxx . . $ `melder/melder.h:44:9`! notHidden) { |
| 1290 | for (integercxx . . $ integer# k = 1; k <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; k ++) { |
| 1291 | if (mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] > 0.0) { |
| 1292 | p = thycxx . . $ `melder/melder.h:45:9`! bik_numcxx . . $ structHMMBaumWelch#bik_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] / thycxx . . $ `melder/melder.h:45:9`! bik_denomcxx . . $ structHMMBaumWelch#bik_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k]; |
| 1293 | mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).k] = ( p > 0.0 ? p : thycxx . . $ `melder/melder.h:45:9`! minProbcxx . . $ structHMMBaumWelch#minProb. ); |
| 1294 | } |
| 1295 | } |
| 1296 | } |
| 1297 | if (mycxx . . $ `melder/melder.h:44:9`! leftToRight && mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] > 0.0) { |
| 1298 | p = thycxx . . $ `melder/melder.h:45:9`! aij_numcxx . . $ structHMMBaumWelch#aij_num. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] / thycxx . . $ `melder/melder.h:45:9`! aij_denomcxx . . $ structHMMBaumWelch#aij_denom. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1]; |
| 1299 | mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfStates + 1] = ( p > 0.0 ? p : thycxx . . $ `melder/melder.h:45:9`! minProbcxx . . $ structHMMBaumWelch#minProb. ); |
| 1300 | } |
| 1301 | } |
| 1302 | } |
| 1303 | |
| 1304 | void HMM_HMMBaumWelch_forwardcxx . . $ HMM_HMMBaumWelch_forward(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs) { |
| 1305 | // initialise at t = 1 & scale |
| 1306 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) |
| 1307 | thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1]]; |
| 1308 | thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (1)); |
| 1309 | thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (1) /=cxx . . $ `operator/=`(c555d170d72ff256). thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 1310 | // recursion |
| 1311 | for (integercxx . . $ integer# it = 2; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.; it ++) { |
| 1312 | thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] = 0.0; |
| 1313 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1314 | double sum = 0.0; |
| 1315 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1316 | sum += thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it - 1] * mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1317 | } |
| 1318 | |
| 1319 | thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] = sum * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it]]; |
| 1320 | thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] += thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1321 | } |
| 1322 | |
| 1323 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1324 | thycxx . . $ `melder/melder.h:45:9`! alphacxx . . $ structHMMBaumWelch#alpha. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] /= thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1325 | } |
| 1326 | } |
| 1327 | |
| 1328 | for (integercxx . . $ integer# it = 1; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.; it ++) { |
| 1329 | thycxx . . $ `melder/melder.h:45:9`! lnProbcxx . . $ structHMMBaumWelch#lnProb. += logcxx . . $ log(fee4f1d22bc8e617). (thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]); |
| 1330 | } |
| 1331 | } |
| 1332 | |
| 1333 | void HMM_HMMBaumWelch_backwardcxx . . $ HMM_HMMBaumWelch_backward(997908ed33d9aa40). (HMM me, HMMBaumWelchcxx . . $ HMMBaumWelch# thee, constINTVECcxx . . $ constINTVEC# obs) { |
| 1334 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (obs.size == thycxx . . $ `melder/melder.h:45:9`! numberOfTimes); |
| 1335 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1336 | thycxx . . $ `melder/melder.h:45:9`! betacxx . . $ structHMMBaumWelch#beta. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.] = 1.0 / thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes.]; |
| 1337 | } |
| 1338 | for (integercxx . . $ integer# it = thycxx . . $ `melder/melder.h:45:9`! numberOfTimescxx . . $ structHMMBaumWelch#numberOfTimes. - 1; it >= 1; it --) { |
| 1339 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1340 | longdoublecxx . . $ longdouble# sum = 0.0; |
| 1341 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1342 | sum += thycxx . . $ `melder/melder.h:45:9`! betacxx . . $ structHMMBaumWelch#beta. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it + 1] * mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js] * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it + 1]]; |
| 1343 | } |
| 1344 | thycxx . . $ `melder/melder.h:45:9`! betacxx . . $ structHMMBaumWelch#beta. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] = double (sum) / thycxx . . $ `melder/melder.h:45:9`! scalecxx . . $ structHMMBaumWelch#scale. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | /*************************** HMM decoding ***********************************/ |
| 1350 | |
| 1351 | // precondition: valid symbols, i.e. 1 <= o [i] <= my numberOfSymbols for i=1..nt |
| 1352 | void HMM_HMMViterbi_decodecxx . . $ HMM_HMMViterbi_decode(f8c11026b00d51af). (HMM me, HMMViterbi thee, constINTVECcxx . . $ constINTVEC# obs) { |
| 1353 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (obs.size == thycxx . . $ `melder/melder.h:45:9`! numberOfTimes); |
| 1354 | const integercxx . . $ integer# numberOfTimes = thycxx . . $ `melder/melder.h:45:9`! numberOfTimes; |
| 1355 | // initialisation |
| 1356 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1357 | thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1]]; |
| 1358 | thycxx . . $ `melder/melder.h:45:9`! bp [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 0; |
| 1359 | } |
| 1360 | // recursion |
| 1361 | for (integercxx . . $ integer# it = 2; it <= numberOfTimes; it ++) { |
| 1362 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1363 | // all transitions isp -> is from previous time to current |
| 1364 | double max_score = -1; // any negative number is ok |
| 1365 | for (integercxx . . $ integer# isp = 1; isp <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; isp ++) { |
| 1366 | const double score = thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).isp] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it - 1] * mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).isp] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).is]; // * my emissionProbs [is] [obs [it]] |
| 1367 | if (score > max_score) { |
| 1368 | max_score = score; |
| 1369 | thycxx . . $ `melder/melder.h:45:9`! bp [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] = isp; |
| 1370 | } |
| 1371 | } |
| 1372 | thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it] = max_score * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1). obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it] ]; |
| 1373 | } |
| 1374 | } |
| 1375 | // path starts at state with best end probability |
| 1376 | thycxx . . $ `melder/melder.h:45:9`! path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfTimes] = 1; |
| 1377 | thycxx . . $ `melder/melder.h:45:9`! prob = thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTimes]; |
| 1378 | for (integercxx . . $ integer# is = 2; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1379 | if (thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTimes] > thycxx . . $ `melder/melder.h:45:9`! prob) |
| 1380 | thycxx . . $ `melder/melder.h:45:9`! prob = thycxx . . $ `melder/melder.h:45:9`! viterbi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).thycxx . . $ `melder/melder.h:45:9`! path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).numberOfTimes] = is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTimes]; |
| 1381 | } |
| 1382 | // trace back and get path |
| 1383 | for (integercxx . . $ integer# it = numberOfTimes; it > 1; it --) |
| 1384 | thycxx . . $ `melder/melder.h:45:9`! path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it - 1] = thycxx . . $ `melder/melder.h:45:9`! bp [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).thycxx . . $ `melder/melder.h:45:9`! path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1385 | } |
| 1386 | |
| 1387 | autoHMMStateSequencecxx . . $ autoHMMStateSequence# HMM_HMMObservationSequence_to_HMMStateSequencecxx . . $ HMM_HMMObservationSequence_to_HMMStateSequence(e3b0918df6c6ca53). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee) { |
| 1388 | try { |
| 1389 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (me, thee); |
| 1390 | INTVECcxx . . $ INTVEC# obs = si ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex..getcxx . . $ autovector#get(e8d1da7fe68a6585).(); // convenience |
| 1391 | const integercxx . . $ integer# numberOfUnknowns = StringsIndex_countItemscxx . . $ StringsIndex_countItems(e8cc7e7a1090a673). (si.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0); |
| 1392 | |
| 1393 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfUnknowns == 0, U"Unknown observation symbol(s) (# = ", numberOfUnknowns, U")."); |
| 1394 | |
| 1395 | const integercxx . . $ integer# numberOfTimes = thycxx . . $ `melder/melder.h:45:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.; |
| 1396 | autoHMMViterbi v = HMM_to_HMMViterbicxx . . $ HMM_to_HMMViterbi(63cc62d0703e50cd). (me, obscxx . . $ constvector#constvector(eac9d6ec4c4bfecd).); |
| 1397 | autoHMMStateSequencecxx . . $ autoHMMStateSequence# him = HMMStateSequence_createcxx . . $ HMMStateSequence_create(9c2f169a35e53358). (numberOfTimes); |
| 1398 | // trace the path and get states |
| 1399 | for (integercxx . . $ integer# it = 1; it <= numberOfTimes; it ++) { |
| 1400 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).v ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). path [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]]; |
| 1401 | hiscxx . . $ `melder/melder.h:47:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).it] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1402 | hiscxx . . $ `melder/melder.h:47:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. ++; |
| 1403 | } |
| 1404 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1405 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1406 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no HMMStateSequence created."); |
| 1407 | } |
| 1408 | } |
| 1409 | |
| 1410 | double HMM_HMMStateSequence_getProbabilitycxx . . $ HMM_HMMStateSequence_getProbability(76df72986c2263a7). (HMM me, HMMStateSequencecxx . . $ HMMStateSequence# thee) { |
| 1411 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMStateSequence_to_StringsIndexcxx . . $ HMM_HMMStateSequence_to_StringsIndex(c40a092f418921de). (me, thee); |
| 1412 | const integercxx . . $ integer# numberOfUnknowns = StringsIndex_countItemscxx . . $ StringsIndex_countItems(e8cc7e7a1090a673). (si.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0); |
| 1413 | constINTVECcxx . . $ constINTVEC# index = sicxx . . $ constvector#constvector(eac9d6ec4c4bfecd). ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex..getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 1414 | |
| 1415 | if (NUMisEmptycxx . . $ NUMisEmpty(d2f4442a12a6e0e9). (index)) |
| 1416 | return undefinedcxx . . $ undefined.; |
| 1417 | if (numberOfUnknowns > 0) { |
| 1418 | Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Unknown states (# = ", numberOfUnknowns, U")."); |
| 1419 | return undefinedcxx . . $ undefined.; |
| 1420 | } |
| 1421 | const double p0 = mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1]]; |
| 1422 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (p0 > 0.0, |
| 1423 | U"You should not start with a zero probability state."); |
| 1424 | |
| 1425 | double lnp = logcxx . . $ log(fee4f1d22bc8e617). (p0); |
| 1426 | for (integercxx . . $ integer# it = 2; it <= thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; it ++) |
| 1427 | lnp += logcxx . . $ log(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).index [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it - 1]] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).index [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it]]); |
| 1428 | return lnp; |
| 1429 | } |
| 1430 | |
| 1431 | double HMM_getProbabilityAtTimeBeingInStatecxx . . $ HMM_getProbabilityAtTimeBeingInState(a5dc8f3f179118c1). (HMM me, integercxx . . $ integer# itime, integercxx . . $ integer# istate) { |
| 1432 | if (istate < 1 || istate > mycxx . . $ `melder/melder.h:44:9`! numberOfStates) |
| 1433 | return undefinedcxx . . $ undefined.; |
| 1434 | |
| 1435 | autoVECcxx . . $ autoVEC# scale = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (itime); |
| 1436 | autoVECcxx . . $ autoVEC# alpha_t = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 1437 | autoVECcxx . . $ autoVEC# alpha_tm1 = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 1438 | |
| 1439 | alpha_t.allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(adea042513329390). mycxx . . $ `melder/melder.h:44:9`! initialStateProbs.allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 1440 | scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (alpha_tcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).()); |
| 1441 | |
| 1442 | alpha_t.allcxx . . $ autovector#all(a26726dad87555bb).() /=cxx . . $ `operator/=`(c555d170d72ff256). scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 1443 | |
| 1444 | // recursion |
| 1445 | for (integercxx . . $ integer# it = 2; it <= itime; it ++) { |
| 1446 | alpha_tm1.allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(adea042513329390). alpha_tcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 1447 | |
| 1448 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1449 | longdoublecxx . . $ longdouble# sum = 0.0; // NUMinner (alpha_tm1.get(), my transitionProbs.column (js)); |
| 1450 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) |
| 1451 | sum += alpha_tm1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] * mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1452 | alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] = double (sum); |
| 1453 | scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] += alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1454 | } |
| 1455 | alpha_t.allcxx . . $ autovector#all(a26726dad87555bb).() /=cxx . . $ `operator/=`(c555d170d72ff256). scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1456 | } |
| 1457 | |
| 1458 | longdoublecxx . . $ longdouble# lnp = 0.0; |
| 1459 | for (integercxx . . $ integer# it = 1; it <= itime; it ++) |
| 1460 | lnp += logcxx . . $ log(fee4f1d22bc8e617). (scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]); |
| 1461 | |
| 1462 | lnp = ( alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).istate] > 0 ? lnp + logcxx . . $ log(fee4f1d22bc8e617). (alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).istate]) : -INFINITYcxx . . $ `<external>/11263917310783833665/math.h:92:12`! ); // p = 0 -> ln(p)=-infinity // ppgb INFINITY is a small number |
| 1463 | return double (lnp); |
| 1464 | } |
| 1465 | |
| 1466 | double HMM_getProbabilityAtTimeBeingInStateEmittingSymbolcxx . . $ HMM_getProbabilityAtTimeBeingInStateEmittingSymbol(db68c79978c7f386). (HMM me, integercxx . . $ integer# itime, integercxx . . $ integer# istate, integercxx . . $ integer# isymbol) { |
| 1467 | // for a notHidden model emissionProbs may be zero! |
| 1468 | if (isymbol < 1 || isymbol > mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols || mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).istate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isymbol] == 0.0) |
| 1469 | return undefinedcxx . . $ undefined.; |
| 1470 | const double lnp = HMM_getProbabilityAtTimeBeingInStatecxx . . $ HMM_getProbabilityAtTimeBeingInState(a5dc8f3f179118c1). (me, itime, istate); |
| 1471 | return ( isundefcxx . . $ isundef(f8197d536af80c96). (lnp) ? undefinedcxx . . $ undefined. : lnp + logcxx . . $ log(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).istate] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).isymbol]) ); |
| 1472 | } |
| 1473 | |
| 1474 | double HMM_getProbabilityOfObservationscxx . . $ HMM_getProbabilityOfObservations(dc3ed4315d2b41a8). (HMM me, constINTVECcxx . . $ constINTVEC# obs) { |
| 1475 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (obs.size > 0); |
| 1476 | const integercxx . . $ integer# numberOfTimes = obs.sizecxx . . $ constvector#size.; |
| 1477 | autoVECcxx . . $ autoVEC# scale = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (numberOfTimes); |
| 1478 | autoVECcxx . . $ autoVEC# alpha_t = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 1479 | autoVECcxx . . $ autoVEC# alpha_tm1 = zero_VECcxx . . $ zero_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfStates); |
| 1480 | |
| 1481 | // initialise |
| 1482 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1483 | alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] = mycxx . . $ `melder/melder.h:44:9`! initialStateProbs [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).1]]; |
| 1484 | scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] += alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1485 | } |
| 1486 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (scale [1] > 0.0, |
| 1487 | U"The observation sequence should not start with a symbol whose state has zero starting probability."); |
| 1488 | |
| 1489 | alpha_t.allcxx . . $ autovector#all(a26726dad87555bb).() /=cxx . . $ `operator/=`(c555d170d72ff256). scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]; |
| 1490 | |
| 1491 | // recursion |
| 1492 | for (integercxx . . $ integer# it = 2; it <= numberOfTimes; it ++) { |
| 1493 | alpha_tm1.allcxx . . $ autovector#all(a26726dad87555bb).() <<=cxx . . $ `operator<<=`(adea042513329390). alpha_tcxx . . $ constvectorview#constvectorview(5c6f246bf1d99401)..allcxx . . $ autovector#all(a26726dad87555bb).(); |
| 1494 | |
| 1495 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) { |
| 1496 | longdoublecxx . . $ longdouble# sum = 0.0; |
| 1497 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1498 | sum += alpha_tm1 [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).is] * mycxx . . $ `melder/melder.h:44:9`! transitionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).is] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1499 | } |
| 1500 | alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] = sum * mycxx . . $ `melder/melder.h:44:9`! emissionProbs [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).js] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).obs [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).it]]; |
| 1501 | scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] += alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js]; |
| 1502 | } |
| 1503 | if (scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it] <= 0.0) |
| 1504 | return -INFINITYcxx . . $ `<external>/11263917310783833665/math.h:92:12`!; |
| 1505 | for (integercxx . . $ integer# js = 1; js <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; js ++) |
| 1506 | alpha_t [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).js] /= scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]; |
| 1507 | } |
| 1508 | |
| 1509 | double lnp = 0.0; |
| 1510 | for (integercxx . . $ integer# it = 1; it <= numberOfTimes; it ++) |
| 1511 | lnp += logcxx . . $ log(fee4f1d22bc8e617). (scale [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).it]); |
| 1512 | return lnp; |
| 1513 | } |
| 1514 | |
| 1515 | double HMM_HMMObservationSequence_getProbabilitycxx . . $ HMM_HMMObservationSequence_getProbability(3536ecb89be28e71). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee) { |
| 1516 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (me, thee); |
| 1517 | const integercxx . . $ integer# numberOfUnknowns = StringsIndex_countItemscxx . . $ StringsIndex_countItems(e8cc7e7a1090a673). (si.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0); |
| 1518 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (numberOfUnknowns == 0, U"Unknown observations (# = ", numberOfUnknowns, U")."); |
| 1519 | |
| 1520 | return HMM_getProbabilityOfObservationscxx . . $ HMM_getProbabilityOfObservations(dc3ed4315d2b41a8). (me, sicxx . . $ constvector#constvector(eac9d6ec4c4bfecd). ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). classIndexcxx . . $ structIndex#classIndex..getcxx . . $ autovector#get(e8d1da7fe68a6585).()); |
| 1521 | } |
| 1522 | |
| 1523 | double HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee) { |
| 1524 | const double lnp = HMM_HMMObservationSequence_getProbabilitycxx . . $ HMM_HMMObservationSequence_getProbability(3536ecb89be28e71). (me, thee); |
| 1525 | return ( isundefcxx . . $ isundef(f8197d536af80c96). (lnp) ? undefinedcxx . . $ undefined. : |
| 1526 | -lnp / (NUMln10cxx . . $ NUMln10. * HMMObservationSequence_getNumberOfObservationscxx . . $ HMMObservationSequence_getNumberOfObservations(60f64ad3800af0f2). (thee)) ); |
| 1527 | } |
| 1528 | |
| 1529 | double HMM_HMMObservationSequence_getPerplexitycxx . . $ HMM_HMMObservationSequence_getPerplexity(3536ecb89be28e71). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee) { |
| 1530 | const double ce = HMM_HMMObservationSequence_getCrossEntropycxx . . $ HMM_HMMObservationSequence_getCrossEntropy(3536ecb89be28e71). (me, thee); |
| 1531 | return ( isundefcxx . . $ isundef(f8197d536af80c96). (ce) ? undefinedcxx . . $ undefined. : powcxx . . $ pow(b71928d39fde4295). (2.0, ce) ); |
| 1532 | } |
| 1533 | |
| 1534 | autoHMM HMM_createFromHMMObservationSequencecxx . . $ HMM_createFromHMMObservationSequence(4680bdcef32192e6). (HMMObservationSequencecxx . . $ HMMObservationSequence# me, integercxx . . $ integer# numberOfStates, int leftToRight) { |
| 1535 | try { |
| 1536 | autoHMM thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (HMM); |
| 1537 | autoStringscxx . . $ autoStrings# s = HMMObservationSequence_to_Stringscxx . . $ HMMObservationSequence_to_Strings(96468204c8f86caf). (me); |
| 1538 | autoDistributionscxx . . $ autoDistributions# d = Strings_to_Distributionscxx . . $ Strings_to_Distributions(51ca0faf08ce563). (s.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1539 | |
| 1540 | const integercxx . . $ integer# numberOfObservationSymbols = d ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfRowscxx . . $ structTableOfReal#numberOfRows.; |
| 1541 | thycxx . . $ `melder/melder.h:45:9`! notHidden = numberOfStates < 1; |
| 1542 | numberOfStates = ( numberOfStates > 0 ? numberOfStates : numberOfObservationSymbols ); |
| 1543 | |
| 1544 | HMM_initcxx . . $ HMM_init(251b2de7ddb14373). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfStates, numberOfObservationSymbols, leftToRight); |
| 1545 | |
| 1546 | for (integercxx . . $ integer# i = 1; i <= numberOfObservationSymbols; i ++) { |
| 1547 | const conststring32cxx . . $ conststring32# label = d ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 1548 | autoHMMObservation hmmo = HMMObservation_createcxx . . $ HMMObservation_create(11a3bc4ca4ae3569). (label, 0, 0, kHMMstorage::DIAGONALS); |
| 1549 | HMM_addObservation_movecxx . . $ HMM_addObservation_move(146d2ca70b877b86). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), hmmocxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 1550 | if (thycxx . . $ `melder/melder.h:45:9`! notHidden) { |
| 1551 | autoHMMState hmms = HMMState_createcxx . . $ HMMState_create(6234ff79f5d4a52a). (label); |
| 1552 | HMM_addState_movecxx . . $ HMM_addState_move(a47c88543731af7f). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), hmmscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).()); |
| 1553 | } |
| 1554 | } |
| 1555 | if (! thycxx . . $ `melder/melder.h:45:9`! notHidden) |
| 1556 | HMM_setDefaultStatescxx . . $ HMM_setDefaultStates(6efb248da18d5537). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1557 | |
| 1558 | //HMM_setDefaultTransitionProbs (thee.get()); |
| 1559 | //HMM_setDefaultInitialStateProbs (thee.get()); |
| 1560 | //HMM_setDefaultEmissionProbs (thee.get()); |
| 1561 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1562 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1563 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no HMM created."); |
| 1564 | } |
| 1565 | } |
| 1566 | |
| 1567 | autoTableOfRealcxx . . $ autoTableOfReal# HMMObservationSequence_to_TableOfReal_transitionscxx . . $ HMMObservationSequence_to_TableOfReal_transitions(cc9aa951ca0d805d). (HMMObservationSequencecxx . . $ HMMObservationSequence# me, int probabilities) { |
| 1568 | try { |
| 1569 | autoStringscxx . . $ autoStrings# thee = HMMObservationSequence_to_Stringscxx . . $ HMMObservationSequence_to_Strings(96468204c8f86caf). (me); |
| 1570 | autoTableOfRealcxx . . $ autoTableOfReal# him = Strings_to_TableOfReal_transitionscxx . . $ Strings_to_TableOfReal_transitions(c553ca65e8404f05). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), probabilities); |
| 1571 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1572 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1573 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transitions created."); |
| 1574 | } |
| 1575 | } |
| 1576 | |
| 1577 | autoStringsIndexcxx . . $ autoStringsIndex# HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee) { |
| 1578 | try { |
| 1579 | autoStringscxx . . $ autoStrings# classes = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 1580 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols); |
| 1581 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols; is ++) { |
| 1582 | const HMMObservation hmmo = mycxx . . $ `melder/melder.h:44:9`! observationSymbols->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 1583 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).is] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (hmmo -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1584 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. ++; |
| 1585 | } |
| 1586 | autoStringscxx . . $ autoStrings# obs = HMMObservationSequence_to_Stringscxx . . $ HMMObservationSequence_to_Strings(96468204c8f86caf). (thee); |
| 1587 | autoStringsIndexcxx . . $ autoStringsIndex# him = Stringses_to_StringsIndexcxx . . $ Stringses_to_StringsIndex(4d8bb01cf73a31d6). (obs.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), classes.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1588 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1589 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1590 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no StringsIndex created."); |
| 1591 | } |
| 1592 | } |
| 1593 | |
| 1594 | autoStringsIndexcxx . . $ autoStringsIndex# HMM_HMMStateSequence_to_StringsIndexcxx . . $ HMM_HMMStateSequence_to_StringsIndex(c40a092f418921de). (HMM me, HMMStateSequencecxx . . $ HMMStateSequence# thee) { |
| 1595 | try { |
| 1596 | autoStringscxx . . $ autoStrings# classes = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 1597 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (mycxx . . $ `melder/melder.h:44:9`! numberOfObservationSymbols); |
| 1598 | for (integercxx . . $ integer# is = 1; is <= mycxx . . $ `melder/melder.h:44:9`! numberOfStates; is ++) { |
| 1599 | const HMMState hmms = mycxx . . $ `melder/melder.h:44:9`! states->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).is]; |
| 1600 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).is] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (hmms -> label.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1601 | classes ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. ++; |
| 1602 | } |
| 1603 | autoStringscxx . . $ autoStrings# sts = HMMStateSequence_to_Stringscxx . . $ HMMStateSequence_to_Strings(ba26850bc1662146). (thee); |
| 1604 | autoStringsIndexcxx . . $ autoStringsIndex# him = Stringses_to_StringsIndexcxx . . $ Stringses_to_StringsIndex(4d8bb01cf73a31d6). (sts.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), classes.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 1605 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1606 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1607 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no StringsIndex created."); |
| 1608 | } |
| 1609 | } |
| 1610 | |
| 1611 | autoTableOfRealcxx . . $ autoTableOfReal# HMM_HMMObservationSequence_to_TableOfReal_transitionscxx . . $ HMM_HMMObservationSequence_to_TableOfReal_transitions(3567f58da6922fc6). (HMM me, HMMObservationSequencecxx . . $ HMMObservationSequence# thee, int probabilities) { |
| 1612 | try { |
| 1613 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMObservationSequence_to_StringsIndexcxx . . $ HMM_HMMObservationSequence_to_StringsIndex(ad5f960e0fe6748c). (me, thee); |
| 1614 | autoTableOfRealcxx . . $ autoTableOfReal# him = StringsIndex_to_TableOfReal_transitionscxx . . $ StringsIndex_to_TableOfReal_transitions(baf5dc16ade1e25b). (si.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), probabilities); |
| 1615 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1616 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1617 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition table created for HMMObservationSequence."); |
| 1618 | } |
| 1619 | } |
| 1620 | |
| 1621 | autoTableOfRealcxx . . $ autoTableOfReal# HMM_HMMStateSequence_to_TableOfReal_transitionscxx . . $ HMM_HMMStateSequence_to_TableOfReal_transitions(f327171d0faaa012). (HMM me, HMMStateSequencecxx . . $ HMMStateSequence# thee, int probabilities) { |
| 1622 | try { |
| 1623 | autoStringsIndexcxx . . $ autoStringsIndex# si = HMM_HMMStateSequence_to_StringsIndexcxx . . $ HMM_HMMStateSequence_to_StringsIndex(c40a092f418921de). (me, thee); |
| 1624 | autoTableOfRealcxx . . $ autoTableOfReal# him = StringsIndex_to_TableOfReal_transitionscxx . . $ StringsIndex_to_TableOfReal_transitions(baf5dc16ade1e25b). (si.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), probabilities); |
| 1625 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1626 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1627 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition table created for HMMStateSequence."); |
| 1628 | } |
| 1629 | } |
| 1630 | |
| 1631 | autoTableOfRealcxx . . $ autoTableOfReal# StringsIndex_to_TableOfReal_transitionscxx . . $ StringsIndex_to_TableOfReal_transitions(baf5dc16ade1e25b). (StringsIndexcxx . . $ StringsIndex# me, int probabilities) { |
| 1632 | try { |
| 1633 | const integercxx . . $ integer# numberOfTypes = mycxx . . $ `melder/melder.h:44:9`! classescxx . . $ structIndex#classes.->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).sizecxx . . $ CollectionOf#size.; |
| 1634 | |
| 1635 | autoTableOfRealcxx . . $ autoTableOfReal# thee = TableOfReal_createcxx . . $ TableOfReal_create(e573ed3514e79d3). (numberOfTypes + 1, numberOfTypes + 1); |
| 1636 | for (integercxx . . $ integer# i = 1; i <= numberOfTypes; i ++) { |
| 1637 | const SimpleStringcxx . . $ SimpleString# s = (SimpleStringcxx . . $ SimpleString#) mycxx . . $ `melder/melder.h:44:9`! classescxx . . $ structIndex#classes.->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab).atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 1638 | TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, s -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1639 | TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i, s -> stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1640 | } |
| 1641 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfItemscxx . . $ structIndex#numberOfItems.; i ++) |
| 1642 | if (mycxx . . $ `melder/melder.h:44:9`! classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1] > 0 && mycxx . . $ `melder/melder.h:44:9`! classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i] > 0) // a zero is a restart! |
| 1643 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).mycxx . . $ `melder/melder.h:44:9`! classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i-1]] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! classIndexcxx . . $ structIndex#classIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]] ++; |
| 1644 | |
| 1645 | longdoublecxx . . $ longdouble# sum = 0.0; |
| 1646 | for (integercxx . . $ integer# i = 1; i <= numberOfTypes; i ++) { |
| 1647 | const double rowSum = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data..rowcxx . . $ automatrix#row(2d545b3cb3f8e666). (i)); |
| 1648 | const double colSum = NUMsumcxx . . $ NUMsum(4bb9c3e3a8dd5442). (thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data..columncxx . . $ automatrix#column(a8b9553e85c2b1fc). (i)); |
| 1649 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTypes + 1] = rowSum; |
| 1650 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).numberOfTypes + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] = colSum; |
| 1651 | sum += colSum; |
| 1652 | } |
| 1653 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).numberOfTypes + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTypes + 1] = sum; |
| 1654 | if (probabilities && sum > 0.0) { |
| 1655 | for (integercxx . . $ integer# i = 1; i <= numberOfTypes; i ++) |
| 1656 | if (thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTypes + 1] > 0.0) |
| 1657 | for (integercxx . . $ integer# j = 1; j <= numberOfTypes; j ++) |
| 1658 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] /= thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTypes + 1]; |
| 1659 | for (integercxx . . $ integer# i = 1; i <= numberOfTypes; i ++) { |
| 1660 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).numberOfTypes + 1] /= sum; |
| 1661 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).numberOfTypes + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] /= sum; |
| 1662 | } |
| 1663 | } |
| 1664 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1665 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1666 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition table created."); |
| 1667 | } |
| 1668 | } |
| 1669 | |
| 1670 | autoTableOfRealcxx . . $ autoTableOfReal# Strings_to_TableOfReal_transitionscxx . . $ Strings_to_TableOfReal_transitions(c553ca65e8404f05). (Stringscxx . . $ Strings# me, int probabilities) { |
| 1671 | try { |
| 1672 | autoStringsIndexcxx . . $ autoStringsIndex# him = Strings_to_StringsIndexcxx . . $ Strings_to_StringsIndex(786a22033bf23ced). (me, kStrings_sortingcxx . . $ kStrings_sorting#::ALPHABETICALcxx . . $ kStrings_sorting#ALPHABETICAL.); |
| 1673 | autoTableOfRealcxx . . $ autoTableOfReal# thee = StringsIndex_to_TableOfReal_transitionscxx . . $ StringsIndex_to_TableOfReal_transitions(baf5dc16ade1e25b). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), probabilities); |
| 1674 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1675 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1676 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": no transition table created."); |
| 1677 | } |
| 1678 | } |
| 1679 | |
| 1680 | /* End of file HMM.cpp */ |