Debian Codegraph @

gram/OTGrammar.cpp

raw symbols SCIP
1 /* OTGrammar.cpp
2 *
3 * Copyright (C) 1997-2026 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 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU 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 /*
20 * pb 2002/07/16 GPL
21 * pb 2002/11/04 randomize in case of equal candidates
22 * pb 2003/05/08 better superset violation warning
23 * pb 2003/05/23 made superset violation warning conditional
24 * pb 2003/10/15 backtrack in case of failing multiple chews for EDCD
25 * pb 2003/10/15 crucial ties option
26 * pb 2004/01/17 OTGrammar_Distributions_getFractionCorrect
27 * pb 2004/08/08 OTGrammar_removeHarmonicallyBoundedCandidates
28 * pb 2004/08/09 bug removal: more complete OTGrammar_save and restore (affected multiple-chew correctness),
29 * changing the 114.5 in Boersma (Phonology 2003) to 118.1
30 * pb 2004/08/09 suppressed superset violation in case of identical constraint violation patterns such
31 * as for /(L L2) L (L2 L) (L1 L)/ and /(L2 L) L (L L2) (L1 L)/, thus restricting the warning to cases
32 * of *strict* superset violations
33 * pb 2004/08/11 repaired memory leak in OTGrammarTableau_removeCandidate_unstripped
34 * pb 2004/09/10 monitor rankings during learning from PairDistribution or Distributions
35 * pb 2004/10/16 struct structOTxx
36 * pb 2005/01/24 write to headerless spreadsheet file
37 * pb 2005/04/19 OTHistory
38 * pb 2005/06/30 learning from partial pairs
39 * pb 2005/12/11 OTGrammar_honourlocalRankings:
40 * pb 2005/12/11 OTGrammar_PairDistribution_listObligatoryRankings (depth 1)
41 * pb 2006/01/05 new decision strategies: HarmonicGrammar and LinearOT
42 * pb 2006/01/21 better procedure name
43 * pb 2006/02/02 new decision strategy: ExponentialHG
44 * pb 2006/12/08 MelderInfo
45 * pb 2007/04/22 multiply learning step by number of violations (for HarmonicGrammar and LinearOT)
46 * pb 2007/04/25 new decision strategy: MaximumEntropy
47 * pb 2007/04/30 many improvements
48 * pb 2007/05/20 new decision strategy: PositiveHG
49 * pb 2007/06/21 corrected PositiveHG
50 * pb 2007/06/21 made spreadsheet file readable as Table
51 * pb 2007/07/24 leak and constraint plasticity
52 * pb 2007/07/27 leak and constraint plasticity also written...
53 * pb 2007/08/08 wchar
54 * pb 2007/10/01 can write as encoding
55 * pb 2008/03/03 EDCD with vacation
56 * pb 2008/03/07 Demote one with vacation
57 * pb 2008/03/07 Reset to random total ranking
58 * pb 2008/03/27 Exponential HG: reset average weight to zero after every change
59 * pb 2008/03/28 Exponential HG: set update rule to HG-GLA rather than OT-GLA
60 * pb 2008/03/31 OTGrammar_PairDistribution_findPositiveWeights
61 * pb 2008/04/08 made (OTGrammar & Distributions) learnFromPartialOutputs and getFractionCorrect five times faster
62 * pb 2008/04/12 split off NUMlinprog
63 * pb 2008/05/31 new decision strategy: ExponentialMaximumEntropy
64 * pb 2009/03/09 new update rule: Weighted all up, highest down
65 * pb 2009/07/07 OTGrammar_PairDistribution_getMinimumNumberCorrect
66 * pb 2010/06/05 corrected colours
67 * pb 2011/03/01 renamed "strategy" to "updateRule", "meanLearningStep" to "plasticity", "rankingSpreading" to "evaluationNoise"
68 * pb 2011/03/22 C++
69 * pb 2011/04/27 Melder_debug 41 and 42
70 * pb 2011/07/14 C++
71 * pb 2014/02/27 skippable symmetric all
72 * pb 2014/07/25 RRIP
73 * pb 2024/12/25 OTGrammar_allOutputsAreDistinguishable
74 */
75
76 #include "OTGrammar.h"cxx . . $ `<file>/gram/OTGrammar.h`/
77
78 #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/
79 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
80 #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/
81 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
82 #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/
83 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
84 #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/
85 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
86 #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/
87 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
88 #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/
89 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
90 #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/
91 #include "OTGrammar_def.h"cxx . . $ `<file>/gram/OTGrammar_def.h`/
92
93 #include "enums_getText.h"cxx . . $ `<file>/melder/enums_getText.h`/
94 #include "OTGrammar_enums.h"cxx . . $ `<file>/gram/OTGrammar_enums.h`/
95 #include "enums_getValue.h"cxx . . $ `<file>/melder/enums_getValue.h`/
96 #include "OTGrammar_enums.h"cxx . . $ `<file>/gram/OTGrammar_enums.h`/
97
98 void structOTGrammar :: v1_info () {
99 structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). ();
100 integercxx . . $ integer# numberOfCandidates = 0, numberOfViolations = 0;
101 for (integercxx . . $ integer# itab = 1; itab <= numberOfTableaus; itab ++) {
102 numberOfCandidates += ourcxx . . $ `melder/melder.h:42:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates;
103 for (integercxx . . $ integer# icand = 1; icand <= ourcxx . . $ `melder/melder.h:42:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; icand ++)
104 for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++)
105 numberOfViolations += ourcxx . . $ `melder/melder.h:42:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
106 }
107 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Decision strategy: ", kOTGrammar_decisionStrategy_getText (decisionStrategy));
108 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of constraints: ", numberOfConstraints);
109 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of tableaus: ", numberOfTableaus);
110 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of candidates: ", numberOfCandidates);
111 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of violation marks: ", numberOfViolations);
112 }
113
114 void structOTGrammar :: v1_writeText (MelderFilecxx . . $ MelderFile# file) {
115 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n<", kOTGrammar_decisionStrategy_getText (decisionStrategy),
116 U">\n", leak, U" ! leak\n", ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints, U" constraints");
117 for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++) {
118 OTGrammarConstraint constraint = & constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
119 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\nconstraint [", icons, U"]: \"");
120 for (const char32cxx . . $ char32# *p = & constraint -> name [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p; p ++) {
121 if (*p == U'\"')
122 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"'); // double any quotes within quotes
123 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p);
124 }
125 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\" ", constraint -> ranking,
126 U" ", constraint -> disharmony, U" ", constraint -> plasticity, U" ! ");
127 for (const char32cxx . . $ char32# *p = & constraint -> name [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p; p ++) {
128 if (*p == U'\n')
129 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U' ');
130 else if (*p == U'\\' && p [1] == U's' && p [2] == U'{')
131 p += 2;
132 else if (*p == U'}')
133 { }
134 else
135 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p);
136 }
137 }
138 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n\n", ourcxx . . $ `melder/melder.h:42:9`! numberOfFixedRankings, U" fixed rankings");
139 for (integercxx . . $ integer# irank = 1; irank <= ourcxx . . $ `melder/melder.h:42:9`! numberOfFixedRankings; irank ++) {
140 OTGrammarFixedRanking fixedRanking = & ourcxx . . $ `melder/melder.h:42:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irank];
141 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n ", fixedRanking -> higher, U" ", fixedRanking -> lower);
142 }
143 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n\n", ourcxx . . $ `melder/melder.h:42:9`! numberOfTableaus, U" tableaus");
144 for (integercxx . . $ integer# itab = 1; itab <= ourcxx . . $ `melder/melder.h:42:9`! numberOfTableaus; itab ++) {
145 OTGrammarTableau tableau = & ourcxx . . $ `melder/melder.h:42:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
146 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\ninput [", itab, U"]: \"");
147 for (const char32cxx . . $ char32# *p = & tableau -> input [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p; p ++) {
148 if (*p == U'\"')
149 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"'); // double any quotes within quotes
150 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p);
151 }
152 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\" ", tableau -> numberOfCandidates);
153 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
154 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
155 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n candidate [", icand, U"]: \"");
156 for (const char32cxx . . $ char32# *p = & candidate -> output [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p; p ++) {
157 if (*p == U'\"')
158 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"'); // double any quotes within quotes
159 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p);
160 }
161 MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"');
162 for (integercxx . . $ integer# icons = 1; icons <= candidate -> numberOfConstraints; icons ++) {
163 MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U" ", candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]);
164 }
165 }
166 }
167 }
168
169 void OTGrammar_checkIndexcxx . . $ OTGrammar_checkIndex(17bef8f582790df). (OTGrammar me) {
170 if (mycxx . . $ `melder/melder.h:44:9`! index.sizecxx . . $ autovector#size. != 0) return;
171 mycxx . . $ `melder/melder.h:44:9`! index =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). to_INTVECcxx . . $ to_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
172 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
173 }
174
175 void structOTGrammar :: v1_readText (MelderReadTextcxx . . $ MelderReadText# text, int formatVersion) {
176 OTGrammar_Parent :: v1_readTextcxx . . $ structDaata#v1_readText(97c85d3b778168ad). (text, formatVersion);
177 if (formatVersion >= 1) {
178 try {
179 ourcxx . . $ `melder/melder.h:42:9`! decisionStrategy = (kOTGrammar_decisionStrategy) texgete8cxx . . $ texgete8(5d13c7fbeaf5c6ca). (text, (enum_generic_getValuecxx . . $ enum_generic_getValue#) kOTGrammar_decisionStrategy_getValuecxx . . $ kOTGrammar_decisionStrategy_getValue(345d9c4981d3075b).);
180 } catch (MelderErrorcxx . . $ MelderError#) {
181 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read decision strategy.");
182 }
183 }
184 if (formatVersion >= 2) {
185 try {
186 ourcxx . . $ `melder/melder.h:42:9`! leak = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text);
187 } catch (MelderErrorcxx . . $ MelderError#) {
188 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read leak.");
189 }
190 }
191 try {
192 ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
193 } catch (MelderErrorcxx . . $ MelderError#) {
194 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read number of constraints.");
195 }
196 if (ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints < 1)
197 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No constraints.");
198 ourcxx . . $ `melder/melder.h:42:9`! constraints =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarConstraint> (ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints);
199 for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++) {
200 OTGrammarConstraint constraint = & constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
201 try {
202 constraint -> name =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (text);
203 } catch (MelderErrorcxx . . $ MelderError#) {
204 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read name of constraint ", icons, U".");
205 }
206 try {
207 constraint -> ranking = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text);
208 } catch (MelderErrorcxx . . $ MelderError#) {
209 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read ranking of constraint ", icons, U".");
210 }
211 try {
212 constraint -> disharmony = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text);
213 } catch (MelderErrorcxx . . $ MelderError#) {
214 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read disharmony of constraint ", icons, U".");
215 }
216 if (formatVersion < 2) {
217 constraint -> plasticity = 1.0;
218 } else {
219 try {
220 constraint -> plasticity = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text);
221 } catch (MelderErrorcxx . . $ MelderError#) {
222 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read plasticity of constraint ", icons, U".");
223 }
224 }
225 }
226 try {
227 ourcxx . . $ `melder/melder.h:42:9`! numberOfFixedRankings = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
228 } catch (MelderErrorcxx . . $ MelderError#) {
229 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read number of fixed rankings.");
230 }
231 if (ourcxx . . $ `melder/melder.h:42:9`! numberOfFixedRankings >= 1) {
232 ourcxx . . $ `melder/melder.h:42:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarFixedRanking> (numberOfFixedRankings);
233 for (integercxx . . $ integer# irank = 1; irank <= ourcxx . . $ `melder/melder.h:42:9`! numberOfFixedRankings; irank ++) {
234 OTGrammarFixedRanking fixedRanking = & ourcxx . . $ `melder/melder.h:42:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irank];
235 try {
236 fixedRanking -> higher = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
237 } catch (MelderErrorcxx . . $ MelderError#) {
238 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read the higher of constraint pair ", irank, U".");
239 }
240 try {
241 fixedRanking -> lower = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
242 } catch (MelderErrorcxx . . $ MelderError#) {
243 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read the lower of constraint pair ", irank, U".");
244 }
245 }
246 }
247 try {
248 ourcxx . . $ `melder/melder.h:42:9`! numberOfTableaus = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
249 } catch (MelderErrorcxx . . $ MelderError#) {
250 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read number of tableaus.");
251 }
252 if (ourcxx . . $ `melder/melder.h:42:9`! numberOfTableaus < 1)
253 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No tableaus.");
254 ourcxx . . $ `melder/melder.h:42:9`! tableaus =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarTableau> (numberOfTableaus);
255 for (integercxx . . $ integer# itab = 1; itab <= ourcxx . . $ `melder/melder.h:42:9`! numberOfTableaus; itab ++) {
256 OTGrammarTableau tableau = & ourcxx . . $ `melder/melder.h:42:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
257 try {
258 tableau -> input =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (text);
259 } catch (MelderErrorcxx . . $ MelderError#) {
260 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read input of tableau ", itab, U".");
261 }
262 try {
263 tableau -> numberOfCandidates = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text);
264 } catch (MelderErrorcxx . . $ MelderError#) {
265 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read number of candidates of tableau ", itab, U".");
266 }
267 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tableau -> numberOfCandidates > 0,
268 U"No candidates in tableau ", itab,
269 U" (input: ", tableau -> input.get(), U")"
270 U" in line ", MelderReadText_getLineNumber (text),
271 itab == 1 ? U"." : U", or perhaps wrong number of candidates for input «",
272 itab == 1 ? nullptr : ourcxx . . $ `melder/melder.h:42:9`! tableaus [itab - 1]. input.get(),
273 itab == 1 ? nullptr : U"»."
274 );
275 tableau -> candidates =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarCandidate> (tableau -> numberOfCandidates);
276 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
277 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
278 try {
279 candidate -> output =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (text);
280 } catch (MelderErrorcxx . . $ MelderError#) {
281 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read candidate ", icand, U" of tableau ", itab,
282 U" (input: ", tableau -> input.get(), U") in line ", MelderReadText_getLineNumber (text), U".");
283 }
284 candidate -> numberOfConstraints = numberOfConstraints; // redundancy, needed for writing binary
285 candidate -> marks =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_INTVECcxx . . $ zero_INTVEC(dab5d3ef28d6a25). (candidate -> numberOfConstraints);
286 for (integercxx . . $ integer# icons = 1; icons <= candidate -> numberOfConstraints; icons ++) {
287 try {
288 candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = texgeti16cxx . . $ texgeti16(df2c8a7d80e92f0e). (text);
289 } catch (MelderErrorcxx . . $ MelderError#) {
290 Melder_throwcxx . . $ `melder/melder_error.h:77:9`!
291 (U"Trying to read number of violations of constraint ", icons,
292 U" (", ourcxx . . $ `melder/melder.h:42:9`! constraints [icons]. name.get(), U")"
293 U" of candidate ", icand,
294 U" (", candidate -> output.get(), U")"
295 U" of tableau ", itab,
296 U" (input: ", tableau -> input.get(), U")"
297 U" in line ", MelderReadText_getLineNumber (text), U".");
298 }
299 }
300 }
301 }
302 OTGrammar_checkIndexcxx . . $ OTGrammar_checkIndex(17bef8f582790df). (this);
303 }
304
305 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (OTGrammar, Daata, 2);
306
307 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (OTHistory, TableOfReal, 0);
308
309 void OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (OTGrammar me) {
310 stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e). (mycxx . . $ `melder/melder.h:44:9`! index.begincxx . . $ autovector#begin(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! index.endcxx . . $ autovector#end(5a2a78a048fb49a8).(),
311 [me] (integercxx . . $ integer# icons, integercxx . . $ integer# jcons) {
312 OTGrammarConstraint ci = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons], cj = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons];
313 /*
314 Sort primarily by disharmony.
315 */
316 if (ci -> disharmony > cj -> disharmony) // already in descending order?
317 return true; // yes, already in descending order
318 if (ci -> disharmony < cj -> disharmony)
319 return false;
320 /*
321 Tied constraints are sorted alphabetically.
322 */
323 return str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) < 0;
324 }
325 );
326 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
327 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
328 constraint -> tiedToTheLeft = ( icons > 1 &&
329 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons - 1]]. disharmony == constraint -> disharmony );
330 constraint -> tiedToTheRight = ( icons < mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints &&
331 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons + 1]]. disharmony == constraint -> disharmony );
332 }
333 }
334
335 void OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (OTGrammar me, double spreading) {
336 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
337 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
338 constraint -> disharmony = constraint -> ranking + NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (0, spreading)
339 /*NUMrandomUniform (-spreading, spreading)*/;
340 }
341 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
342 }
343
344 integercxx . . $ integer# OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (constOTGrammar me, conststring32cxx . . $ conststring32# input) {
345 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++)
346 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), input))
347 return itab;
348 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Input \"", input, U"\" not in list of tableaus.");
349 }
350
351 static void _OTGrammar_fillInHarmoniescxx . . $ _OTGrammar_fillInHarmonies(fdf5e50ec04b442). (OTGrammar me, integercxx . . $ integer# itab) {
352 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::OPTIMALITY_THEORY)
353 return;
354 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
355 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
356 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
357 INTVECcxx . . $ INTVEC# marks = candidate -> marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
358 longdoublecxx . . $ longdouble# disharmony = 0.0;
359 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::HARMONIC_GRAMMAR ||
360 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::MAXIMUM_ENTROPY)
361 {
362 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
363 disharmony += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
364 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG ||
365 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY)
366 {
367 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
368 disharmony += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
369 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::LINEAR_OT || mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::NONNEGATIVE_MAXIMUM_ENTROPY) {
370 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
371 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony > 0.0)
372 disharmony += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
373 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::POSITIVE_HG) {
374 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
375 const double constraintDisharmony = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony, 1.0);
376 disharmony += constraintDisharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
377 }
378 } else {
379 Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"_OTGrammar_fillInHarmonies: unimplemented decision strategy.");
380 }
381 candidate -> harmony = - (double) disharmony;
382 }
383 }
384
385 int OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (OTGrammar me, integercxx . . $ integer# itab1, integercxx . . $ integer# icand1, integercxx . . $ integer# itab2, integercxx . . $ integer# icand2) {
386 INTVECcxx . . $ INTVEC# marks1 = mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab1]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand1]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
387 INTVECcxx . . $ INTVEC# marks2 = mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab2]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand2]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
388 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::OPTIMALITY_THEORY) {
389 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
390 integercxx . . $ integer# numberOfMarks1 = marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
391 integercxx . . $ integer# numberOfMarks2 = marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
392 /*
393 Count tied constraints as one.
394 */
395 while (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. tiedToTheRight) {
396 icons ++;
397 numberOfMarks1 += marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
398 numberOfMarks2 += marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
399 }
400 if (numberOfMarks1 < numberOfMarks2)
401 return -1; // candidate 1 is better than candidate 2
402 if (numberOfMarks1 > numberOfMarks2)
403 return +1; // candidate 2 is better than candidate 1
404 }
405 /*
406 If we arrive here, none of the comparisons found a difference
407 between the two candidates. Hence, they are equally good.
408 */
409 return 0;
410 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::HARMONIC_GRAMMAR ||
411 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::MAXIMUM_ENTROPY)
412 {
413 double disharmony1 = 0.0, disharmony2 = 0.0;
414 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
415 disharmony1 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
416 disharmony2 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
417 }
418 if (disharmony1 < disharmony2)
419 return -1; // candidate 1 is better than candidate 2
420 if (disharmony1 > disharmony2)
421 return +1; // candidate 2 is better than candidate 1
422 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::LINEAR_OT || mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::NONNEGATIVE_MAXIMUM_ENTROPY) {
423 double disharmony1 = 0.0, disharmony2 = 0.0;
424 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
425 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony > 0.0) {
426 disharmony1 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
427 disharmony2 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
428 }
429 }
430 if (disharmony1 < disharmony2)
431 return -1; // candidate 1 is better than candidate 2
432 if (disharmony1 > disharmony2)
433 return +1; // candidate 2 is better than candidate 1
434 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG ||
435 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY)
436 {
437 double disharmony1 = 0.0, disharmony2 = 0.0;
438 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
439 disharmony1 += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
440 disharmony2 += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
441 }
442 if (disharmony1 < disharmony2)
443 return -1; // candidate 1 is better than candidate 2
444 if (disharmony1 > disharmony2)
445 return +1; // candidate 2 is better than candidate 1
446 } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::POSITIVE_HG) {
447 double disharmony1 = 0.0, disharmony2 = 0.0;
448 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
449 double constraintDisharmony = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony, 1.0);
450 disharmony1 += constraintDisharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
451 disharmony2 += constraintDisharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons];
452 }
453 if (disharmony1 < disharmony2)
454 return -1; // candidate 1 is better than candidate 2
455 if (disharmony1 > disharmony2)
456 return +1; // candidate 2 is better than candidate 1
457 } else
458 Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Unimplemented decision strategy.");
459 return 0; // the two total disharmonies are equal
460 }
461
462 static void _OTGrammar_fillInProbabilitiescxx . . $ _OTGrammar_fillInProbabilities(fdf5e50ec04b442). (OTGrammar me, integercxx . . $ integer# itab) {
463 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
464 double maximumHarmony = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. harmony;
465 for (integercxx . . $ integer# icand = 2; icand <= tableau -> numberOfCandidates; icand ++) {
466 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
467 if (candidate -> harmony > maximumHarmony)
468 maximumHarmony = candidate -> harmony;
469 }
470 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
471 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
472 candidate -> probability = expcxx . . $ exp(fee4f1d22bc8e617). (candidate -> harmony - maximumHarmony);
473 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate -> probability >= 0.0 && candidate -> probability <= 1.0);
474 }
475 longdoublecxx . . $ longdouble# sumOfProbabilities = 0.0;
476 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
477 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
478 sumOfProbabilities += candidate -> probability;
479 }
480 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (sumOfProbabilities > 0.0); // because at least one of them is 1.0
481 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
482 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
483 candidate -> probability /= double (sumOfProbabilities);
484 }
485 }
486
487 integercxx . . $ integer# OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (OTGrammar me, integercxx . . $ integer# itab) {
488 integercxx . . $ integer# icand_best = 1;
489 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::MAXIMUM_ENTROPY ||
490 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY ||
491 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::NONNEGATIVE_MAXIMUM_ENTROPY)
492 {
493 _OTGrammar_fillInHarmoniescxx . . $ _OTGrammar_fillInHarmonies(fdf5e50ec04b442). (me, itab);
494 _OTGrammar_fillInProbabilitiescxx . . $ _OTGrammar_fillInProbabilities(fdf5e50ec04b442). (me, itab);
495 double cutOff = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0);
496 longdoublecxx . . $ longdouble# sumOfProbabilities = 0.0;
497 for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; icand ++) {
498 sumOfProbabilities += mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. probability;
499 if (sumOfProbabilities > cutOff) {
500 icand_best = icand;
501 break;
502 }
503 }
504 } else {
505 integercxx . . $ integer# numberOfBestCandidates = 1;
506 for (integercxx . . $ integer# icand = 2; icand <= mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; icand ++) {
507 int comparison = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, icand_best);
508 if (comparison == -1) {
509 icand_best = icand; // the current candidate is the unique best candidate found so far
510 numberOfBestCandidates = 1;
511 } else if (comparison == 0) {
512 numberOfBestCandidates += 1; // the current candidate is equally good as the best found before
513 /*
514 Give all candidates that are equally good an equal chance to become the winner.
515 */
516 if (Melder_debugcxx . . $ Melder_debug. == 41) {
517 icand_best = icand_best; // keep first
518 } else if (Melder_debugcxx . . $ Melder_debug. == 42) {
519 icand_best = icand; // take last
520 } else if (NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, numberOfBestCandidates) < 1.0) { // default: take random
521 icand_best = icand;
522 }
523 }
524 }
525 }
526 return icand_best;
527 }
528
529 integercxx . . $ integer# OTGrammar_getNumberOfOptimalCandidatescxx . . $ OTGrammar_getNumberOfOptimalCandidates(7a18ede9c0367db4). (OTGrammar me, integercxx . . $ integer# itab) {
530 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::MAXIMUM_ENTROPY ||
531 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY ||
532 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::NONNEGATIVE_MAXIMUM_ENTROPY) return 1;
533 integercxx . . $ integer# icand_best = 1, numberOfBestCandidates = 1;
534 for (integercxx . . $ integer# icand = 2; icand <= mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; icand ++) {
535 int comparison = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, icand_best);
536 if (comparison == -1) {
537 icand_best = icand; // the current candidate is the best candidate found so far
538 numberOfBestCandidates = 1;
539 } else if (comparison == 0) {
540 numberOfBestCandidates += 1; // the current candidate is equally good as the best found before
541 }
542 }
543 return numberOfBestCandidates;
544 }
545
546 bool OTGrammar_isCandidateGrammaticalcxx . . $ OTGrammar_isCandidateGrammatical(f38c237485a6e739). (OTGrammar me, integercxx . . $ integer# itab, integercxx . . $ integer# icand) {
547 for (integercxx . . $ integer# jcand = 1; jcand <= mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; jcand ++)
548 if (jcand != icand && OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, jcand, itab, icand) < 0)
549 return false;
550 return true;
551 }
552
553 bool OTGrammar_isCandidateSinglyGrammaticalcxx . . $ OTGrammar_isCandidateSinglyGrammatical(f38c237485a6e739). (OTGrammar me, integercxx . . $ integer# itab, integercxx . . $ integer# icand) {
554 for (integercxx . . $ integer# jcand = 1; jcand <= mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates; jcand ++)
555 if (jcand != icand && OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, jcand, itab, icand) <= 0)
556 return false;
557 return true;
558 }
559
560 void OTGrammar_getInterpretiveParsecxx . . $ OTGrammar_getInterpretiveParse(c29944d43509464b). (OTGrammar me, conststring32cxx . . $ conststring32# partialOutput, integercxx . . $ integer# *out_bestTableau, integercxx . . $ integer# *out_bestCandidate) {
561 try {
562 integercxx . . $ integer# itab_best = 0, icand_best = 0, numberOfBestCandidates = 0;
563 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
564 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
565 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
566 OTGrammarCandidate cand = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
567 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (cand -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput)) { // T&S' idea of surface->overt mapping
568 if (itab_best == 0) {
569 itab_best = itab; // the first compatible input/output pair found is the first guess for the best candidate
570 icand_best = icand;
571 numberOfBestCandidates = 1;
572 } else {
573 int comparison = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab_best, icand_best);
574 if (comparison == -1) {
575 itab_best = itab; // the current input/output pair is the best candidate found so far
576 icand_best = icand;
577 numberOfBestCandidates = 1;
578 } else if (comparison == 0) {
579 numberOfBestCandidates += 1; // the current input/output pair is equally good as the best found before
580 /*
581 * Give all candidates that are equally good an equal chance to become the winner.
582 */
583 if (Melder_debugcxx . . $ Melder_debug. == 41) {
584 itab_best = itab_best;
585 icand_best = icand_best; // keep first
586 } else if (Melder_debugcxx . . $ Melder_debug. == 42) {
587 itab_best = itab;
588 icand_best = icand; // take last
589 } else if (NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, numberOfBestCandidates) < 1.0) { // default: take random
590 itab_best = itab;
591 icand_best = icand;
592 }
593 }
594 }
595 }
596 }
597 }
598 if (itab_best == 0)
599 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The partial output \"", partialOutput, U"\" does not match any candidate for any input form.");
600 if (out_bestTableau)
601 *out_bestTableau = itab_best;
602 if (out_bestCandidate)
603 *out_bestCandidate = icand_best;
604 } catch (MelderErrorcxx . . $ MelderError#) {
605 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Interpretive parse not computed.");
606 }
607 }
608
609 static void OTGrammar_getInterpretiveParse_optcxx . . $ OTGrammar_getInterpretiveParse_opt(197077f79b5e7fbb). (OTGrammar me, integercxx . . $ integer# ipartialOutput, integercxx . . $ integer# *out_bestTableau, integercxx . . $ integer# *out_bestCandidate) {
610 try {
611 integercxx . . $ integer# itab_best = 0, icand_best = 0, numberOfBestCandidates = 0;
612 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
613 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
614 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
615 OTGrammarCandidate cand = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
616 if (cand -> partialOutputMatches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipartialOutput]) { // T&S' idea of surface->overt mapping
617 if (itab_best == 0) {
618 itab_best = itab; // the first compatible input/output pair found is the first guess for the best candidate
619 icand_best = icand;
620 numberOfBestCandidates = 1;
621 } else {
622 int comparison = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab_best, icand_best);
623 if (comparison == -1) {
624 itab_best = itab; // the current input/output pair is the best candidate found so far
625 icand_best = icand;
626 numberOfBestCandidates = 1;
627 } else if (comparison == 0) {
628 numberOfBestCandidates += 1; // the current input/output pair is equally good as the best found before
629 /*
630 * Give all candidates that are equally good an equal chance to become the winner.
631 */
632 if (Melder_debugcxx . . $ Melder_debug. == 41) {
633 itab_best = itab_best;
634 icand_best = icand_best; // keep first
635 } else if (Melder_debugcxx . . $ Melder_debug. == 42) {
636 itab_best = itab;
637 icand_best = icand; // take last
638 } else if (NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, numberOfBestCandidates) < 1.0) { // default: take random
639 itab_best = itab;
640 icand_best = icand;
641 }
642 }
643 }
644 }
645 }
646 }
647 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (itab_best != 0);
648 if (out_bestTableau)
649 *out_bestTableau = itab_best;
650 if (out_bestCandidate)
651 *out_bestCandidate = icand_best;
652 } catch (MelderErrorcxx . . $ MelderError#) {
653 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Interpretive parse not computed.");
654 }
655 }
656
657 bool OTGrammar_isPartialOutputGrammaticalcxx . . $ OTGrammar_isPartialOutputGrammatical(f10314946276fdfa). (OTGrammar me, conststring32cxx . . $ conststring32# partialOutput) {
658 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
659 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
660 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
661 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput))
662 if (OTGrammar_isCandidateGrammaticalcxx . . $ OTGrammar_isCandidateGrammatical(f38c237485a6e739). (me, itab, icand))
663 return true;
664 }
665 }
666 return false;
667 }
668
669 bool OTGrammar_areAllPartialOutputsGrammaticalcxx . . $ OTGrammar_areAllPartialOutputsGrammatical(78c251f47636c607). (OTGrammar me, Stringscxx . . $ Strings# thee) {
670 for (integercxx . . $ integer# ioutput = 1; ioutput <= thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; ioutput ++) {
671 conststring32cxx . . $ conststring32# partialOutput = thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ioutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
672 if (! OTGrammar_isPartialOutputGrammaticalcxx . . $ OTGrammar_isPartialOutputGrammatical(f10314946276fdfa). (me, partialOutput))
673 return false;
674 }
675 return true;
676 }
677
678 bool OTGrammar_isPartialOutputSinglyGrammaticalcxx . . $ OTGrammar_isPartialOutputSinglyGrammatical(f10314946276fdfa). (OTGrammar me, conststring32cxx . . $ conststring32# partialOutput) {
679 bool found = false;
680 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
681 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
682 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
683 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput)) {
684 if (OTGrammar_isCandidateGrammaticalcxx . . $ OTGrammar_isCandidateGrammatical(f38c237485a6e739). (me, itab, icand)) {
685 found = true;
686 /*
687 All other grammatical candidates should match.
688 */
689 for (integercxx . . $ integer# jcand = 1; jcand <= tableau -> numberOfCandidates; jcand ++) {
690 if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, jcand, itab, icand) == 0)
691 if (! str32strcxx . . $ str32str(2de17cd8f7c584a6). (tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput))
692 return false; // partial output is multiply optimal
693 }
694 }
695 }
696 }
697 }
698 return found;
699 }
700
701 bool OTGrammar_areAllPartialOutputsSinglyGrammaticalcxx . . $ OTGrammar_areAllPartialOutputsSinglyGrammatical(78c251f47636c607). (OTGrammar me, Stringscxx . . $ Strings# thee) {
702 for (integercxx . . $ integer# ioutput = 1; ioutput <= thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; ioutput ++) {
703 conststring32cxx . . $ conststring32# partialOutput = thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ioutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
704 if (! OTGrammar_isPartialOutputSinglyGrammaticalcxx . . $ OTGrammar_isPartialOutputSinglyGrammatical(f10314946276fdfa). (me, partialOutput))
705 return false;
706 }
707 return true;
708 }
709
710 static integercxx . . $ integer# OTGrammar_crucialCellcxx . . $ OTGrammar_crucialCell(d847cb0037bf05). (OTGrammar me, integercxx . . $ integer# itab, integercxx . . $ integer# icand, integercxx . . $ integer# iwinner, integercxx . . $ integer# numberOfOptimalCandidates) {
711 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
712 if (tableau -> numberOfCandidates < 2) return 0; // if there is only one candidate, all cells can be greyed
713 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::OPTIMALITY_THEORY) return mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; // nothing grey
714 if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, iwinner) == 0) { // candidate equally good as winner?
715 if (numberOfOptimalCandidates > 1) {
716 /* All cells are important. */
717 } else {
718 integercxx . . $ integer# secondBest = 0;
719 for (integercxx . . $ integer# jcand = 1; jcand <= tableau -> numberOfCandidates; jcand ++) {
720 if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, jcand, itab, iwinner) != 0) { // a non-optimal candidate?
721 if (secondBest == 0) {
722 secondBest = jcand; // first guess
723 } else if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, jcand, itab, secondBest) < 0) {
724 secondBest = jcand; // better guess
725 }
726 }
727 }
728 if (secondBest == 0) return 0; // if all candidates are equally good, all cells can be greyed
729 return OTGrammar_crucialCellcxx . . $ OTGrammar_crucialCell(d847cb0037bf05). (me, itab, secondBest, iwinner, 1);
730 }
731 } else {
732 const constINTVECcxx . . $ constINTVEC# candidateMarks = tableaucxx . . $ constvector#constvector(eac9d6ec4c4bfecd). -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
733 const constINTVECcxx . . $ constINTVEC# winnerMarks = tableaucxx . . $ constvector#constvector(eac9d6ec4c4bfecd). -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
734 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
735 integercxx . . $ integer# numberOfCandidateMarks = candidateMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
736 integercxx . . $ integer# numberOfWinnerMarks = winnerMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
737 while (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. tiedToTheRight) {
738 icons ++;
739 numberOfCandidateMarks += candidateMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
740 numberOfWinnerMarks += winnerMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
741 }
742 if (numberOfCandidateMarks > numberOfWinnerMarks)
743 return icons;
744 }
745 }
746 return mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; // nothing grey
747 }
748
749 static double OTGrammar_constraintWidthcxx . . $ OTGrammar_constraintWidth(c49f17072ec643bd). (Graphicscxx . . $ Graphics# g, conststring32cxx . . $ conststring32# name) {
750 char32cxx . . $ char32# text [100];
751 Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (text,100, name);
752 char32cxx . . $ char32# *newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (text, U'\n');
753 if (newLine) {
754 double firstWidth, secondWidth;
755 *newLine = U'\0';
756 firstWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, text);
757 secondWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, newLine + 1);
758 return firstWidth > secondWidth ? firstWidth : secondWidth;
759 }
760 return Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, text);
761 }
762
763 void OTGrammar_drawTableaucxx . . $ OTGrammar_drawTableau(822cef9b7e8eee15). (OTGrammar me, Graphicscxx . . $ Graphics# g, bool vertical, conststring32cxx . . $ conststring32# input) {
764 try {
765 const double fontSize = Graphics_inqFontSizecxx . . $ Graphics_inqFontSize(f906975acce41a59). (g);
766 MelderColourcxx . . $ MelderColour# colour = Graphics_inqColourcxx . . $ Graphics_inqColour(322ea1b2fa08ba06). (g);
767 const integercxx . . $ integer# itab = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
768 _OTGrammar_fillInHarmoniescxx . . $ _OTGrammar_fillInHarmonies(fdf5e50ec04b442). (me, itab);
769 const integercxx . . $ integer# winner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
770
771 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, 0.0, 1.0, 0.0, 1.0);
772 const double margin = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 1.0);
773 const double fingerWidth = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 7.0) * fontSize / 12.0;
774 const double doubleLineDx = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 0.9);
775 const double doubleLineDy = Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 0.9);
776 const double rowHeight = Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 1.5 * fontSize * 25.4 / 72);
777 const double descent = rowHeight * 0.5;
778 const double worldAspectRatio = Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 1.0) / Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 1.0); // because Graphics_textWidth measures in the x direction only
779 /*
780 Compute the height of the header row.
781 */
782 double headerHeight;
783 if (vertical) {
784 headerHeight = 0.0;
785 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
786 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
787 const double constraintTextWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
788 if (constraintTextWidth > headerHeight)
789 headerHeight = constraintTextWidth;
790 }
791 headerHeight += margin * 2;
792 headerHeight *= worldAspectRatio;
793 } else {
794 headerHeight = rowHeight;
795 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
796 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
797 if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n')) {
798 headerHeight *= 1.6;
799 break;
800 }
801 }
802 }
803 /*
804 Compute longest candidate string.
805 Also count the number of optimal candidates (if there are more than one, the fingers will be drawn in red).
806 */
807 double candWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, input);
808 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
809 integercxx . . $ integer# numberOfOptimalCandidates = 0;
810 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
811 double width = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
812 if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, winner) == 0) {
813 width += fingerWidth;
814 numberOfOptimalCandidates ++;
815 }
816 if (width > candWidth)
817 candWidth = width;
818 }
819 candWidth += margin * 3;
820 /*
821 Compute tableau width.
822 */
823 double tableauWidth = candWidth + doubleLineDx;
824 if (vertical) {
825 tableauWidth += rowHeight * mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints / worldAspectRatio;
826 } else {
827 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
828 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
829 tableauWidth += OTGrammar_constraintWidthcxx . . $ OTGrammar_constraintWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
830 }
831 tableauWidth += margin * 2 * mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints;
832 }
833 /*
834 Draw box.
835 */
836 double x = doubleLineDx; // left side of tableau
837 double y = 1.0 - doubleLineDy;
838 Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + tableauWidth,
839 y - headerHeight - tableau -> numberOfCandidates * rowHeight - doubleLineDy, y);
840 /*
841 Draw input.
842 */
843 y -= headerHeight;
844 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
845 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + 0.5 * candWidth, y + 0.5 * headerHeight, input);
846 Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + candWidth, y, y + headerHeight);
847 /*
848 Draw constraint names.
849 */
850 x += candWidth + doubleLineDx;
851 if (vertical)
852 Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 90.0);
853 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
854 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
855 const double width = vertical ? rowHeight / worldAspectRatio : OTGrammar_constraintWidthcxx . . $ OTGrammar_constraintWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) + margin * 2;
856 if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n') && ! vertical) {
857 autoMelderStringcxx . . $ autoMelderString# textcxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).;
858 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& text, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
859 char32cxx . . $ char32# *newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (text.stringcxx . . $ MelderString#string., U'\n');
860 *newLine = U'\0';
861 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!);
862 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + headerHeight, text.stringcxx . . $ MelderString#string.);
863 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!);
864 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y, newLine + 1);
865 } else if (vertical) {
866 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
867 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + margin, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
868 } else {
869 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
870 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + 0.5 * headerHeight, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
871 }
872 if (constraint -> tiedToTheLeft)
873 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`!);
874 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x, y + headerHeight);
875 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!);
876 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x + width, y);
877 x += width;
878 }
879 if (vertical)
880 Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 0.0);
881 /*
882 Draw candidates.
883 */
884 y -= doubleLineDy;
885 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
886 integercxx . . $ integer# crucialCell = OTGrammar_crucialCellcxx . . $ OTGrammar_crucialCell(d847cb0037bf05). (me, itab, icand, winner, numberOfOptimalCandidates);
887 bool candidateIsOptimal = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, winner) == 0;
888 /*
889 Draw candidate transcription.
890 */
891 x = doubleLineDx;
892 y -= rowHeight;
893 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
894 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + candWidth - margin, y + descent, tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
895 if (candidateIsOptimal) {
896 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
897 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 1.5 * fontSize);
898 if (numberOfOptimalCandidates > 1) Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.);
899 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + margin, y + descent - Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 1.0) * fontSize / 12.0, U"☞");
900 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour);
901 Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize);
902 }
903 Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + candWidth, y, y + rowHeight);
904 /*
905 Draw grey cell backgrounds.
906 */
907 x = candWidth + 2 * doubleLineDx;
908 Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (g, 0.9);
909 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
910 const integercxx . . $ integer# index = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
911 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index];
912 const double width = ( vertical ? rowHeight / worldAspectRatio :
913 OTGrammar_constraintWidthcxx . . $ OTGrammar_constraintWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) + margin * 2 );
914 if (icons > crucialCell)
915 Graphics_fillRectanglecxx . . $ Graphics_fillRectangle(72bdb7937dbb13da). (g, x, x + width, y, y + rowHeight);
916 x += width;
917 }
918 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour);
919 /*
920 Draw cell marks.
921 */
922 x = candWidth + 2 * doubleLineDx;
923 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
924 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
925 const integercxx . . $ integer# index = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
926 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index];
927 const double width = vertical ? rowHeight / worldAspectRatio : OTGrammar_constraintWidthcxx . . $ OTGrammar_constraintWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) + margin * 2;
928 static MelderStringcxx . . $ MelderString# markString;
929 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& markString);
930 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::OPTIMALITY_THEORY) {
931 /*
932 An exclamation mark can be drawn in this cell only if all of the following conditions are met:
933 1. the candidate is not optimal;
934 2. the constraint is not tied;
935 3. this is the crucial cell, i.e. the cells after it are drawn in grey.
936 */
937 if (icons == crucialCell && ! candidateIsOptimal && ! constraint -> tiedToTheLeft && ! constraint -> tiedToTheRight) {
938 const integercxx . . $ integer# winnerMarks = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).winner]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index];
939 for (integercxx . . $ integer# imark = 1; imark <= winnerMarks + 1; imark ++)
940 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
941 for (integercxx . . $ integer# imark = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark < 0; imark ++)
942 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'+');
943 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'!');
944 for (integercxx . . $ integer# imark = winnerMarks + 2; imark <= tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++)
945 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
946 } else {
947 if (! candidateIsOptimal && (constraint -> tiedToTheLeft || constraint -> tiedToTheRight) &&
948 crucialCell >= 1 && constraint -> disharmony == mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialCell]]. disharmony)
949 {
950 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.);
951 }
952 for (integercxx . . $ integer# imark = 1; imark <= tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++)
953 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
954 for (integercxx . . $ integer# imark = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark < 0; imark ++)
955 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'+');
956 }
957 } else {
958 for (integercxx . . $ integer# imark = 1; imark <= tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++)
959 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
960 for (integercxx . . $ integer# imark = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark < 0; imark ++)
961 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'+');
962 }
963 Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + descent, markString.stringcxx . . $ MelderString#string.);
964 Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour);
965 if (constraint -> tiedToTheLeft)
966 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`!);
967 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x, y + rowHeight);
968 Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DRAWNcxx . . $ `sys/Graphics.h:287:9`!);
969 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y + rowHeight, x + width, y + rowHeight);
970 x += width;
971 }
972 /*
973 Draw harmony.
974 */
975 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::OPTIMALITY_THEORY) {
976 Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!);
977 const double value = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. harmony;
978 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG ||
979 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY)
980 {
981 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, y + descent, Melder_graphicalHalfcxx . . $ Melder_graphicalHalf(f05d861d9dbec9b2). (value));
982 } else {
983 Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x, y + descent, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (value, 3));
984 }
985 }
986 }
987 /*
988 Draw box.
989 */
990 x = doubleLineDx; // left side of tableau
991 y = 1.0 - doubleLineDy;
992 Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + tableauWidth,
993 y - headerHeight - tableau -> numberOfCandidates * rowHeight - doubleLineDy, y);
994 } catch (MelderErrorcxx . . $ MelderError#) {
995 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": tableau not drawn.");
996 }
997 }
998
999 autoStringscxx . . $ autoStrings# OTGrammar_generateInputscxx . . $ OTGrammar_generateInputs(2c631e0145e471da). (OTGrammar me, integercxx . . $ integer# numberOfTrials) {
1000 try {
1001 autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
1002 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = numberOfTrials);
1003 for (integercxx . . $ integer# i = 1; i <= numberOfTrials; i ++) {
1004 integercxx . . $ integer# itab = NUMrandomIntegercxx . . $ NUMrandomInteger(d0a0e4c270da0eca). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus);
1005 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1006 }
1007 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1008 } catch (MelderErrorcxx . . $ MelderError#) {
1009 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": inputs not generated.");
1010 }
1011 }
1012
1013 autoStringscxx . . $ autoStrings# OTGrammar_getInputscxx . . $ OTGrammar_getInputs(d533707318a2ea1b). (OTGrammar me) {
1014 try {
1015 autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
1016 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus);
1017 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; i ++)
1018 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1019 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1020 } catch (MelderErrorcxx . . $ MelderError#) {
1021 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": inputs not gotten.");
1022 }
1023 }
1024
1025 autostring32cxx . . $ autostring32# OTGrammar_inputToOutputcxx . . $ OTGrammar_inputToOutput(c8f670774824696c). (OTGrammar me, conststring32cxx . . $ conststring32# input, double evaluationNoise) {
1026 try {
1027 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
1028 integercxx . . $ integer# itab = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
1029 integercxx . . $ integer# winner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
1030 if (winner == 0)
1031 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No winner");
1032 return Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).winner]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1033 } catch (MelderErrorcxx . . $ MelderError#) {
1034 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": output not computed from input \"", input, U"\".");
1035 }
1036 }
1037
1038 autoStringscxx . . $ autoStrings# OTGrammar_inputsToOutputscxx . . $ OTGrammar_inputsToOutputs(14edd5c2a0df16ec). (OTGrammar me, Stringscxx . . $ Strings# inputs, double evaluationNoise) {
1039 try {
1040 autoStringscxx . . $ autoStrings# him = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
1041 integercxx . . $ integer# n = inputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.;
1042 hiscxx . . $ `melder/melder.h:47:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = n;
1043 hiscxx . . $ `melder/melder.h:47:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (n);
1044 for (integercxx . . $ integer# i = 1; i <= n; i ++)
1045 hiscxx . . $ `melder/melder.h:47:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). OTGrammar_inputToOutputcxx . . $ OTGrammar_inputToOutput(c8f670774824696c). (me, inputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), evaluationNoise);
1046 return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1047 } catch (MelderErrorcxx . . $ MelderError#) {
1048 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": outputs not computed.");
1049 }
1050 }
1051
1052 autoStringscxx . . $ autoStrings# OTGrammar_inputToOutputscxx . . $ OTGrammar_inputToOutputs(d25e0ea609ea9bc8). (OTGrammar me, conststring32cxx . . $ conststring32# input, integercxx . . $ integer# n, double evaluationNoise) {
1053 try {
1054 autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
1055 thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = n;
1056 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (n);
1057 for (integercxx . . $ integer# i = 1; i <= n; i ++)
1058 thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). OTGrammar_inputToOutputcxx . . $ OTGrammar_inputToOutput(c8f670774824696c). (me, input, evaluationNoise);
1059 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1060 } catch (MelderErrorcxx . . $ MelderError#) {
1061 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": output not computed.");
1062 }
1063 }
1064
1065 autoDistributionscxx . . $ autoDistributions# OTGrammar_to_Distributioncxx . . $ OTGrammar_to_Distribution(e63311810804d1e0). (OTGrammar me, integercxx . . $ integer# trialsPerInput, double noise) {
1066 try {
1067 integercxx . . $ integer# totalNumberOfOutputs = 0, nout = 0;
1068 /*
1069 Count the total number of outputs.
1070 */
1071 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++)
1072 totalNumberOfOutputs += mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates;
1073 /*
1074 Create the distribution. One row for every output form.
1075 */
1076 autoDistributionscxx . . $ autoDistributions# thee = Distributions_createcxx . . $ Distributions_create(6e2acaa0535ba708). (totalNumberOfOutputs, 1);
1077 /*
1078 Measure every input form.
1079 */
1080 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"OTGrammar: compute output distribution.");
1081 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
1082 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1083 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((itab - 0.5) / mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus, U"Measuring input \"", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\"");
1084 /*
1085 Set the row labels to the output strings.
1086 */
1087 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
1088 thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).nout + icand] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (
1089 Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" \\-> ", tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).())
1090 );
1091 }
1092 /*
1093 Compute a number of outputs and store the results.
1094 */
1095 for (integercxx . . $ integer# itrial = 1; itrial <= trialsPerInput; itrial ++) {
1096 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, noise);
1097 integercxx . . $ integer# iwinner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
1098 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).nout + iwinner] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] += 1;
1099 }
1100 /*
1101 Update the offset.
1102 */
1103 nout += tableau -> numberOfCandidates;
1104 }
1105 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1106 } catch (MelderErrorcxx . . $ MelderError#) {
1107 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": output distribution not computed.");
1108 }
1109 }
1110
1111 autoPairDistributioncxx . . $ autoPairDistribution# OTGrammar_to_PairDistributioncxx . . $ OTGrammar_to_PairDistribution(816b1fe75c724a5c). (OTGrammar me, integercxx . . $ integer# trialsPerInput, double noise) {
1112 try {
1113 integercxx . . $ integer# nout = 0;
1114 /*
1115 Create the distribution. One row for every output form.
1116 */
1117 autoPairDistributioncxx . . $ autoPairDistribution# thee = PairDistribution_createcxx . . $ PairDistribution_create(55fbb411edc59193). ();
1118 /*
1119 Measure every input form.
1120 */
1121 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"OTGrammar: compute output distribution.");
1122 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
1123 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1124 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((itab - 0.5) / mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus, U"Measuring input \"", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\"");
1125 /*
1126 Copy the input and output strings to the target object.
1127 */
1128 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
1129 PairDistribution_addcxx . . $ PairDistribution_add(abae96e3399dd15c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0.0);
1130 }
1131 /*
1132 Compute a number of outputs and store the results.
1133 */
1134 for (integercxx . . $ integer# itrial = 1; itrial <= trialsPerInput; itrial ++) {
1135 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, noise);
1136 integercxx . . $ integer# iwinner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
1137 thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).nout + iwinner] -> weightcxx . . $ structPairProbability#weight. += 1.0;
1138 }
1139 /*
1140 Update the offset.
1141 */
1142 nout += tableau -> numberOfCandidates;
1143 }
1144 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1145 } catch (MelderErrorcxx . . $ MelderError#) {
1146 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": output distribution not computed.");
1147 }
1148 }
1149
1150 static bool honoursFixedRankingscxx . . $ honoursFixedRankings(62951cbe4b2b5c08). (OTGrammar me) {
1151 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; i ++) {
1152 integercxx . . $ integer# higher = mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. higher, lower = mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. lower;
1153 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1154 if (mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] == higher)
1155 break; // detected higher before lower: OK
1156 if (mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] == lower)
1157 return false;
1158 }
1159 }
1160 return true;
1161 }
1162
1163 autoDistributionscxx . . $ autoDistributions# OTGrammar_measureTypology_WEAKcxx . . $ OTGrammar_measureTypology_WEAK(e4ba9d8bf50fd03e). (OTGrammar me) {
1164 try {
1165 integercxx . . $ integer# totalNumberOfOutputs = 0, nout = 0, nperm, factorial [1+12];
1166 if (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints > 12)
1167 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot handle more than 12 constraints.");
1168 factorial [0] = 1;
1169 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1170 factorial [icons] = factorial [icons - 1] * icons;
1171 nperm = factorial [mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints];
1172 /*
1173 Count the total number of outputs.
1174 */
1175 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++)
1176 totalNumberOfOutputs += mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. numberOfCandidates;
1177 /*
1178 Create the distribution. One row for every output form.
1179 */
1180 autoDistributionscxx . . $ autoDistributions# thee = Distributions_createcxx . . $ Distributions_create(6e2acaa0535ba708). (totalNumberOfOutputs, 1);
1181 /*
1182 Measure every input form.
1183 */
1184 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Measuring typology...");
1185 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
1186 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1187 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((itab - 0.5) / mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus, U"Measuring input \"", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\"");
1188 /*
1189 Set the row labels to the output strings.
1190 */
1191 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
1192 thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).nout + icand] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (
1193 Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" \\-> ", tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).())
1194 );
1195 }
1196 /*
1197 Compute a number of outputs and store the results.
1198 */
1199 for (integercxx . . $ integer# iperm = 0; iperm < nperm; iperm ++) {
1200 integercxx . . $ integer# permleft = iperm, iwinner;
1201 /* Initialize to 12345 before permuting. */
1202 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1203 mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = icons;
1204 for (integercxx . . $ integer# icons = 1; icons < mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1205 const integercxx . . $ integer# fac = factorial [mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints - icons], shift = permleft / fac;
1206 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons], mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons + shift]);
1207 permleft %= fac;
1208 }
1209 if (honoursFixedRankingscxx . . $ honoursFixedRankings(62951cbe4b2b5c08). (me)) {
1210 iwinner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
1211 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).nout + iwinner] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] += 1;
1212 }
1213 }
1214 /*
1215 Update the offset.
1216 */
1217 nout += tableau -> numberOfCandidates;
1218 }
1219 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
1220 } catch (MelderErrorcxx . . $ MelderError#) {
1221 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": typology not measured.");
1222 }
1223 }
1224
1225 static double learningStepcxx . . $ learningStep(d8e7e0733fa41c87). (double mean, double relativeSpreading) {
1226 return relativeSpreading == 0.0 ? mean : NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (mean, relativeSpreading * mean);
1227 }
1228
1229 static void OTGrammar_honourLocalRankingscxx . . $ OTGrammar_honourLocalRankings(1aa770b9d7841165). (OTGrammar me, double plasticity, double relativePlasticityNoise, bool *grammarHasChanged) {
1230 bool improved;
1231 do {
1232 improved = false;
1233 for (integercxx . . $ integer# irank = 1; irank <= mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; irank ++) {
1234 OTGrammarFixedRanking fixedRanking = & mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).irank];
1235 OTGrammarConstraint higher = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).fixedRanking -> higher], lower = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).fixedRanking -> lower];
1236 while (higher -> ranking <= lower -> ranking) {
1237 lower -> ranking -= learningStepcxx . . $ learningStep(d8e7e0733fa41c87). (plasticity, relativePlasticityNoise);
1238 if (grammarHasChanged)
1239 *grammarHasChanged = true;
1240 improved = true;
1241 }
1242 }
1243 } while (improved);
1244 }
1245
1246 static void OTGrammar_modifyRankingscxx . . $ OTGrammar_modifyRankings(7adda7ae88de30c4). (OTGrammar me, integercxx . . $ integer# itab, integercxx . . $ integer# iwinner, integercxx . . $ integer# iadult,
1247 kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
1248 double plasticity, double relativePlasticityNoise, bool warnIfStalled, bool *out_grammarHasChanged)
1249 {
1250 try {
1251 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1252 OTGrammarCandidate winner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner], adult = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iadult];
1253 const double step = learningStepcxx . . $ learningStep(d8e7e0733fa41c87). (plasticity, relativePlasticityNoise);
1254 bool multiplyStepByNumberOfViolations =
1255 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::HARMONIC_GRAMMAR ||
1256 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::LINEAR_OT ||
1257 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::MAXIMUM_ENTROPY ||
1258 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::POSITIVE_HG ||
1259 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG ||
1260 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_MAXIMUM_ENTROPY ||
1261 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::NONNEGATIVE_MAXIMUM_ENTROPY;
1262 if (Melder_debugcxx . . $ Melder_debug. != 0) {
1263 /*
1264 * Perhaps override the standard update rule.
1265 */
1266 if (Melder_debugcxx . . $ Melder_debug. == 26)
1267 multiplyStepByNumberOfViolations = false; // OT-GLA
1268 else if (Melder_debugcxx . . $ Melder_debug. == 27)
1269 multiplyStepByNumberOfViolations = true; // HG-GLA
1270 }
1271 if (updateRule == kOTGrammar_rerankingStrategy::SYMMETRIC_ONE) {
1272 const integercxx . . $ integer# icons = NUMrandomIntegercxx . . $ NUMrandomInteger(d0a0e4c270da0eca). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1273 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1274 double constraintStep = step * constraint -> plasticity;
1275 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1276 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1277 if (adultMarks > winnerMarks) {
1278 if (multiplyStepByNumberOfViolations)
1279 constraintStep *= adultMarks - winnerMarks;
1280 constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1281 if (out_grammarHasChanged)
1282 *out_grammarHasChanged = true;
1283 }
1284 if (winnerMarks > adultMarks) {
1285 if (multiplyStepByNumberOfViolations)
1286 constraintStep *= winnerMarks - adultMarks;
1287 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1288 if (out_grammarHasChanged)
1289 *out_grammarHasChanged = true;
1290 }
1291 } else if (updateRule == kOTGrammar_rerankingStrategy::SYMMETRIC_ALL) {
1292 bool changed = false;
1293 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1294 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1295 double constraintStep = step * constraint -> plasticity;
1296 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1297 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1298 if (adultMarks > winnerMarks) {
1299 if (multiplyStepByNumberOfViolations)
1300 constraintStep *= adultMarks - winnerMarks;
1301 constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1302 changed = true;
1303 }
1304 if (winnerMarks > adultMarks) {
1305 if (multiplyStepByNumberOfViolations)
1306 constraintStep *= winnerMarks - adultMarks;
1307 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1308 changed = true;
1309 }
1310 }
1311 if (changed && mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG)
1312 {
1313 longdoublecxx . . $ longdouble# sumOfWeights = 0.0;
1314 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1315 sumOfWeights += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
1316 const double averageWeight = (double) sumOfWeights / mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints;
1317 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1318 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking -= averageWeight;
1319 }
1320 if (out_grammarHasChanged)
1321 *out_grammarHasChanged = changed;
1322 } else if (updateRule == kOTGrammar_rerankingStrategy::SYMMETRIC_ALL_SKIPPABLE) {
1323 bool changed = false;
1324 integercxx . . $ integer# winningConstraints = 0, adultConstraints = 0;
1325 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1326 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1327 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1328 if (adultMarks > winnerMarks)
1329 adultConstraints ++;
1330 if (winnerMarks > adultMarks)
1331 winningConstraints ++;
1332 }
1333 if (winningConstraints != 0) for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1334 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1335 double constraintStep = step * constraint -> plasticity;
1336 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1337 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1338 if (adultMarks > winnerMarks) {
1339 if (multiplyStepByNumberOfViolations)
1340 constraintStep *= adultMarks - winnerMarks;
1341 constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1342 changed = true;
1343 }
1344 if (winnerMarks > adultMarks) {
1345 if (multiplyStepByNumberOfViolations)
1346 constraintStep *= winnerMarks - adultMarks;
1347 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1348 changed = true;
1349 }
1350 }
1351 if (changed && mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG) {
1352 longdoublecxx . . $ longdouble# sumOfWeights = 0.0;
1353 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1354 sumOfWeights += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
1355 const double averageWeight = (double) sumOfWeights / mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints;
1356 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1357 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking -= averageWeight;
1358 }
1359 if (out_grammarHasChanged)
1360 *out_grammarHasChanged = changed;
1361 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_UNCANCELLED) {
1362 integercxx . . $ integer# winningConstraints = 0, adultConstraints = 0;
1363 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1364 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1365 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1366 if (adultMarks > winnerMarks)
1367 adultConstraints ++;
1368 if (winnerMarks > adultMarks)
1369 winningConstraints ++;
1370 }
1371 if (winningConstraints != 0) for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1372 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1373 double constraintStep = step * constraint -> plasticity;
1374 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1375 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1376 if (adultMarks > winnerMarks) {
1377 if (multiplyStepByNumberOfViolations)
1378 constraintStep *= adultMarks - winnerMarks;
1379 constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / adultConstraints;
1380 //constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * my leak) * winningConstraints;
1381 if (out_grammarHasChanged)
1382 *out_grammarHasChanged = true;
1383 }
1384 if (winnerMarks > adultMarks) {
1385 if (multiplyStepByNumberOfViolations)
1386 constraintStep *= winnerMarks - adultMarks;
1387 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / winningConstraints;
1388 //constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * my leak) * adultConstraints;
1389 if (out_grammarHasChanged)
1390 *out_grammarHasChanged = true;
1391 }
1392 }
1393 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_ALL) {
1394 integercxx . . $ integer# winningConstraints = 0, adultConstraints = 0;
1395 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1396 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1397 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1398 if (adultMarks > 0)
1399 adultConstraints ++;
1400 if (winnerMarks > 0)
1401 winningConstraints ++;
1402 }
1403 if (winningConstraints != 0) for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1404 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1405 double constraintStep = step * constraint -> plasticity;
1406 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1407 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1408 if (adultMarks > 0) {
1409 if (multiplyStepByNumberOfViolations)
1410 constraintStep *= adultMarks /*- winnerMarks*/;
1411 constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / adultConstraints;
1412 if (out_grammarHasChanged)
1413 *out_grammarHasChanged = true;
1414 }
1415 if (winnerMarks > 0) {
1416 if (multiplyStepByNumberOfViolations)
1417 constraintStep *= winnerMarks /*- adultMarks*/;
1418 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / winningConstraints;
1419 if (out_grammarHasChanged)
1420 *out_grammarHasChanged = true;
1421 }
1422 }
1423 } else if (updateRule == kOTGrammar_rerankingStrategy::EDCD || updateRule == kOTGrammar_rerankingStrategy::EDCD_WITH_VACATION) {
1424 /*
1425 Determine the crucial winner mark.
1426 */
1427 double pivotRanking;
1428 bool equivalent = true;
1429 integercxx . . $ integer# icons = 1;
1430 for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1431 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, therefore indirect
1432 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1433 if (adultMarks < winnerMarks)
1434 break;
1435 if (adultMarks > winnerMarks)
1436 equivalent = false;
1437 }
1438 if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) { // completed the loop?
1439 if (warnIfStalled && ! equivalent)
1440 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Correct output is harmonically bounded (by having strict superset violations as compared to the learner's output)! EDCD stalls.\n"
1441 U"Input: ", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nCorrect output: ", adult -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nLearner's output: ", winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1442 return; // Tesar & Smolensky (2000: 67): "stopped dead in its tracks"
1443 }
1444 /*
1445 Determine the stratum into which some constraints will be demoted.
1446 */
1447 pivotRanking = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. ranking;
1448 if (updateRule == kOTGrammar_rerankingStrategy::EDCD_WITH_VACATION) {
1449 integercxx . . $ integer# numberOfConstraintsToDemote = 0;
1450 for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1451 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1452 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1453 if (adultMarks > winnerMarks) {
1454 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1455 if (constraint -> ranking >= pivotRanking)
1456 numberOfConstraintsToDemote += 1;
1457 }
1458 }
1459 if (numberOfConstraintsToDemote > 0) {
1460 for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1461 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1462 if (constraint -> ranking < pivotRanking) {
1463 constraint -> ranking -= numberOfConstraintsToDemote * step * constraint -> plasticity;
1464 if (out_grammarHasChanged)
1465 *out_grammarHasChanged = true;
1466 }
1467 }
1468 }
1469 }
1470 /*
1471 Demote all the uniquely violated constraints in the adult form
1472 that have rankings not lower than the pivot.
1473 */
1474 for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1475 integercxx . . $ integer# numberOfConstraintsDemoted = 0;
1476 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // for the vacation version, the order is important, therefore indirect
1477 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1478 if (adultMarks > winnerMarks) {
1479 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1480 const double constraintStep = step * constraint -> plasticity;
1481 if (constraint -> ranking >= pivotRanking) {
1482 numberOfConstraintsDemoted += 1;
1483 constraint -> ranking = pivotRanking - numberOfConstraintsDemoted * constraintStep; // this preserves the order of the demotees
1484 if (out_grammarHasChanged)
1485 *out_grammarHasChanged = true;
1486 }
1487 }
1488 }
1489 } else if (updateRule == kOTGrammar_rerankingStrategy::DEMOTION_ONLY) {
1490 /*
1491 Determine the crucial adult mark.
1492 */
1493 integercxx . . $ integer# crucialAdultMark;
1494 OTGrammarConstraint offendingConstraint;
1495 integercxx . . $ integer# icons = 1;
1496 for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1497 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, so we indirect
1498 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1499 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. tiedToTheRight)
1500 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints.");
1501 if (adultMarks < winnerMarks)
1502 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Adult form wins! Should never happen.");
1503 if (adultMarks > winnerMarks)
1504 break;
1505 }
1506 if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) // completed the loop?
1507 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Adult form equals correct candidate.");
1508 crucialAdultMark = icons;
1509 /*
1510 Demote the highest uniquely violated constraint in the adult form.
1511 */
1512 offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialAdultMark]];
1513 double constraintStep = step * offendingConstraint -> plasticity;
1514 offendingConstraint -> ranking -= constraintStep;
1515 if (out_grammarHasChanged)
1516 *out_grammarHasChanged = true;
1517 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_ALL_UP_HIGHEST_DOWN) {
1518 integercxx . . $ integer# numberOfUp = 0;
1519 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1520 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1521 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1522 if (winnerMarks > adultMarks)
1523 numberOfUp ++;
1524 }
1525 if (numberOfUp > 0) {
1526 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1527 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1528 double constraintStep = step * constraint -> plasticity;
1529 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1530 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1531 if (winnerMarks > adultMarks) {
1532 if (multiplyStepByNumberOfViolations)
1533 constraintStep *= winnerMarks - adultMarks;
1534 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / numberOfUp;
1535 if (out_grammarHasChanged)
1536 *out_grammarHasChanged = true;
1537 }
1538 }
1539 integercxx . . $ integer# winnerMarks = 0, adultMarks = 0;
1540 integercxx . . $ integer# icons = 1;
1541 for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1542 winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, therefore indirect
1543 adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1544 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. tiedToTheRight)
1545 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints.");
1546 if (adultMarks < winnerMarks)
1547 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Adult form wins! Should never happen.");
1548 if (adultMarks > winnerMarks) break;
1549 }
1550 if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) // completed the loop?
1551 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Adult form equals correct candidate.");
1552 const integercxx . . $ integer# crucialAdultMark = icons;
1553 /*
1554 Demote the highest uniquely violated constraint in the adult form.
1555 */
1556 const OTGrammarConstraint offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialAdultMark]];
1557 double constraintStep = step * offendingConstraint -> plasticity;
1558 if (multiplyStepByNumberOfViolations)
1559 constraintStep *= winnerMarks - adultMarks;
1560 offendingConstraint -> ranking -= /*numberOfUp **/ constraintStep * (1.0 - offendingConstraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1561 if (out_grammarHasChanged)
1562 *out_grammarHasChanged = true;
1563 }
1564 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_ALL_UP_HIGHEST_DOWN_2012) {
1565 integercxx . . $ integer# numberOfUp = 0;
1566 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1567 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1568 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1569 if (winnerMarks > adultMarks)
1570 numberOfUp ++;
1571 }
1572 if (numberOfUp > 0) {
1573 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1574 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1575 double constraintStep = step * constraint -> plasticity;
1576 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1577 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1578 if (winnerMarks > adultMarks) {
1579 if (multiplyStepByNumberOfViolations)
1580 constraintStep *= winnerMarks - adultMarks;
1581 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / (numberOfUp + 1);
1582 if (out_grammarHasChanged)
1583 *out_grammarHasChanged = true;
1584 }
1585 }
1586 integercxx . . $ integer# winnerMarks = 0, adultMarks = 0;
1587 integercxx . . $ integer# icons = 1;
1588 for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1589 winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, therefore indirect
1590 adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1591 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. tiedToTheRight)
1592 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints.");
1593 if (adultMarks < winnerMarks)
1594 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Adult form wins! Should never happen.");
1595 if (adultMarks > winnerMarks) break;
1596 }
1597 if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) // completed the loop?
1598 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Adult form equals correct candidate.");
1599 const integercxx . . $ integer# crucialAdultMark = icons;
1600 /*
1601 Demote the highest uniquely violated constraint in the adult form.
1602 */
1603 const OTGrammarConstraint offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialAdultMark]];
1604 double constraintStep = step * offendingConstraint -> plasticity;
1605 if (multiplyStepByNumberOfViolations)
1606 constraintStep *= winnerMarks - adultMarks;
1607 offendingConstraint -> ranking -= /*numberOfUp **/ constraintStep * (1.0 - offendingConstraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1608 if (out_grammarHasChanged)
1609 *out_grammarHasChanged = true;
1610 }
1611 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_ALL_UP_HIGH_DOWN) {
1612 integercxx . . $ integer# numberOfDown = 0, numberOfUp = 0, lowestDemotableConstraint = 0;
1613 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1614 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, therefore indirect
1615 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1616 if (adultMarks < winnerMarks) {
1617 numberOfUp ++;
1618 } else if (adultMarks > winnerMarks) {
1619 if (numberOfUp == 0) {
1620 numberOfDown ++;
1621 lowestDemotableConstraint = icons;
1622 }
1623 }
1624 }
1625 if (warnIfStalled && numberOfDown == 0) {
1626 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Correct output is harmonically bounded (by having strict superset violations as compared to the learner's output)! EDCD stalls.\n"
1627 U"Input: ", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nCorrect output: ", adult -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nLearner's output: ", winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1628 return;
1629 }
1630 if (numberOfUp > 0) {
1631 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1632 const integercxx . . $ integer# constraintIndex = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1633 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]. tiedToTheRight)
1634 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints.");
1635 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex];
1636 double constraintStep = step * constraint -> plasticity;
1637 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; // the order is important, therefore indirect
1638 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex];
1639 if (adultMarks < winnerMarks) {
1640 if (multiplyStepByNumberOfViolations)
1641 constraintStep *= winnerMarks - adultMarks;
1642 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) * numberOfDown / (numberOfUp + 0.0);
1643 } else if (adultMarks > winnerMarks) {
1644 if (icons <= lowestDemotableConstraint) {
1645 if (multiplyStepByNumberOfViolations)
1646 constraintStep *= adultMarks - winnerMarks;
1647 constraint -> ranking -= constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1648 }
1649 }
1650 }
1651 if (out_grammarHasChanged) *out_grammarHasChanged = true;
1652 }
1653 } else if (updateRule == kOTGrammar_rerankingStrategy::WEIGHTED_ALL_UP_HIGH_DOWN_2012) {
1654 integercxx . . $ integer# numberOfDown = 0, numberOfUp = 0, lowestDemotableConstraint = 0;
1655 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1656 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // the order is important, therefore indirect
1657 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1658 if (adultMarks < winnerMarks) {
1659 numberOfUp ++;
1660 } else if (adultMarks > winnerMarks) {
1661 if (numberOfUp == 0) {
1662 numberOfDown ++;
1663 lowestDemotableConstraint = icons;
1664 }
1665 }
1666 }
1667 if (warnIfStalled && numberOfDown == 0) {
1668 Melder_warningcxx . . $ Melder_warning(6298c93241566110). (U"Correct output is harmonically bounded (by having strict superset violations as compared to the learner's output)! EDCD stalls.\n"
1669 U"Input: ", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nCorrect output: ", adult -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nLearner's output: ", winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
1670 return;
1671 }
1672 if (numberOfUp > 0) {
1673 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1674 const integercxx . . $ integer# constraintIndex = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1675 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]. tiedToTheRight)
1676 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints.");
1677 const OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex];
1678 double constraintStep = step * constraint -> plasticity;
1679 const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; // the order is important, therefore indirect
1680 const integercxx . . $ integer# adultMarks = adult -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex];
1681 if (adultMarks < winnerMarks) {
1682 if (multiplyStepByNumberOfViolations)
1683 constraintStep *= winnerMarks - adultMarks;
1684 constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) * numberOfDown / (numberOfUp + 1.0);
1685 } else if (adultMarks > winnerMarks) {
1686 if (icons <= lowestDemotableConstraint) {
1687 if (multiplyStepByNumberOfViolations)
1688 constraintStep *= adultMarks - winnerMarks;
1689 constraint -> ranking -= constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak);
1690 }
1691 }
1692 }
1693 if (out_grammarHasChanged)
1694 *out_grammarHasChanged = true;
1695 }
1696 }
1697 if (honourLocalRankings && mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings)
1698 OTGrammar_honourLocalRankingscxx . . $ OTGrammar_honourLocalRankings(1aa770b9d7841165). (me, plasticity, relativePlasticityNoise, out_grammarHasChanged);
1699 } catch (MelderErrorcxx . . $ MelderError#) {
1700 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": rankings not modified.");
1701 }
1702 }
1703
1704 void OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (OTGrammar me, conststring32cxx . . $ conststring32# input, conststring32cxx . . $ conststring32# adultOutput,
1705 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
1706 double plasticity, double relativePlasticityNoise, bool newDisharmonies, bool warnIfStalled, bool *out_grammarHasChanged)
1707 {
1708 try {
1709 if (newDisharmonies)
1710 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
1711 if (out_grammarHasChanged)
1712 *out_grammarHasChanged = false;
1713
1714 /*
1715 Evaluate the input in the learner's hypothesis.
1716 */
1717 integercxx . . $ integer# itab = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
1718 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1719
1720 /*
1721 Determine the "winner", i.e. the candidate that wins in the learner's grammar
1722 (Tesar & Smolensky call this the "loser").
1723 */
1724 integercxx . . $ integer# iwinner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab);
1725 OTGrammarCandidate winner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner];
1726
1727 /*
1728 Error-driven: compare the adult winner (the correct candidate) and the learner's winner.
1729 */
1730 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), adultOutput))
1731 return; // as far as we know, the grammar is already correct: don't update rankings
1732
1733 /*
1734 Find (perhaps the learner's interpretation of) the adult output in the learner's own tableau
1735 (Tesar & Smolensky call this the "winner").
1736 */
1737 integercxx . . $ integer# iadult = 1;
1738 for (; iadult <= tableau -> numberOfCandidates; iadult ++) {
1739 OTGrammarCandidate cand = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iadult];
1740 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (cand -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), adultOutput))
1741 break;
1742 }
1743 if (iadult > tableau -> numberOfCandidates)
1744 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot generate adult output \"", adultOutput, U"\".");
1745
1746 /*
1747 Now we know that the current hypothesis prefers the (wrong) learner's winner over the (correct) adult output.
1748 The grammar will have to change.
1749 */
1750 OTGrammar_modifyRankingscxx . . $ OTGrammar_modifyRankings(7adda7ae88de30c4). (me, itab, iwinner, iadult, updateRule, honourLocalRankings,
1751 plasticity, relativePlasticityNoise, warnIfStalled, out_grammarHasChanged);
1752 } catch (MelderErrorcxx . . $ MelderError#) {
1753 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not learned from input \"", input, U"\" and adult output \"", adultOutput, U"\".");
1754 }
1755 }
1756
1757 void OTGrammar_learncxx . . $ OTGrammar_learn(3827da1cf6d683c8). (OTGrammar me, Stringscxx . . $ Strings# inputs, Stringscxx . . $ Strings# outputs,
1758 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
1759 double plasticity, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews)
1760 {
1761 if (! inputs)
1762 inputs = outputs;
1763 try {
1764 const integercxx . . $ integer# n = inputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.;
1765 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (outputs -> numberOfStrings == n,
1766 U"Numbers of strings in input and output should be equal.");
1767 for (integercxx . . $ integer# i = 1; i <= n; i ++) {
1768 for (integercxx . . $ integer# ichew = 1; ichew <= numberOfChews; ichew ++)
1769 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, inputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), outputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
1770 evaluationNoise, updateRule, honourLocalRankings,
1771 plasticity, relativePlasticityNoise, true, true, nullptr
1772 );
1773 }
1774 } catch (MelderErrorcxx . . $ MelderError#) {
1775 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not learned from ", inputs, U" (inputs) and ", outputs, U" (outputs).");
1776 }
1777 }
1778
1779 void OTGrammar_PairDistribution_learncxx . . $ OTGrammar_PairDistribution_learn(a19079481669c00d). (OTGrammar me, PairDistributioncxx . . $ PairDistribution# thee,
1780 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
1781 double initialPlasticity, integercxx . . $ integer# replicationsPerPlasticity, double plasticityDecrement,
1782 integercxx . . $ integer# numberOfPlasticities, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews)
1783 {
1784 integercxx . . $ integer# idatum = 0, numberOfData = numberOfPlasticities * replicationsPerPlasticity;
1785 try {
1786 double plasticity = initialPlasticity;
1787 autoMelderMonitorcxx . . $ autoMelderMonitor# monitorcxx . . $ autoMelderMonitor#autoMelderMonitor(ff00d524ab0355ec). (U"Learning with full knowledge...");
1788 for (integercxx . . $ integer# iplasticity = 1; iplasticity <= numberOfPlasticities; iplasticity ++) {
1789 for (integercxx . . $ integer# ireplication = 1; ireplication <= replicationsPerPlasticity; ireplication ++) {
1790 conststring32cxx . . $ conststring32# input, output;
1791 PairDistribution_peekPaircxx . . $ PairDistribution_peekPair(dc3b14082034b9b4). (thee, & input, & output);
1792 ++ idatum;
1793 if (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).() && idatum % (numberOfData / 400 + 1) == 0) {
1794 Graphics_beginMovieFramecxx . . $ Graphics_beginMovieFrame(39e73bcf122a4f1d). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), nullptr);
1795 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0, numberOfData, 50, 150);
1796 for (integercxx . . $ integer# icons = 1; icons <= 14 && icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1797 Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), (double) icons / 14);
1798 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(),
1799 idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking,
1800 idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking + 1.0
1801 );
1802 }
1803 Graphics_endMovieFramecxx . . $ Graphics_endMovieFrame(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0.0);
1804 }
1805 Melder_monitorcxx . . $ Melder_monitor(71ac93a27c32a1fa). ((double) idatum / numberOfData,
1806 U"Processing input-output pair ", idatum,
1807 U" out of ", numberOfData, U": ", input, U" -> ", output
1808 );
1809 for (integercxx . . $ integer# ichew = 1; ichew <= numberOfChews; ichew ++)
1810 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, input, output,
1811 evaluationNoise, updateRule, honourLocalRankings,
1812 plasticity, relativePlasticityNoise, true, true, nullptr
1813 );
1814 }
1815 plasticity *= plasticityDecrement;
1816 }
1817 } catch (MelderErrorcxx . . $ MelderError#) {
1818 if (idatum > 1)
1819 Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"Only ", idatum - 1, U" input-output pairs out of ", numberOfData, U" were processed.");
1820 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": did not complete learning from ", thee, U".");
1821 }
1822 }
1823
1824 static integercxx . . $ integer# PairDistribution_getNumberOfAttestedOutputscxx . . $ PairDistribution_getNumberOfAttestedOutputs(88f929654d2e6522). (PairDistributioncxx . . $ PairDistribution# me, conststring32cxx . . $ conststring32# input, conststring32cxx . . $ conststring32# *out_attestedOutput) {
1825 integercxx . . $ integer# result = 0;
1826 for (integercxx . . $ integer# ipair = 1; ipair <= mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
1827 PairProbabilitycxx . . $ PairProbability# pair = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
1828 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (pair -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), input) && pair -> weightcxx . . $ structPairProbability#weight. > 0.0) {
1829 if (out_attestedOutput)
1830 *out_attestedOutput = pair -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
1831 result ++;
1832 }
1833 }
1834 return result;
1835 }
1836
1837 bool OTGrammar_PairDistribution_findPositiveWeightscxx . . $ OTGrammar_PairDistribution_findPositiveWeights(eaf0cef6ddde00a8). (OTGrammar me, PairDistributioncxx . . $ PairDistribution# thee, double weightFloor, double marginOfSeparation) {
1838 NUMlinprogcxx . . $ NUMlinprog# linprog = nullptr;
1839 try {
1840 bool result = false;
1841 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::HARMONIC_GRAMMAR &&
1842 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::LINEAR_OT &&
1843 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::POSITIVE_HG &&
1844 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::EXPONENTIAL_HG)
1845 {
1846 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"To find positive weights, the decision strategy should be HarmonicGrammar, LinearOT, PositiveHG, or ExponentialHG.");
1847 }
1848 autoINTVECcxx . . $ autoINTVEC# optimalCandidates = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus);
1849 /*
1850 Check that there is exactly one optimal output for each input.
1851 */
1852 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
1853 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1854 conststring32cxx . . $ conststring32# attestedOutput = nullptr;
1855 integercxx . . $ integer# numberOfAttestedOutputs = PairDistribution_getNumberOfAttestedOutputscxx . . $ PairDistribution_getNumberOfAttestedOutputs(88f929654d2e6522). (thee, tab -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & attestedOutput);
1856 if (numberOfAttestedOutputs == 0) {
1857 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Input \"", tab -> input.get(), U"\" has no attested output.");
1858 } else if (numberOfAttestedOutputs > 1) {
1859 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Input \"", tab -> input.get(), U"\" has more than one attested output.");
1860 } else {
1861 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (attestedOutput);
1862 for (integercxx . . $ integer# icand = 1; icand <= tab -> numberOfCandidates; icand ++) {
1863 OTGrammarCandidate cand = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
1864 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (attestedOutput, cand -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()))
1865 optimalCandidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab] = icand;
1866 }
1867 }
1868 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (optimalCandidates [itab] != 0);
1869 }
1870 /*
1871 Create linear programming problem.
1872 */
1873 linprog = NUMlinprog_newcxx . . $ NUMlinprog_new(e45508a6b3e00df1). (false);
1874 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1875 NUMlinprog_addVariablecxx . . $ NUMlinprog_addVariable(4ef4d7bf833ead05). (linprog, weightFloor, undefinedcxx . . $ undefined., 1.0);
1876 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
1877 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1878 const integercxx . . $ integer# ioptimalCandidate = optimalCandidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
1879 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ioptimalCandidate >= 1);
1880 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ioptimalCandidate <= tab -> numberOfCandidates);
1881 OTGrammarCandidate optimalCandidate = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ioptimalCandidate];
1882 for (integercxx . . $ integer# icand = 1; icand <= tab -> numberOfCandidates; icand ++) {
1883 if (icand != ioptimalCandidate) {
1884 OTGrammarCandidate cand = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
1885 NUMlinprog_addConstraintcxx . . $ NUMlinprog_addConstraint(18c4cf8641bea46b). (linprog, marginOfSeparation, undefinedcxx . . $ undefined.);
1886 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
1887 NUMlinprog_addConstraintCoefficientcxx . . $ NUMlinprog_addConstraintCoefficient(c403c649573868f6). (linprog, cand -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] - optimalCandidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]);
1888 }
1889 }
1890 }
1891 NUMlinprog_runcxx . . $ NUMlinprog_run(9ce666dfbc88138b). (linprog);
1892 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1893 const double weighting = NUMlinprog_getPrimalValuecxx . . $ NUMlinprog_getPrimalValue(c683336232228036). (linprog, icons);
1894 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (weighting >= weightFloor);
1895 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony =
1896 mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategy::EXPONENTIAL_HG ? logcxx . . $ log(fee4f1d22bc8e617). (weighting) : weighting;
1897 }
1898 NUMlinprog_deletecxx . . $ NUMlinprog_delete(9ce666dfbc88138b). (linprog);
1899 return result;
1900 } catch (MelderErrorcxx . . $ MelderError#) {
1901 NUMlinprog_deletecxx . . $ NUMlinprog_delete(9ce666dfbc88138b). (linprog);
1902 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": positive weights not found.");
1903 }
1904 }
1905
1906 void OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (OTGrammar me, double ranking) {
1907 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1908 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1909 constraint -> disharmony = constraint -> ranking = ranking;
1910 }
1911 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
1912 }
1913
1914 void OTGrammar_resetToRandomRankingcxx . . $ OTGrammar_resetToRandomRanking(b654a70d7ca48ec1). (OTGrammar me, double mean, double standardDeviation) {
1915 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1916 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1917 constraint -> disharmony = constraint -> ranking = NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (mean, standardDeviation);
1918 }
1919 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
1920 }
1921
1922 void OTGrammar_resetToRandomTotalRankingcxx . . $ OTGrammar_resetToRandomTotalRanking(b654a70d7ca48ec1). (OTGrammar me, double maximumRanking, double rankingDistance) {
1923 /*
1924 First put the constraints in a random order and build a random index.
1925 */
1926 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1927 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1928 constraint -> ranking = 0.0;
1929 }
1930 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, 1.0);
1931 /*
1932 Then use the random index to yield a cascade of rankings.
1933 */
1934 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1935 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
1936 constraint -> disharmony = constraint -> ranking = maximumRanking - (icons - 1) * rankingDistance;
1937 }
1938 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
1939 }
1940
1941 void OTGrammar_setRankingcxx . . $ OTGrammar_setRanking(68a1fc1b7054b6a3). (OTGrammar me, integercxx . . $ integer# constraint, double ranking, double disharmony) {
1942 try {
1943 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint > 0 && constraint <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints,
1944 U"There is no constraint with number ", constraint, U".");
1945 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. ranking = ranking;
1946 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. disharmony = disharmony;
1947 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
1948 } catch (MelderErrorcxx . . $ MelderError#) {
1949 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": ranking of constraint ", constraint, U" not set.");
1950 }
1951 }
1952
1953 void OTGrammar_setConstraintPlasticitycxx . . $ OTGrammar_setConstraintPlasticity(73ee87a426f39261). (OTGrammar me, integercxx . . $ integer# constraint, double plasticity) {
1954 try {
1955 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint > 0 && constraint <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints,
1956 U"There is no constraint with number ", constraint, U".");
1957 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. plasticity = plasticity;
1958 } catch (MelderErrorcxx . . $ MelderError#) {
1959 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": plasticity of constraint ", constraint, U" not set.");
1960 }
1961 }
1962
1963 integercxx . . $ integer# theSaveNumberOfConstraintscxx . . $ theSaveNumberOfConstraints.;
1964 autoINTVECcxx . . $ autoINTVEC# theSaveIndexcxx . . $ theSaveIndex.;
1965 autoVECcxx . . $ autoVEC# theSaveRankingscxx . . $ theSaveRankings., theSaveDisharmoniescxx . . $ theSaveDisharmonies.;
1966 autoBOOLVECcxx . . $ autoBOOLVEC# theSaveTiedToTheLeftcxx . . $ theSaveTiedToTheLeft., theSaveTiedToTheRightcxx . . $ theSaveTiedToTheRight.;
1967 static void OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (OTGrammar me) {
1968 if (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints != theSaveNumberOfConstraintscxx . . $ theSaveNumberOfConstraints.) {
1969 theSaveIndexcxx . . $ theSaveIndex. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1970 theSaveRankingscxx . . $ theSaveRankings. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1971 theSaveDisharmoniescxx . . $ theSaveDisharmonies. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1972 theSaveTiedToTheLeftcxx . . $ theSaveTiedToTheLeft. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_BOOLVECcxx . . $ raw_BOOLVEC(ba622805578e0bb3). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1973 theSaveTiedToTheRightcxx . . $ theSaveTiedToTheRight. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_BOOLVECcxx . . $ raw_BOOLVEC(ba622805578e0bb3). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
1974 theSaveNumberOfConstraintscxx . . $ theSaveNumberOfConstraints. = mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints;
1975 }
1976 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1977 theSaveIndexcxx . . $ theSaveIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1978 theSaveRankingscxx . . $ theSaveRankings. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
1979 theSaveDisharmoniescxx . . $ theSaveDisharmonies. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony;
1980 theSaveTiedToTheLeftcxx . . $ theSaveTiedToTheLeft. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. tiedToTheLeft;
1981 theSaveTiedToTheRightcxx . . $ theSaveTiedToTheRight. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. tiedToTheRight;
1982 }
1983 }
1984 static void OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (OTGrammar me) {
1985 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
1986 mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = theSaveIndexcxx . . $ theSaveIndex. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1987 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking = theSaveRankingscxx . . $ theSaveRankings. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1988 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony = theSaveDisharmoniescxx . . $ theSaveDisharmonies. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1989 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. tiedToTheLeft = theSaveTiedToTheLeftcxx . . $ theSaveTiedToTheLeft. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1990 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. tiedToTheRight = theSaveTiedToTheRightcxx . . $ theSaveTiedToTheRight. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
1991 }
1992 }
1993
1994 void OTGrammar_learnOneFromPartialOutputcxx . . $ OTGrammar_learnOneFromPartialOutput(bf78488c347ea88b). (OTGrammar me, conststring32cxx . . $ conststring32# partialAdultOutput,
1995 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
1996 double plasticity, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews, bool warnIfStalled)
1997 {
1998 try {
1999 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2000 if (numberOfChews > 1 && updateRule == kOTGrammar_rerankingStrategy::EDCD)
2001 OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (me);
2002 integercxx . . $ integer# ichew = 1;
2003 for (; ichew <= numberOfChews; ichew ++) {
2004 integercxx . . $ integer# assumedAdultInputTableau, assumedAdultCandidate;
2005 OTGrammar_getInterpretiveParsecxx . . $ OTGrammar_getInterpretiveParse(c29944d43509464b). (me, partialAdultOutput, & assumedAdultInputTableau, & assumedAdultCandidate);
2006 bool grammarHasChanged = false;
2007 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me,
2008 mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2009 mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultCandidate]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2010 evaluationNoise, updateRule, honourLocalRankings,
2011 plasticity, relativePlasticityNoise, Melder_debugcxx . . $ Melder_debug. == 47, warnIfStalled, & grammarHasChanged
2012 );
2013 if (! grammarHasChanged)
2014 return;
2015 }
2016 if (numberOfChews > 1 && updateRule == kOTGrammar_rerankingStrategy::EDCD && ichew > numberOfChews) {
2017 /*
2018 Is the partial output form grammatical by now?
2019 */
2020 integercxx . . $ integer# assumedAdultInputTableau, assumedAdultCandidate;
2021 OTGrammar_getInterpretiveParsecxx . . $ OTGrammar_getInterpretiveParse(c29944d43509464b). (me, partialAdultOutput, & assumedAdultInputTableau, & assumedAdultCandidate);
2022 const integercxx . . $ integer# ilearnerCandidate = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, assumedAdultInputTableau);
2023 OTGrammarCandidate learnerCandidate = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ilearnerCandidate];
2024 if (! str32equcxx . . $ `melder/melder_str32.h:122:9`! (learnerCandidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2025 mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultCandidate]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()))
2026 { /* Still ungrammatical? */
2027 /*
2028 Backtrack as in Tesar & Smolensky 2000:69.
2029 */
2030 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2031 }
2032 }
2033 } catch (MelderErrorcxx . . $ MelderError#) {
2034 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not learned from partial adult output \"", partialAdultOutput, U"\".");
2035 }
2036 }
2037
2038 static void OTGrammar_learnOneFromPartialOutput_optcxx . . $ OTGrammar_learnOneFromPartialOutput_opt(f3a0dba7bc957b0c). (OTGrammar me, conststring32cxx . . $ conststring32# partialAdultOutput, integercxx . . $ integer# ipartialAdultOutput,
2039 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
2040 double plasticity, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews, bool warnIfStalled,
2041 bool resampleForVirtualProduction, bool compareOnlyPartialOutput, integercxx . . $ integer# resampleForCorrectForm)
2042 {
2043 try {
2044 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2045 if (numberOfChews > 1 && updateRule == kOTGrammar_rerankingStrategy::EDCD)
2046 OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (me);
2047 integercxx . . $ integer# ichew = 1;
2048 for (; ichew <= numberOfChews; ichew ++) {
2049 integercxx . . $ integer# assumedAdultInputTableau, assumedAdultCandidate;
2050 OTGrammar_getInterpretiveParse_optcxx . . $ OTGrammar_getInterpretiveParse_opt(197077f79b5e7fbb). (me, ipartialAdultOutput, & assumedAdultInputTableau, & assumedAdultCandidate);
2051 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau];
2052 OTGrammarCandidate assumedCorrect = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultCandidate];
2053
2054 /*
2055 Determine the "winner", i.e. the candidate that wins in the learner's grammar
2056 (Tesar & Smolensky call this the "loser").
2057 */
2058 if (resampleForVirtualProduction)
2059 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2060 integercxx . . $ integer# iwinner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, assumedAdultInputTableau);
2061 OTGrammarCandidate winner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner];
2062
2063 /*
2064 Error-driven: compare the adult winner (the correct candidate) and the learner's winner.
2065 */
2066 if (compareOnlyPartialOutput) {
2067 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialAdultOutput))
2068 return; // as far as we know, the grammar is already correct: don't update rankings
2069 } else {
2070 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (winner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), assumedCorrect -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()))
2071 return; // as far as we know, the grammar is already correct: don't update rankings
2072 }
2073 if (resampleForCorrectForm) {
2074 integercxx . . $ integer# itry = 1;
2075 for (; itry <= resampleForCorrectForm; itry ++) {
2076 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2077 integercxx . . $ integer# iwinner2 = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, assumedAdultInputTableau);
2078 OTGrammarCandidate winner2 = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner2];
2079 if (compareOnlyPartialOutput) {
2080 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (winner2 -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialAdultOutput)) {
2081 assumedAdultCandidate = iwinner2;
2082 break;
2083 }
2084 } else {
2085 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (winner2 -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), assumedCorrect -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).())) {
2086 assumedAdultCandidate = iwinner2;
2087 break;
2088 }
2089 }
2090 }
2091 if (itry > resampleForCorrectForm)
2092 return; // no match, so bail out
2093 }
2094
2095 /*
2096 Now we know that the current hypothesis prefers the (wrong) learner's winner over the (correct) adult output.
2097 The grammar will have to change.
2098 */
2099 bool grammarHasChanged = false;
2100 OTGrammar_modifyRankingscxx . . $ OTGrammar_modifyRankings(7adda7ae88de30c4). (me, assumedAdultInputTableau, iwinner, assumedAdultCandidate, updateRule, honourLocalRankings,
2101 plasticity, relativePlasticityNoise, warnIfStalled, & grammarHasChanged);
2102 if (! grammarHasChanged)
2103 return;
2104 }
2105 if (numberOfChews > 1 && updateRule == kOTGrammar_rerankingStrategy::EDCD && ichew > numberOfChews) {
2106 /*
2107 Is the partial output form grammatical by now?
2108 */
2109 integercxx . . $ integer# assumedAdultInputTableau, assumedAdultCandidate;
2110 OTGrammar_getInterpretiveParse_optcxx . . $ OTGrammar_getInterpretiveParse_opt(197077f79b5e7fbb). (me, ipartialAdultOutput, & assumedAdultInputTableau, & assumedAdultCandidate);
2111 const integercxx . . $ integer# ilearnerCandidate = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, assumedAdultInputTableau);
2112 OTGrammarCandidate learnerCandidate = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ilearnerCandidate];
2113 if (! str32equcxx . . $ `melder/melder_str32.h:122:9`! (learnerCandidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2114 mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultCandidate]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()))
2115 { /* Still ungrammatical? */
2116 /*
2117 Backtrack as in Tesar & Smolensky 2000:69.
2118 */
2119 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2120 }
2121 }
2122 } catch (MelderErrorcxx . . $ MelderError#) {
2123 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not learned from partial adult output ", partialAdultOutput, U".");
2124 }
2125 }
2126
2127 static autoOTHistorycxx . . $ autoOTHistory# OTGrammar_createHistorycxx . . $ OTGrammar_createHistory(833a5df63d192ad3). (OTGrammar me, integercxx . . $ integer# storeHistoryEvery, integercxx . . $ integer# numberOfData) {
2128 try {
2129 integercxx . . $ integer# numberOfSamplingPoints = numberOfData / storeHistoryEvery; // e.g. 0, 20, 40, ...
2130 autoOTHistorycxx . . $ autoOTHistory# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (OTHistory);
2131 TableOfReal_initcxx . . $ TableOfReal_init(cfadf70b559ed315). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 2 + numberOfSamplingPoints * 2, 1 + mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
2132 TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, U"Datum");
2133 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2134 TableOfReal_setColumnLabelcxx . . $ TableOfReal_setColumnLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), icons + 1, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2135 TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, U"Initial state");
2136 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 0.0;
2137 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2138 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons + 1] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
2139 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
2140 } catch (MelderErrorcxx . . $ MelderError#) {
2141 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": history not created.");
2142 }
2143 }
2144
2145 static void OTGrammar_updateHistorycxx . . $ OTGrammar_updateHistory(91f30eb605b5f7cf). (OTGrammar me, OTHistorycxx . . $ OTHistory# thee, integercxx . . $ integer# storeHistoryEvery, integercxx . . $ integer# datumNumber, conststring32cxx . . $ conststring32# input) {
2146 try {
2147 if (datumNumber % storeHistoryEvery == 0) {
2148 integercxx . . $ integer# rowNumber = 2 * datumNumber / storeHistoryEvery;
2149 TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee, rowNumber, input);
2150 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rowNumber] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = datumNumber;
2151 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rowNumber + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = datumNumber;
2152 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2153 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rowNumber] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons + 1] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony;
2154 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).rowNumber + 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons + 1] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
2155 }
2156 }
2157 } catch (MelderErrorcxx . . $ MelderError#) {
2158 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": history not updated.");
2159 }
2160 }
2161
2162 static void OTGrammar_finalizeHistorycxx . . $ OTGrammar_finalizeHistory(a01ff8fd684a9761). (OTGrammar me, OTHistorycxx . . $ OTHistory# thee, integercxx . . $ integer# datumNumber) {
2163 try {
2164 TableOfReal_setRowLabelcxx . . $ TableOfReal_setRowLabel(7bba53c4f5b398fa). (thee, thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows., U"Final state");
2165 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = datumNumber;
2166 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2167 thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons + 1] = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking;
2168 } catch (MelderErrorcxx . . $ MelderError#) {
2169 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": history not finalized.");
2170 }
2171 }
2172
2173 void OTGrammar_learnFromPartialOutputscxx . . $ OTGrammar_learnFromPartialOutputs(d1f13382b8c2ea65). (OTGrammar me, Stringscxx . . $ Strings# partialOutputs,
2174 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
2175 double plasticity, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews,
2176 integercxx . . $ integer# storeHistoryEvery, autoOTHistorycxx . . $ autoOTHistory# *history_out)
2177 {
2178 try {
2179 autoOTHistorycxx . . $ autoOTHistory# historycxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
2180 if (storeHistoryEvery)
2181 history =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). OTGrammar_createHistorycxx . . $ OTGrammar_createHistory(833a5df63d192ad3). (me, storeHistoryEvery, partialOutputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.);
2182 try {
2183 for (integercxx . . $ integer# idatum = 1; idatum <= partialOutputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.; idatum ++) {
2184 try {
2185 OTGrammar_learnOneFromPartialOutputcxx . . $ OTGrammar_learnOneFromPartialOutput(bf78488c347ea88b). (me, partialOutputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).idatum].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2186 evaluationNoise, updateRule, honourLocalRankings,
2187 plasticity, relativePlasticityNoise, numberOfChews, false);
2188 } catch (MelderErrorcxx . . $ MelderError#) {
2189 if (history)
2190 OTGrammar_updateHistorycxx . . $ OTGrammar_updateHistory(91f30eb605b5f7cf). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, partialOutputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).idatum].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); // so that we can inspect
2191 throw;
2192 }
2193 if (history)
2194 OTGrammar_updateHistorycxx . . $ OTGrammar_updateHistory(91f30eb605b5f7cf). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, partialOutputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).idatum].getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2195 }
2196 if (history)
2197 OTGrammar_finalizeHistorycxx . . $ OTGrammar_finalizeHistory(a01ff8fd684a9761). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), partialOutputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.);
2198 *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
2199 } catch (MelderErrorcxx . . $ MelderError#) {
2200 *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); // so that we can inspect
2201 throw;
2202 }
2203 } catch (MelderErrorcxx . . $ MelderError#) {
2204 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not learned from partial outputs ", partialOutputs, U".");
2205 }
2206 }
2207
2208 static void OTGrammar_opt_deleteOutputMatchingcxx . . $ OTGrammar_opt_deleteOutputMatching(17bef8f582790df). (OTGrammar me) {
2209 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2210 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2211 for (integercxx . . $ integer# icand = 1; icand <= tab -> numberOfCandidates; icand ++) {
2212 OTGrammarCandidate cand = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
2213 cand -> numberOfPotentialPartialOutputsMatching = 0;
2214 cand -> partialOutputMatches. resetcxx . . $ autovector#reset(ced63f7c635d850d).();
2215 }
2216 }
2217 }
2218
2219 static void OTGrammar_Distributions_opt_createOutputMatchingcxx . . $ OTGrammar_Distributions_opt_createOutputMatching(53d5c23304eec8aa). (OTGrammar me, Distributionscxx . . $ Distributions# thee, integercxx . . $ integer# columnNumber) {
2220 try {
2221 if (columnNumber > thycxx . . $ `melder/melder.h:45:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.)
2222 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No column ", columnNumber, U" in Distributions.");
2223 if (thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. < 1)
2224 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No candidates in Distributions.");
2225 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2226 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2227 for (integercxx . . $ integer# icand = 1; icand <= tab -> numberOfCandidates; icand ++) {
2228 OTGrammarCandidate cand = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
2229 cand -> numberOfPotentialPartialOutputsMatching = thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.;
2230 cand -> partialOutputMatches =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). zero_BOOLVECcxx . . $ zero_BOOLVEC(ba622805578e0bb3). (thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.);
2231 }
2232 }
2233 for (integercxx . . $ integer# ipartialOutput = 1; ipartialOutput <= thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; ipartialOutput ++) {
2234 if (thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).ipartialOutput] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).columnNumber] > 0.0) {
2235 conststring32cxx . . $ conststring32# partialOutput = thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ipartialOutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
2236 bool foundPartialOutput = false;
2237 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2238 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2239 for (integercxx . . $ integer# icand = 1; icand <= tab -> numberOfCandidates; icand ++) {
2240 OTGrammarCandidate cand = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
2241 if (str32strcxx . . $ str32str(2de17cd8f7c584a6). (cand -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput)) {
2242 foundPartialOutput = true;
2243 cand -> partialOutputMatches [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipartialOutput] = true;
2244 }
2245 }
2246 }
2247 if (! foundPartialOutput)
2248 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The partial output \"", partialOutput, U"\" does not match any candidate for any input form.");
2249 }
2250 }
2251 } catch (MelderErrorcxx . . $ MelderError#) {
2252 OTGrammar_opt_deleteOutputMatchingcxx . . $ OTGrammar_opt_deleteOutputMatching(17bef8f582790df). (me);
2253 throw;
2254 }
2255 }
2256
2257 void OTGrammar_Distributions_learnFromPartialOutputscxx . . $ OTGrammar_Distributions_learnFromPartialOutputs(6fee105ba7335590). (OTGrammar me, Distributionscxx . . $ Distributions# thee, integercxx . . $ integer# columnNumber,
2258 double evaluationNoise, enum kOTGrammar_rerankingStrategy updateRule, bool honourLocalRankings,
2259 double initialPlasticity, integercxx . . $ integer# replicationsPerPlasticity, double plasticityDecrement,
2260 integercxx . . $ integer# numberOfPlasticities, double relativePlasticityNoise, integercxx . . $ integer# numberOfChews,
2261 integercxx . . $ integer# storeHistoryEvery, autoOTHistorycxx . . $ autoOTHistory# *history_out,
2262 bool resampleForVirtualProduction, bool compareOnlyPartialOutput, integercxx . . $ integer# resampleForCorrectForm)
2263 {
2264 integercxx . . $ integer# idatum = 0;
2265 const integercxx . . $ integer# numberOfData = numberOfPlasticities * replicationsPerPlasticity;
2266 try {
2267 autoOTHistorycxx . . $ autoOTHistory# historycxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).;
2268 OTGrammar_Distributions_opt_createOutputMatchingcxx . . $ OTGrammar_Distributions_opt_createOutputMatching(53d5c23304eec8aa). (me, thee, columnNumber);
2269 autoMelderMonitorcxx . . $ autoMelderMonitor# monitorcxx . . $ autoMelderMonitor#autoMelderMonitor(ff00d524ab0355ec). (U"Learning with limited knowledge...");
2270 if (storeHistoryEvery)
2271 history =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). OTGrammar_createHistorycxx . . $ OTGrammar_createHistory(833a5df63d192ad3). (me, storeHistoryEvery, numberOfData);
2272 try {
2273 double plasticity = initialPlasticity;
2274 for (integercxx . . $ integer# iplasticity = 1; iplasticity <= numberOfPlasticities; iplasticity ++) {
2275 for (integercxx . . $ integer# ireplication = 1; ireplication <= replicationsPerPlasticity; ireplication ++) {
2276 conststring32cxx . . $ conststring32# partialOutput;
2277 integercxx . . $ integer# ipartialOutput;
2278 Distributions_peekcxx . . $ Distributions_peek(70b1239ea03afa). (thee, columnNumber, & partialOutput, & ipartialOutput);
2279 ++ idatum;
2280 if (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).() && idatum % (numberOfData / 400 + 1) == 0) {
2281 Graphics_beginMovieFramecxx . . $ Graphics_beginMovieFrame(39e73bcf122a4f1d). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), nullptr);
2282 Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0, numberOfData, 50.0, 150.0);
2283 for (integercxx . . $ integer# icons = 1; icons <= 14 && icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2284 Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), (double) icons / 14);
2285 Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(),
2286 idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking,
2287 idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking + 10.0
2288 );
2289 }
2290 Graphics_endMovieFramecxx . . $ Graphics_endMovieFrame(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0.0);
2291 }
2292 Melder_monitorcxx . . $ Melder_monitor(71ac93a27c32a1fa). ((double) idatum / numberOfData,
2293 U"Processing partial output ", idatum, U" out of ", numberOfData, U": ",
2294 thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ipartialOutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).()
2295 );
2296 try {
2297 OTGrammar_learnOneFromPartialOutput_optcxx . . $ OTGrammar_learnOneFromPartialOutput_opt(f3a0dba7bc957b0c). (me, partialOutput, ipartialOutput,
2298 evaluationNoise, updateRule, honourLocalRankings,
2299 plasticity, relativePlasticityNoise, numberOfChews, false,
2300 resampleForVirtualProduction, compareOnlyPartialOutput, resampleForCorrectForm
2301 ); // no warning if stalled: RIP form is allowed to be harmonically bounded
2302 } catch (MelderErrorcxx . . $ MelderError#) {
2303 if (history)
2304 OTGrammar_updateHistorycxx . . $ OTGrammar_updateHistory(91f30eb605b5f7cf). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ipartialOutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2305 throw;
2306 }
2307 if (history)
2308 OTGrammar_updateHistorycxx . . $ OTGrammar_updateHistory(91f30eb605b5f7cf). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).ipartialOutput].getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2309 }
2310 plasticity *= plasticityDecrement;
2311 }
2312 if (history)
2313 OTGrammar_finalizeHistorycxx . . $ OTGrammar_finalizeHistory(a01ff8fd684a9761). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), numberOfData);
2314 OTGrammar_opt_deleteOutputMatchingcxx . . $ OTGrammar_opt_deleteOutputMatching(17bef8f582790df). (me);
2315 if (history_out)
2316 *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
2317 } catch (MelderErrorcxx . . $ MelderError#) {
2318 OTGrammar_opt_deleteOutputMatchingcxx . . $ OTGrammar_opt_deleteOutputMatching(17bef8f582790df). (me);
2319 if (history_out)
2320 *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); // so that we can inspect
2321 throw;
2322 }
2323 } catch (MelderErrorcxx . . $ MelderError#) {
2324 if (idatum > 1)
2325 Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"Only ", idatum - 1, U" input-output pairs out of ", numberOfData, U" were processed.");
2326 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": not learned from partial outputs.");
2327 }
2328 }
2329
2330 double OTGrammar_PairDistribution_getFractionCorrectcxx . . $ OTGrammar_PairDistribution_getFractionCorrect(94bcbbbc39507653). (OTGrammar me, PairDistributioncxx . . $ PairDistribution# thee,
2331 double evaluationNoise, integercxx . . $ integer# numberOfInputs)
2332 {
2333 try {
2334 integercxx . . $ integer# numberOfCorrect = 0;
2335 for (integercxx . . $ integer# ireplication = 1; ireplication <= numberOfInputs; ireplication ++) {
2336 conststring32cxx . . $ conststring32# input, adultOutput;
2337 PairDistribution_peekPaircxx . . $ PairDistribution_peekPair(dc3b14082034b9b4). (thee, & input, & adultOutput);
2338 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2339 integercxx . . $ integer# inputTableau = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
2340 const integercxx . . $ integer# ilearnerCandidate = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, inputTableau);
2341 OTGrammarCandidate learnerCandidate = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ilearnerCandidate];
2342 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (learnerCandidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), adultOutput))
2343 numberOfCorrect ++;
2344 }
2345 return (double) numberOfCorrect / numberOfInputs;
2346 } catch (MelderErrorcxx . . $ MelderError#) {
2347 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": fraction correct not computed.");
2348 }
2349 }
2350
2351 integercxx . . $ integer# OTGrammar_PairDistribution_getMinimumNumberCorrectcxx . . $ OTGrammar_PairDistribution_getMinimumNumberCorrect(682fb95bb304ac5f). (OTGrammar me, PairDistributioncxx . . $ PairDistribution# thee,
2352 double evaluationNoise, integercxx . . $ integer# numberOfReplications)
2353 {
2354 try {
2355 integercxx . . $ integer# minimumNumberCorrect = numberOfReplications;
2356 for (integercxx . . $ integer# ipair = 1; ipair <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
2357 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
2358 if (prob -> weightcxx . . $ structPairProbability#weight. > 0.0) {
2359 integercxx . . $ integer# numberOfCorrect = 0;
2360 conststring32cxx . . $ conststring32# input = prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), adultOutput = prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
2361 integercxx . . $ integer# inputTableau = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
2362 for (integercxx . . $ integer# ireplication = 1; ireplication <= numberOfReplications; ireplication ++) {
2363 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2364 const integercxx . . $ integer# ilearnerCandidate = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, inputTableau);
2365 OTGrammarCandidate learnerCandidate = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).inputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ilearnerCandidate];
2366 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (learnerCandidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), adultOutput))
2367 numberOfCorrect ++;
2368 }
2369 if (numberOfCorrect < minimumNumberCorrect)
2370 minimumNumberCorrect = numberOfCorrect;
2371 }
2372 }
2373 return minimumNumberCorrect;
2374 } catch (MelderErrorcxx . . $ MelderError#) {
2375 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": minimum number correct not computed.");
2376 }
2377 }
2378
2379 double OTGrammar_Distributions_getFractionCorrectcxx . . $ OTGrammar_Distributions_getFractionCorrect(6cc4c2aef93c6d6c). (OTGrammar me, Distributionscxx . . $ Distributions# thee, integercxx . . $ integer# columnNumber,
2380 double evaluationNoise, integercxx . . $ integer# numberOfInputs)
2381 {
2382 try {
2383 integercxx . . $ integer# numberOfCorrect = 0;
2384 OTGrammar_Distributions_opt_createOutputMatchingcxx . . $ OTGrammar_Distributions_opt_createOutputMatching(53d5c23304eec8aa). (me, thee, columnNumber);
2385 for (integercxx . . $ integer# ireplication = 1; ireplication <= numberOfInputs; ireplication ++) {
2386 integercxx . . $ integer# ipartialOutput;
2387 Distributions_peekcxx . . $ Distributions_peek(70b1239ea03afa). (thee, columnNumber, nullptr, & ipartialOutput);
2388 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2389 integercxx . . $ integer# assumedAdultInputTableau, assumedAdultCandidate;
2390 OTGrammar_getInterpretiveParse_optcxx . . $ OTGrammar_getInterpretiveParse_opt(197077f79b5e7fbb). (me, ipartialOutput, & assumedAdultInputTableau, & assumedAdultCandidate);
2391 const integercxx . . $ integer# ilearnerCandidate = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, assumedAdultInputTableau);
2392 OTGrammarCandidate learnerCandidate = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ilearnerCandidate];
2393 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (learnerCandidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultInputTableau]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).assumedAdultCandidate]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()))
2394 numberOfCorrect ++;
2395 }
2396 OTGrammar_opt_deleteOutputMatchingcxx . . $ OTGrammar_opt_deleteOutputMatching(17bef8f582790df). (me);
2397 return (double) numberOfCorrect / numberOfInputs;
2398 } catch (MelderErrorcxx . . $ MelderError#) {
2399 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": fraction correct not computed.");
2400 }
2401 }
2402
2403 void OTGrammar_removeConstraintcxx . . $ OTGrammar_removeConstraint(90425b6eb4fa5279). (OTGrammar me, conststring32cxx . . $ conststring32# constraintName) {
2404 try {
2405 integercxx . . $ integer# removed = 0;
2406 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints > 1,
2407 U"Cannot remove last remaining constraint.");
2408
2409 /*
2410 Look for the constraint to be removed.
2411 */
2412 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2413 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
2414 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), constraintName)) {
2415 removed = icons;
2416 break;
2417 }
2418 }
2419 if (removed == 0)
2420 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No such constraint.");
2421 /*
2422 Remove the constraint while reusing the memory space.
2423 */
2424 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).removed]. destroy ();
2425 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! mycxx . . $ `melder/melder.h:44:9`! constraints [removed]. name);
2426 mycxx . . $ `melder/melder.h:44:9`! constraints. removecxx . . $ autovector#remove(1624ee8275b10bda). (removed);
2427 mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints -= 1; // maintain invariant
2428 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints == mycxx . . $ `melder/melder.h:44:9`! constraints.size);
2429 /*
2430 Remove or shift fixed rankings.
2431 */
2432 for (integercxx . . $ integer# ifixed = mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; ifixed > 0; ifixed --) {
2433 OTGrammarFixedRanking fixed = & mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixed];
2434 if (fixed -> higher == removed || fixed -> lower == removed) {
2435 /*
2436 Remove fixed ranking.
2437 */
2438 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixed]. destroy();
2439 mycxx . . $ `melder/melder.h:44:9`! fixedRankings. removecxx . . $ autovector#remove(1624ee8275b10bda). (ifixed);
2440 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings -= 1; // maintain invariant
2441 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings == mycxx . . $ `melder/melder.h:44:9`! fixedRankings.size);
2442 } else {
2443 /*
2444 Shift fixed ranking.
2445 */
2446 if (fixed -> higher > removed)
2447 fixed -> higher -= 1;
2448 if (fixed -> lower > removed)
2449 fixed -> lower -= 1;
2450 }
2451 }
2452 /*
2453 Shift tableau rows.
2454 */
2455 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2456 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2457 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
2458 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
2459 candidate -> marks. removecxx . . $ autovector#remove(1624ee8275b10bda). (removed);
2460 candidate -> numberOfConstraints -= 1; // maintain invariant
2461 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate -> numberOfConstraints == candidate -> marks.size);
2462 }
2463 }
2464 /*
2465 Rebuild index.
2466 */
2467 mycxx . . $ `melder/melder.h:44:9`! index. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
2468 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2469 mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = icons;
2470 OTGrammar_sortcxx . . $ OTGrammar_sort(17bef8f582790df). (me);
2471 } catch (MelderErrorcxx . . $ MelderError#) {
2472 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": constraint \"", constraintName, U"\" not removed.");
2473 }
2474 }
2475
2476 static void OTGrammarTableau_removeCandidate_unstrippedcxx . . $ OTGrammarTableau_removeCandidate_unstripped(9698e919b740b73f). (OTGrammarTableau me, integercxx . . $ integer# candidateNumber) {
2477 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidateNumber >= 1);
2478 if (candidateNumber > mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates)
2479 Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"icand ", candidateNumber, U", ncand ", mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates);
2480
2481 mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).candidateNumber]. destroy ();
2482 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (! mycxx . . $ `melder/melder.h:44:9`! candidates [candidateNumber]. output); // check leak
2483 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! candidates [candidateNumber]. marks.size == 0);
2484 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! candidates [candidateNumber]. marks.cells == nullptr); // check leak
2485 mycxx . . $ `melder/melder.h:44:9`! candidates. removecxx . . $ autovector#remove(1624ee8275b10bda). (candidateNumber);
2486 mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates -= 1; // maintain invariant
2487 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates == mycxx . . $ `melder/melder.h:44:9`! candidates.size);
2488 }
2489
2490 static bool OTGrammarTableau_isHarmonicallyBoundedcxx . . $ OTGrammarTableau_isHarmonicallyBounded(fc577e3ccf42e362). (OTGrammarTableau me, integercxx . . $ integer# icand, integercxx . . $ integer# jcand) {
2491 OTGrammarCandidate candi = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand], candj = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcand];
2492 bool equal = true;
2493 if (icand == jcand)
2494 return false;
2495 for (integercxx . . $ integer# icons = 1; icons <= candi -> numberOfConstraints; icons ++) {
2496 if (candi -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] < candj -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons])
2497 return false;
2498 if (candi -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] > candj -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons])
2499 equal = false;
2500 }
2501 return ! equal;
2502 }
2503
2504 static bool OTGrammarTableau_candidateIsPossibleWinnercxx . . $ OTGrammarTableau_candidateIsPossibleWinner(f38c237485a6e739). (OTGrammar me, integercxx . . $ integer# itab, integercxx . . $ integer# icand) {
2505 OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (me);
2506 try {
2507 OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (me, 100.0);
2508 for (;;) {
2509 bool grammarHasChanged = false;
2510 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab]. candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2511 1e-3, kOTGrammar_rerankingStrategy::EDCD, false, 1.0, 0.0, true, true, & grammarHasChanged);
2512 if (! grammarHasChanged) {
2513 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2514 return true;
2515 }
2516 double previousStratum = 101.0;
2517 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, 0.0);
2518 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2519 const double stratum = mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]. ranking;
2520 #if 0
2521 if (stratum < 50.0 - my numberOfConstraints) {
2522 OTGrammar_restore (me);
2523 return false; // we detected a tumble
2524 }
2525 #else
2526 if (stratum < previousStratum) {
2527 if (stratum < previousStratum - 1.0) {
2528 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2529 return false; // we detected a vacated stratum
2530 }
2531 previousStratum = stratum;
2532 }
2533 #endif
2534 }
2535 }
2536 } catch (MelderErrorcxx . . $ MelderError#) {
2537 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me); // strong exception guarantee
2538 throw;
2539 }
2540 return false; // cannot occur
2541 }
2542
2543 void OTGrammar_removeHarmonicallyBoundedCandidatescxx . . $ OTGrammar_removeHarmonicallyBoundedCandidates(de1cdd9e0b276ab2). (OTGrammar me, bool singly) {
2544 try {
2545 /*
2546 First, the candidates that are harmonically bounded by one or more single other candidates have to be removed;
2547 otherwise, EDCD will stall.
2548 */
2549 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2550 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2551 for (integercxx . . $ integer# icand = tab -> numberOfCandidates; icand >= 1; icand --) {
2552 for (integercxx . . $ integer# jcand = 1; jcand <= tab -> numberOfCandidates; jcand ++) {
2553 if (OTGrammarTableau_isHarmonicallyBoundedcxx . . $ OTGrammarTableau_isHarmonicallyBounded(fc577e3ccf42e362). (tab, icand, jcand)) {
2554 OTGrammarTableau_removeCandidate_unstrippedcxx . . $ OTGrammarTableau_removeCandidate_unstripped(9698e919b740b73f). (tab, icand);
2555 break;
2556 }
2557 }
2558 }
2559 //tab -> candidates.shrinkToFit();
2560 }
2561 if (! singly) {
2562 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2563 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2564 for (integercxx . . $ integer# icand = tab -> numberOfCandidates; icand >= 1; icand --) {
2565 if (! OTGrammarTableau_candidateIsPossibleWinnercxx . . $ OTGrammarTableau_candidateIsPossibleWinner(f38c237485a6e739). (me, itab, icand))
2566 OTGrammarTableau_removeCandidate_unstrippedcxx . . $ OTGrammarTableau_removeCandidate_unstripped(9698e919b740b73f). (tab, icand);
2567 }
2568 //tab -> candidates.shrinkToFit();
2569 }
2570 }
2571 } catch (MelderErrorcxx . . $ MelderError#) {
2572 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not all harmonically bounded candidates were removed.");
2573 }
2574 }
2575
2576 static bool OTGrammarTableau_candidatesAreDistinguishablecxx . . $ OTGrammarTableau_candidatesAreDistinguishable(17e5a3fe06bc5b2). (constOTGrammarTableau me, integercxx . . $ integer# icand, integercxx . . $ integer# jcand) {
2577 OTGrammarCandidate candi = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand], candj = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcand];
2578 for (integercxx . . $ integer# icons = 1; icons <= candi -> numberOfConstraints; icons ++)
2579 if (candi -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] != candj -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons])
2580 return true;
2581 return false;
2582 }
2583
2584 static bool OTGrammarTableau_areAllCandidatesDistinguishablecxx . . $ OTGrammarTableau_areAllCandidatesDistinguishable(967f12df43e649cc). (constOTGrammarTableau me) {
2585 for (integercxx . . $ integer# icand = 1; icand < mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++)
2586 for (integercxx . . $ integer# jcand = icand + 1; jcand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; jcand ++)
2587 if (! OTGrammarTableau_candidatesAreDistinguishablecxx . . $ OTGrammarTableau_candidatesAreDistinguishable(17e5a3fe06bc5b2). (me, icand, jcand))
2588 return false;
2589 return true;
2590 }
2591
2592 bool OTGrammar_areAllOutputsDistinguishablecxx . . $ OTGrammar_areAllOutputsDistinguishable(62951cbe4b2b5c08). (OTGrammar me) {
2593 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2594 OTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2595 if (! OTGrammarTableau_areAllCandidatesDistinguishablecxx . . $ OTGrammarTableau_areAllCandidatesDistinguishable(967f12df43e649cc). (tab))
2596 return false;
2597 }
2598 return true;
2599 }
2600
2601 autoTablecxx . . $ autoTable# OTGrammar_tabulateEquivalentPairscxx . . $ OTGrammar_tabulateEquivalentPairs(1b61c83392fc114d). (OTGrammar me) {
2602 try {
2603 autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (0, 6 + mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
2604 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"tableau");
2605 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"Tableau");
2606 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"candi");
2607 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"Candi");
2608 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"candj");
2609 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (U"Candj");
2610 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2611 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6 + icons]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2612 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
2613 const constOTGrammarTableau tab = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
2614 for (integercxx . . $ integer# icand = 1; icand < tab -> numberOfCandidates; icand ++) {
2615 for (integercxx . . $ integer# jcand = icand + 1; jcand <= tab -> numberOfCandidates; jcand ++) {
2616 if (! OTGrammarTableau_candidatesAreDistinguishablecxx . . $ OTGrammarTableau_candidatesAreDistinguishable(17e5a3fe06bc5b2). (tab, icand, jcand)) {
2617 Table_appendRowcxx . . $ Table_appendRow(1499cd40562fac4f). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
2618 const integercxx . . $ integer# rowNumber = thycxx . . $ `melder/melder.h:45:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.;
2619 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 1, itab);
2620 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 2, tab -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2621 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 3, icand);
2622 const constOTGrammarCandidate candi = & tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
2623 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 4, candi -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2624 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 5, jcand);
2625 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 6, tab -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcand]. output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2626 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++)
2627 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, 6 + icons, candi -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]);
2628 }
2629 }
2630 }
2631 }
2632 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
2633 } catch (MelderErrorcxx . . $ MelderError#) {
2634 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": equivalent pairs not tabulated.");
2635 }
2636 }
2637
2638 Thing_definecxx . . $ `sys/Thing.h:60:9`! (OTGrammar_List4, Daata) {
2639 // new data:
2640 integercxx . . $ integer# hi1cxx . . $ structOTGrammar_List4#hi1., lo1cxx . . $ structOTGrammar_List4#lo1., hi2cxx . . $ structOTGrammar_List4#hi2., lo2cxx . . $ structOTGrammar_List4#lo2.;
2641 };
2642
2643 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (OTGrammar_List4, Daata, 0);
2644
2645 void OTGrammar_PairDistribution_listObligatoryRankingscxx . . $ OTGrammar_PairDistribution_listObligatoryRankings(df4b34804257e4d4). (OTGrammar me, PairDistributioncxx . . $ PairDistribution# thee) {
2646 /*
2647 Save.
2648 */
2649 integercxx . . $ integer# savedNumberOfFixedRankings = mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings;
2650 autovectorcxx . . $ autovector# <structOTGrammarFixedRanking> savedFixedRankings = mycxx . . $ `melder/melder.h:44:9`! fixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).(); // BUG: is not restored upon throw
2651 OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (me);
2652 try {
2653 integercxx . . $ integer# ipair = 0, npair = mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints * (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints - 1);
2654 integercxx . . $ integer# itrial;
2655 const double evaluationNoise = 1e-9;
2656 /*
2657 Add room for two more fixed rankings.
2658 */
2659 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarFixedRanking> (mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings + 2);
2660 for (integercxx . . $ integer# ifixedRanking = 1; ifixedRanking <= mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; ifixedRanking ++) {
2661 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. higher = savedFixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. higher;
2662 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. lower = savedFixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. lower;
2663 }
2664 /*
2665 Test whether there are rankings at all for these output data.
2666 */
2667 OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (me, 100.0);
2668 for (itrial = 1; itrial <= 40; itrial ++) {
2669 bool grammarHasChangedDuringCycle = false;
2670 OTGrammar_honourLocalRankingscxx . . $ OTGrammar_honourLocalRankings(1aa770b9d7841165). (me, 1.0, 0.0, & grammarHasChangedDuringCycle);
2671 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2672 for (integercxx . . $ integer# iform = 1; iform <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; iform ++) {
2673 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iform];
2674 if (prob -> weightcxx . . $ structPairProbability#weight. > 0.0) {
2675 bool grammarHasChanged = false;
2676 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2677 evaluationNoise, kOTGrammar_rerankingStrategy::EDCD, true /* honour fixed rankings; very important */,
2678 1.0, 0.0, false, true, & grammarHasChanged
2679 );
2680 if (grammarHasChanged)
2681 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2682 grammarHasChangedDuringCycle |= grammarHasChanged;
2683 }
2684 }
2685 if (! grammarHasChangedDuringCycle)
2686 break;
2687 }
2688 if (itrial > 40) {
2689 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"There are no total rankings that generate these input-output pairs.");
2690 throw MelderErrorcxx . . $ MelderError# ();
2691 }
2692 /*
2693 Test learnability of every possible ranked pair.
2694 */
2695 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings ++;
2696 autoBOOLMATcxx . . $ autoBOOLMAT# obligatory = zero_BOOLMATcxx . . $ zero_BOOLMAT(e9a8779cbc949ca0). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints, mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints);
2697 MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). ();
2698 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Finding obligatory rankings.");
2699 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2700 for (integercxx . . $ integer# jcons = 1; jcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; jcons ++) if (icons != jcons) {
2701 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. higher = icons;
2702 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. lower = jcons;
2703 OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (me, 100.0);
2704 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((double) ipair / npair, ipair + 1, U"/", npair, U": Trying ranking ",
2705 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2706 ipair ++;
2707 for (itrial = 1; itrial <= 40; itrial ++) {
2708 bool grammarHasChangedDuringCycle = false;
2709 OTGrammar_honourLocalRankingscxx . . $ OTGrammar_honourLocalRankings(1aa770b9d7841165). (me, 1.0, 0.0, & grammarHasChangedDuringCycle);
2710 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2711 for (integercxx . . $ integer# iform = 1; iform <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; iform ++) {
2712 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iform];
2713 if (prob -> weightcxx . . $ structPairProbability#weight. > 0.0) {
2714 bool grammarHasChanged = false;
2715 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2716 evaluationNoise, kOTGrammar_rerankingStrategy::EDCD, true /* honour fixed rankings; very important */,
2717 1.0, 0.0, false, true, & grammarHasChanged);
2718 if (grammarHasChanged)
2719 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2720 grammarHasChangedDuringCycle |= grammarHasChanged;
2721 }
2722 }
2723 if (! grammarHasChangedDuringCycle)
2724 break;
2725 }
2726 if (itrial > 40) {
2727 obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).jcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons] = true;
2728 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2729 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2730 }
2731 }
2732 }
2733 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings ++;
2734 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.0, U"");
2735 npair = npair * npair;
2736 OrderedOfcxx . . $ OrderedOf#<structOTGrammar_List4cxx . . $ structOTGrammar_List4#> listcxx . . $ OrderedOf#OrderedOf(49f6e7a06ebc5aa8).;
2737 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2738 for (integercxx . . $ integer# jcons = 1; jcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; jcons ++) if (icons != jcons && ! obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).jcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]) {
2739 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings - 1]. higher = icons;
2740 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings - 1]. lower = jcons;
2741 for (integercxx . . $ integer# kcons = icons; kcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; kcons ++) {
2742 for (integercxx . . $ integer# lcons = 1; lcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; lcons ++) if (kcons != lcons && ! obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).lcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).kcons]) {
2743 if (icons == kcons && jcons >= lcons)
2744 continue;
2745 if (icons == lcons && jcons == kcons)
2746 continue;
2747 if (jcons == kcons && obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).lcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons])
2748 continue;
2749 if (icons == lcons && obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).jcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).kcons])
2750 continue;
2751 if (obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).lcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons] && obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).jcons] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).kcons])
2752 continue;
2753 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. higher = kcons;
2754 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. lower = lcons;
2755 OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (me, 100.0);
2756 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((double) ipair / npair, ipair + 1, U"/", npair);
2757 ipair ++;
2758 for (itrial = 1; itrial <= 40; itrial ++) {
2759 bool grammarHasChangedDuringCycle = false;
2760 OTGrammar_honourLocalRankingscxx . . $ OTGrammar_honourLocalRankings(1aa770b9d7841165). (me, 1.0, 0.0, & grammarHasChangedDuringCycle);
2761 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2762 for (integercxx . . $ integer# iform = 1; iform <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; iform ++) {
2763 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iform];
2764 if (prob -> weightcxx . . $ structPairProbability#weight. > 0.0) {
2765 bool grammarHasChanged = false;
2766 OTGrammar_learnOnecxx . . $ OTGrammar_learnOne(ee39fc6cd929bcff). (me, prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(),
2767 evaluationNoise, kOTGrammar_rerankingStrategy::EDCD, true /* honour fixed rankings; very important */,
2768 1.0, 0.0, false, true, & grammarHasChanged);
2769 if (grammarHasChanged)
2770 OTGrammar_newDisharmoniescxx . . $ OTGrammar_newDisharmonies(ebbb2d2a494dd028). (me, evaluationNoise);
2771 grammarHasChangedDuringCycle |= grammarHasChanged;
2772 }
2773 }
2774 if (! grammarHasChangedDuringCycle)
2775 break;
2776 }
2777 if (itrial > 40) {
2778 autoOTGrammar_List4cxx . . $ autoOTGrammar_List4# listElement = Thing_newcxx . . $ `sys/Thing.h:514:9`! (OTGrammar_List4);
2779 listElement ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). hi1cxx . . $ structOTGrammar_List4#hi1. = jcons;
2780 listElement ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lo1cxx . . $ structOTGrammar_List4#lo1. = icons;
2781 listElement ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). hi2cxx . . $ structOTGrammar_List4#hi2. = lcons;
2782 listElement ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). lo2cxx . . $ structOTGrammar_List4#lo2. = kcons;
2783 list. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (listElementcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
2784 }
2785 }
2786 }
2787 }
2788 }
2789 Melder_progresscxx . . $ Melder_progress(ba8836b59fb42830). (1.0);
2790 /*
2791 Improve list.
2792 */
2793 bool improved = true;
2794 while (improved) {
2795 improved = false;
2796 for (integercxx . . $ integer# ilist = 1; ilist <= list.sizecxx . . $ CollectionOf#size.; ilist ++) {
2797 for (integercxx . . $ integer# jlist = 1; jlist <= list.sizecxx . . $ CollectionOf#size.; jlist ++) if (ilist != jlist) {
2798 OTGrammar_List4cxx . . $ OTGrammar_List4# elA = list.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ilist];
2799 OTGrammar_List4cxx . . $ OTGrammar_List4# elB = list.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).jlist];
2800 integercxx . . $ integer# ahi1 = elA -> hi1cxx . . $ structOTGrammar_List4#hi1., alo1 = elA -> lo1cxx . . $ structOTGrammar_List4#lo1., ahi2 = elA -> hi2cxx . . $ structOTGrammar_List4#hi2., alo2 = elA -> lo2cxx . . $ structOTGrammar_List4#lo2.;
2801 integercxx . . $ integer# bhi1 = elB -> hi1cxx . . $ structOTGrammar_List4#hi1., blo1 = elB -> lo1cxx . . $ structOTGrammar_List4#lo1., bhi2 = elB -> hi2cxx . . $ structOTGrammar_List4#hi2., blo2 = elB -> lo2cxx . . $ structOTGrammar_List4#lo2.;
2802 improved |= (ahi1 == bhi1 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).bhi1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ahi1]) && (ahi2 == bhi2 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).bhi2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ahi2]) &&
2803 (alo1 == blo1 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).alo1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).blo1]) && (alo2 == blo2 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).alo2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).blo2]);
2804 improved |= (ahi1 == bhi2 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).bhi2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ahi1]) && (ahi2 == bhi1 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).bhi1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ahi2]) &&
2805 (alo1 == blo2 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).alo1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).blo2]) && (alo2 == blo1 || obligatory [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).alo2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).blo1]);
2806 if (improved) {
2807 list. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (jlist);
2808 break;
2809 }
2810 }
2811 if (improved) break;
2812 }
2813 }
2814 improved = true;
2815 while (improved) {
2816 improved = false;
2817 for (integercxx . . $ integer# ilist = 1; ilist <= list.sizecxx . . $ CollectionOf#size.; ilist ++) {
2818 for (integercxx . . $ integer# jlist = 1; jlist <= list.sizecxx . . $ CollectionOf#size.; jlist ++) if (ilist != jlist) {
2819 OTGrammar_List4cxx . . $ OTGrammar_List4# elA = list.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ilist];
2820 OTGrammar_List4cxx . . $ OTGrammar_List4# elB = list.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).jlist];
2821 integercxx . . $ integer# ahi1 = elA -> hi1cxx . . $ structOTGrammar_List4#hi1., alo1 = elA -> lo1cxx . . $ structOTGrammar_List4#lo1., ahi2 = elA -> hi2cxx . . $ structOTGrammar_List4#hi2., alo2 = elA -> lo2cxx . . $ structOTGrammar_List4#lo2.;
2822 integercxx . . $ integer# bhi1 = elB -> hi1cxx . . $ structOTGrammar_List4#hi1., blo1 = elB -> lo1cxx . . $ structOTGrammar_List4#lo1., bhi2 = elB -> hi2cxx . . $ structOTGrammar_List4#hi2., blo2 = elB -> lo2cxx . . $ structOTGrammar_List4#lo2.;
2823 improved |= ahi1 == bhi1 && alo1 == blo1 && ahi2 == bhi2 && blo2 == bhi1 && alo2 == alo1;
2824 improved |= ahi1 == bhi2 && alo1 == blo2 && ahi2 == bhi1 && blo1 == bhi2 && alo2 == alo1;
2825 improved |= ahi2 == bhi1 && alo2 == blo1 && ahi1 == bhi2 && blo2 == bhi1 && alo1 == alo2;
2826 improved |= ahi2 == bhi2 && alo2 == blo2 && ahi1 == bhi1 && blo1 == bhi2 && alo1 == alo2;
2827 if (improved) {
2828 list. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (jlist);
2829 break;
2830 }
2831 }
2832 if (improved) break;
2833 }
2834 }
2835 for (integercxx . . $ integer# ilist = 1; ilist <= list.sizecxx . . $ CollectionOf#size.; ilist ++) {
2836 OTGrammar_List4cxx . . $ OTGrammar_List4# el = list.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ilist];
2837 MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).el -> hi1cxx . . $ structOTGrammar_List4#hi1.]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).el -> lo1cxx . . $ structOTGrammar_List4#lo1.]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" OR ");
2838 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).el -> hi2cxx . . $ structOTGrammar_List4#hi2.]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).el -> lo2cxx . . $ structOTGrammar_List4#lo2.]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2839 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2840 }
2841 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2842
2843 /*
2844 Restore.
2845 */
2846 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings = savedNumberOfFixedRankings;
2847 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). savedFixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
2848 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2849 } catch (MelderErrorcxx . . $ MelderError#) {
2850 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2851 /*
2852 Restore.
2853 */
2854 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings = savedNumberOfFixedRankings;
2855 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). savedFixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
2856 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2857 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": obligatory rankings not listed.");
2858 }
2859 }
2860
2861 void OTGrammar_Distributions_listObligatoryRankingscxx . . $ OTGrammar_Distributions_listObligatoryRankings(53d5c23304eec8aa). (OTGrammar me, Distributionscxx . . $ Distributions# thee, integercxx . . $ integer# columnNumber) {
2862 /*
2863 Save.
2864 */
2865 autovectorcxx . . $ autovector# <structOTGrammarFixedRanking> savedFixedRankings = mycxx . . $ `melder/melder.h:44:9`! fixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
2866 OTGrammar_savecxx . . $ OTGrammar_save(17bef8f582790df). (me);
2867 try {
2868 integercxx . . $ integer# ipair = 0, npair = mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints * (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints - 1);
2869 /*
2870 Add room for one more fixed ranking.
2871 */
2872 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings ++;
2873 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTGrammarFixedRanking> (mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings);
2874 for (integercxx . . $ integer# ifixedRanking = 1; ifixedRanking < mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; ifixedRanking ++) {
2875 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. higher = savedFixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. higher;
2876 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. lower = savedFixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. lower;
2877 }
2878 /*
2879 Test learnability of every possible ranked pair.
2880 */
2881 MelderInfo_opencxx . . $ MelderInfo_open(49f6e7a06ebc5aa8). ();
2882 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Finding obligatory rankings.");
2883 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
2884 for (integercxx . . $ integer# jcons = 1; jcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; jcons ++) if (icons != jcons) {
2885 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. higher = icons;
2886 mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings]. lower = jcons;
2887 OTGrammar_resetcxx . . $ OTGrammar_reset(ebbb2d2a494dd028). (me, 100.0);
2888 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((double) ipair / npair, ipair + 1, U"/", npair, U": Trying ranking ",
2889 mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2890 ipair ++;
2891 Melder_progressOffcxx . . $ Melder_progressOff(49f6e7a06ebc5aa8). ();
2892 OTGrammar_Distributions_learnFromPartialOutputscxx . . $ OTGrammar_Distributions_learnFromPartialOutputs(6fee105ba7335590). (me, thee, columnNumber,
2893 1e-9, kOTGrammar_rerankingStrategy::EDCD, true /* honour fixed rankings; very important */,
2894 1.0, 1000, 0.0, 1, 0.0, 1, 0, nullptr, false, false, 0);
2895 Melder_progressOncxx . . $ Melder_progressOn(49f6e7a06ebc5aa8). ();
2896 for (integercxx . . $ integer# kcons = 1; kcons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; kcons ++) {
2897 if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).kcons]. ranking < 0.0) {
2898 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).jcons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" >> ", mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2899 break;
2900 }
2901 }
2902 }
2903 }
2904 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2905 /*
2906 Restore.
2907 */
2908 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings --;
2909 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). savedFixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
2910 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2911 } catch (MelderErrorcxx . . $ MelderError#) {
2912 MelderInfo_closecxx . . $ MelderInfo_close(49f6e7a06ebc5aa8). ();
2913 /*
2914 Restore.
2915 */
2916 mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings --;
2917 mycxx . . $ `melder/melder.h:44:9`! fixedRankings =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). savedFixedRankings.movecxx . . $ autovector#move(57d90d7d77dfc011).();
2918 OTGrammar_restorecxx . . $ OTGrammar_restore(17bef8f582790df). (me);
2919 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": obligatory rankings not listed.");
2920 }
2921 }
2922
2923 autoTablecxx . . $ autoTable# OTGrammar_tabulateAllCorrectRankingscxx . . $ OTGrammar_tabulateAllCorrectRankings(c1a5b99a0b12b6a8). (constOTGrammar me, constStringscxx . . $ constStrings# inputs, constStringscxx . . $ constStrings# partialOutputs) {
2924 try {
2925 /*
2926 Check the arguments.
2927 */
2928 if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy != kOTGrammar_decisionStrategy::OPTIMALITY_THEORY)
2929 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Rankings make sense only for Optimality-Theoretic grammars.");
2930 const integercxx . . $ integer# numberOfInputOutputPairs = inputs -> numberOfStringscxx . . $ structStrings#numberOfStrings.;
2931 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (partialOutputs -> numberOfStrings == numberOfInputOutputPairs,
2932 U"The number of input forms (", numberOfInputOutputPairs,
2933 U") should be equal to the number of partial output forms (", partialOutputs -> numberOfStrings, U").");
2934 /*
2935 Compute a big number.
2936 */
2937 const integercxx . . $ integer# numberOfConstraints = mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints;
2938 if (numberOfConstraints > factorial_int53_MAXIMUM_ARGUMENTcxx . . $ factorial_int53_MAXIMUM_ARGUMENT.)
2939 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot handle more than ", factorial_int53_MAXIMUM_ARGUMENT, U" constraints.");
2940 const int64cxx . . $ int64# numberOfPermutations = factorial_int53cxx . . $ factorial_int53. [numberOfConstraints];
2941 /*
2942 Create the result table.
2943 */
2944 autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (0, numberOfConstraints);;
2945 for (integercxx . . $ integer# icons = 1; icons <= numberOfConstraints; icons ++)
2946 thycxx . . $ `melder/melder.h:45:9`! columnHeaderscxx . . $ structTable#columnHeaders. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. labelcxx . . $ structTableColumnHeader#label. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
2947 /*
2948 Cycle many times.
2949 */
2950 autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Tabulating all correct rankings...");
2951 integercxx . . $ integer# rankToConstraintNumber [1 + factorial_int53_MAXIMUM_ARGUMENTcxx . . $ factorial_int53_MAXIMUM_ARGUMENT.];
2952 int64cxx . . $ int64# numberOfCorrectRankings = 0, numberOfPossibleRankings = 0;
2953 for (int64cxx . . $ int64# iperm_base0 = 0; iperm_base0 < numberOfPermutations; iperm_base0 ++) {
2954 if (iperm_base0 % 1000 == 0)
2955 Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). ((iperm_base0 + 0.5) / numberOfPermutations,
2956 U"Testing permutation ", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (iperm_base0), U" out of ", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (numberOfPermutations),
2957 U" (", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (numberOfCorrectRankings), U" correct)"
2958 );
2959 /* mutable cycle */ int64cxx . . $ int64# permleft = iperm_base0;
2960 /*
2961 Initialize to { 1, 2, 3, 4, 5, ... } before permuting.
2962 */
2963 for (integercxx . . $ integer# rank = 1; rank <= numberOfConstraints; rank ++)
2964 rankToConstraintNumber [rank] = rank;
2965 /*
2966 Create the permutation, i.e. put the constraints in a new unique order.
2967 */
2968 for (integercxx . . $ integer# rank = 1; rank < numberOfConstraints; rank ++) {
2969 const int64cxx . . $ int64# fac = factorial_int53cxx . . $ factorial_int53. [numberOfConstraints - rank];
2970 const integercxx . . $ integer# shift = permleft / fac;
2971 permleft = permleft % fac;
2972 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (rankToConstraintNumber [rank], rankToConstraintNumber [rank + shift]);
2973 }
2974 /*
2975 Ignore permutations that violate our fixed rankings.
2976 */
2977 bool fixedRankingsAreHonoured = true;
2978 if (mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings > 0) {
2979 integercxx . . $ integer# ranks [1 + factorial_int53_MAXIMUM_ARGUMENTcxx . . $ factorial_int53_MAXIMUM_ARGUMENT.];
2980 for (integercxx . . $ integer# rank = 1; rank < numberOfConstraints; rank ++)
2981 ranks [rankToConstraintNumber [rank]] = rank; // invert the index
2982 for (integercxx . . $ integer# ifixedRanking = 1; ifixedRanking <= mycxx . . $ `melder/melder.h:44:9`! numberOfFixedRankings; ifixedRanking ++) {
2983 // in the next line, ">" means 'lower ranked than'! (the highest ranking is 1)
2984 if (ranks [mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. higher] > ranks [mycxx . . $ `melder/melder.h:44:9`! fixedRankings [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ifixedRanking]. lower]) {
2985 fixedRankingsAreHonoured = false;
2986 break;
2987 }
2988 }
2989 }
2990 if (! fixedRankingsAreHonoured)
2991 continue;
2992 numberOfPossibleRankings += 1; // we count
2993 /*
2994 Check correctness.
2995 */
2996 bool correct = true;
2997 for (integercxx . . $ integer# ipair = 1; ipair <= numberOfInputOutputPairs; ipair ++) {
2998 const conststring32cxx . . $ conststring32# input = inputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(56be665fc86fc225).ipair].getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
2999 const conststring32cxx . . $ conststring32# partialOutput = partialOutputs -> stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(56be665fc86fc225).ipair].getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
3000 const integercxx . . $ integer# tableauNumber = OTGrammar_getTableaucxx . . $ OTGrammar_getTableau(c62a8df3d6387e3f). (me, input);
3001 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).tableauNumber];
3002 /*
3003 In the case of fully specified desired outputs, there should be exactly one winner.
3004 In the case of partial desired outputs, all winners should share that partial output.
3005 */
3006 /* mutable search */ integercxx . . $ integer# icand_best = 1;
3007 constINTVECcxx . . $ constINTVEC# marks_best = tableaucxx . . $ constvector#constvector(eac9d6ec4c4bfecd). -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
3008 /* mutable count */ integercxx . . $ integer# numberOfBestCandidates = 1;
3009 for (integercxx . . $ integer# icand = 2; icand <= tableau -> numberOfCandidates; icand ++) {
3010 bool candidatesAreEquivalent = true; // no difference found yet; hence, all candidates are still equally good
3011 const constINTVECcxx . . $ constINTVEC# marks_cand = tableaucxx . . $ constvector#constvector(eac9d6ec4c4bfecd). -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
3012 for (integercxx . . $ integer# rank = 1; rank <= numberOfConstraints; rank ++) {
3013 const integercxx . . $ integer# numberOfMarks_best = marks_best [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).rankToConstraintNumber [rank]];
3014 const integercxx . . $ integer# numberOfMarks_cand = marks_cand [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).rankToConstraintNumber [rank]];
3015 if (numberOfMarks_cand != numberOfMarks_best) {
3016 if (numberOfMarks_cand < numberOfMarks_best) {
3017 /*
3018 The new candidate is better than the earlier winner(s).
3019 */
3020 icand_best = icand; // the current candidate is the unique best candidate found so far
3021 marks_best =cxx . . $ constvector#`operator=`(ce36413be79cc4a7). marks_cand;
3022 numberOfBestCandidates = 1;
3023 }
3024 candidatesAreEquivalent = false;
3025 break;
3026 }
3027 }
3028 if (candidatesAreEquivalent) {
3029 /*
3030 The current candidate is equally good as the best found before.
3031 We keep the first winner as "the" winner, and later check that the other winners match the output as well.
3032 */
3033 numberOfBestCandidates += 1;
3034 }
3035 }
3036 if (numberOfBestCandidates == 1) {
3037 const constOTGrammarCandidate singleWinner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand_best];
3038 const bool singleWinnerMatches = !! str32strcxx . . $ str32str(2de17cd8f7c584a6). (singleWinner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput);
3039 if (! singleWinnerMatches) {
3040 correct = false;
3041 break;
3042 }
3043 } else {
3044 /*
3045 The winners should either all match or all not match.
3046 */
3047 const constOTGrammarCandidate firstWinner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand_best];
3048 const bool firstWinnerMatches = !! str32strcxx . . $ str32str(2de17cd8f7c584a6). (firstWinner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput);
3049 for (integercxx . . $ integer# icand = icand_best + 1; icand <= tableau -> numberOfCandidates; icand ++) { // start above icand_best
3050 bool candidatesAreEquivalent = true;
3051 const constINTVECcxx . . $ constINTVEC# marks_cand = tableaucxx . . $ constvector#constvector(eac9d6ec4c4bfecd). -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).();
3052 for (integercxx . . $ integer# icons = 1; icons <= numberOfConstraints; icons ++) {
3053 if (marks_cand [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).icons] != marks_best [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).icons]) { // no need for indirection
3054 candidatesAreEquivalent = false;
3055 break;
3056 }
3057 }
3058 if (candidatesAreEquivalent) {
3059 const constOTGrammarCandidate alternativeWinner = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
3060 const bool alternativeWinnerMatches = !! str32strcxx . . $ str32str(2de17cd8f7c584a6). (alternativeWinner -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), partialOutput);
3061 if (alternativeWinnerMatches != firstWinnerMatches) {
3062 const constOTGrammarCandidate matchingWinner = ( firstWinnerMatches ? firstWinner : alternativeWinner );
3063 const constOTGrammarCandidate nonmatchingWinner = ( firstWinnerMatches ? alternativeWinner : firstWinner );
3064 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Indeterminate grammar: "
3065 "one of the winners (", matchingWinner -> output.get(), U") "
3066 "does match the desired output (", partialOutput, U"), "
3067 "but another winner (", nonmatchingWinner -> output.get(), U") doesn’t."
3068 );
3069 }
3070 }
3071 }
3072 if (! firstWinnerMatches) {
3073 correct = false;
3074 break;
3075 }
3076 }
3077 }
3078 /*
3079 Record the correct ranking in the table.
3080 */
3081 if (correct) {
3082 if (numberOfCorrectRankings == INTEGER_MAXcxx . . $ `melder/melder_int.h:54:9`!) // can occur on a 32-bit machine
3083 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Cannot put more than ", Melder_bigInteger (INTEGER_MAXcxx . . $ `melder/melder_int.h:54:9`!), U" rows in a Table.");
3084 numberOfCorrectRankings += 1;
3085 Table_appendRowcxx . . $ Table_appendRow(1499cd40562fac4f). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
3086 const integercxx . . $ integer# rowNumber = thycxx . . $ `melder/melder.h:45:9`! rowscxx . . $ structTable#rows..sizecxx . . $ CollectionOf#size.;
3087 for (integercxx . . $ integer# rank = 1; rank <= numberOfConstraints; rank ++)
3088 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), rowNumber, rankToConstraintNumber [rank], rank);
3089 }
3090 }
3091 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Number of correct rankings: ", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (numberOfCorrectRankings));
3092 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Number of possible rankings: ", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (numberOfPossibleRankings));
3093 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Number of permutations: ", Melder_bigIntegercxx . . $ Melder_bigInteger(7b348ebc2004441d). (numberOfPermutations));
3094 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
3095 } catch (MelderErrorcxx . . $ MelderError#) {
3096 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": correct rankings not tabulated.");
3097 }
3098 }
3099
3100 static void printConstraintNamescxx . . $ printConstraintNames(f59e18d8c71c8d1e). (OTGrammar me, MelderStringcxx . . $ MelderString# *buffer) {
3101 char32cxx . . $ char32# text [200];
3102 bool secondLine = false;
3103 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
3104 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
3105 if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n')) {
3106 char32cxx . . $ char32# *newLine;
3107 str32cpycxx . . $ str32cpy(6ab934322573b179). (text, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
3108 newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (text, U'\n');
3109 *newLine = U'\0';
3110 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, U"\t", text);
3111 secondLine = true;
3112 } else {
3113 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, U"\t", constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
3114 }
3115 }
3116 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (buffer, U'\n');
3117 if (secondLine) {
3118 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (buffer, U'\t');
3119 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
3120 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
3121 char32cxx . . $ char32# *newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n');
3122 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, U"\t", newLine ? newLine + 1 : U"");
3123 }
3124 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (buffer, U'\n');
3125 }
3126 }
3127
3128 void OTGrammar_writeToHeaderlessSpreadsheetFilecxx . . $ OTGrammar_writeToHeaderlessSpreadsheetFile(b477585282d679e0). (OTGrammar me, MelderFilecxx . . $ MelderFile# file) {
3129 try {
3130 autoMelderStringcxx . . $ autoMelderString# buffercxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).;
3131 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& buffer, U"CONSTRAINTS\t");
3132 printConstraintNamescxx . . $ printConstraintNames(f59e18d8c71c8d1e). (me, & buffer);
3133 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"rankings\t");
3134 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
3135 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
3136 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"\t", constraint -> ranking);
3137 }
3138 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"\ndisharmonies\t");
3139 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
3140 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]];
3141 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"\t", constraint -> disharmony);
3142 }
3143 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& buffer, U'\n');
3144 for (integercxx . . $ integer# itab = 1; itab <= mycxx . . $ `melder/melder.h:44:9`! numberOfTableaus; itab ++) {
3145 OTGrammarTableau tableau = & mycxx . . $ `melder/melder.h:44:9`! tableaus [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itab];
3146 integercxx . . $ integer# winner = OTGrammar_getWinnercxx . . $ OTGrammar_getWinner(7a18ede9c0367db4). (me, itab), numberOfOptimalCandidates = 0;
3147 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints + 1; icons ++)
3148 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& buffer, U'\t');
3149 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"\nINPUT\t", tableau -> input.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
3150 printConstraintNamescxx . . $ printConstraintNames(f59e18d8c71c8d1e). (me, & buffer);
3151 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
3152 if (OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, winner) == 0)
3153 numberOfOptimalCandidates ++;
3154 }
3155 for (integercxx . . $ integer# icand = 1; icand <= tableau -> numberOfCandidates; icand ++) {
3156 OTGrammarCandidate candidate = & tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand];
3157 bool candidateIsOptimal = OTGrammar_compareCandidatescxx . . $ OTGrammar_compareCandidates(75a0bd0abef82b32). (me, itab, icand, itab, winner) == 0;
3158 integercxx . . $ integer# crucialCell = OTGrammar_crucialCellcxx . . $ OTGrammar_crucialCell(d847cb0037bf05). (me, itab, icand, winner, numberOfOptimalCandidates);
3159 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer,
3160 candidateIsOptimal == false ? U"loser" : numberOfOptimalCandidates > 1 ? U"co-winner" : U"winner",
3161 U"\t",
3162 candidate -> output.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
3163 for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) {
3164 integercxx . . $ integer# index = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons];
3165 OTGrammarConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index];
3166 static MelderStringcxx . . $ MelderString# markString;
3167 MelderString_emptycxx . . $ MelderString_empty(93db1090f27e5462). (& markString);
3168 /*
3169 An exclamation mark can be drawn in this cell only if all of the following conditions are met:
3170 1. the candidate is not optimal;
3171 2. the constraint is not tied;
3172 3. this is the crucial cell, i.e. the cells after it are drawn in grey.
3173 */
3174 if (icons == crucialCell && ! candidateIsOptimal && ! constraint -> tiedToTheLeft && ! constraint -> tiedToTheRight) {
3175 const integercxx . . $ integer# winnerMarks = tableau -> candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).winner]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index];
3176 for (integercxx . . $ integer# imark = 1; imark <= winnerMarks + 1; imark ++)
3177 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
3178 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'!');
3179 for (integercxx . . $ integer# imark = winnerMarks + 2; imark <= candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++)
3180 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
3181 } else {
3182 if (! candidateIsOptimal && (constraint -> tiedToTheLeft || constraint -> tiedToTheRight) &&
3183 crucialCell >= 1 && constraint -> disharmony == mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialCell]]. disharmony)
3184 {
3185 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'=');
3186 }
3187 for (integercxx . . $ integer# imark = 1; imark <= candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++)
3188 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& markString, U'*');
3189 }
3190 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U"\t", markString.stringcxx . . $ MelderString#string.);
3191 }
3192 MelderString_appendCharactercxx . . $ MelderString_appendCharacter(f4ab64866cffe712). (& buffer, U'\n');
3193 }
3194 }
3195 MelderFile_writeText_ecxx . . $ MelderFile_writeText_e(4f26204211a3b413). (file, buffer.stringcxx . . $ MelderString#string., Melder_getOutputEncodingcxx . . $ Melder_getOutputEncoding(581d0d572cba43d7). ());
3196 } catch (MelderErrorcxx . . $ MelderError#) {
3197 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not saved to tab-separated file ", file, U".");
3198 }
3199 }
3200
3201 /* End of file OTGrammar.cpp */