| 1 | /* OTMulti.cpp |
| 2 | * |
| 3 | * Copyright (C) 2005-2025 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 2005/06/11 the very beginning of computational bidirectional multi-level OT |
| 21 | * pb 2006/05/16 guarded against cells with many violations |
| 22 | * pb 2006/05/17 draw disharmonies above tableau |
| 23 | * pb 2007/05/19 decision strategies |
| 24 | * pb 2007/08/12 wchar |
| 25 | * pb 2007/10/01 leak and constraint plasticity |
| 26 | * pb 2007/10/01 can write as encoding |
| 27 | * pb 2007/11/14 drawTableau: corrected direction of arrows for positive satisfactions |
| 28 | * pb 2008/04/14 OTMulti_getConstraintIndexFromName |
| 29 | * pb 2009/03/18 modern enums |
| 30 | * pb 2010/06/05 corrected colours |
| 31 | * pb 2011/03/01 multiple update rules; more decision strategies |
| 32 | * pb 2011/03/29 C++ |
| 33 | * pb 2011/04/27 Melder_debug 41 and 42 |
| 34 | * pb 2011/05/15 prevented zero sums of probabilities in MaxEnt |
| 35 | */ |
| 36 | |
| 37 | #include "OTMulti.h"cxx . . $ `<file>/gram/OTMulti.h`/ |
| 38 | |
| 39 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 40 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 41 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 42 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 43 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 44 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 45 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 46 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 47 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 48 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 49 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 50 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 51 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 52 | #include "OTMulti_def.h"cxx . . $ `<file>/gram/OTMulti_def.h`/ |
| 53 | |
| 54 | void structOTMulti :: v1_info () { |
| 55 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 56 | integercxx . . $ integer# numberOfViolations = 0; |
| 57 | for (integercxx . . $ integer# icand = 1; icand <= ourcxx . . $ `melder/melder.h:42:9`! numberOfCandidates; icand ++) |
| 58 | for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++) |
| 59 | numberOfViolations += ourcxx . . $ `melder/melder.h:42:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 60 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Decision strategy: ", kOTGrammar_decisionStrategy_getTextcxx . . $ kOTGrammar_decisionStrategy_getText(1c40b6068c7e53c0). (decisionStrategy)); |
| 61 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of constraints: ", ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints); |
| 62 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of candidates: ", ourcxx . . $ `melder/melder.h:42:9`! numberOfCandidates); |
| 63 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of violation marks: ", numberOfViolations); |
| 64 | } |
| 65 | |
| 66 | void structOTMulti :: v1_writeText (MelderFilecxx . . $ MelderFile# file) { |
| 67 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n<", kOTGrammar_decisionStrategy_getTextcxx . . $ kOTGrammar_decisionStrategy_getText(1c40b6068c7e53c0). (decisionStrategy), |
| 68 | U">\n", leak, U" ! leak\n", ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints, U" constraints"); |
| 69 | for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++) { |
| 70 | OTConstraint constraint = & ourcxx . . $ `melder/melder.h:42:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 71 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n\t\""); |
| 72 | for (const char32cxx . . $ char32# *p = & constraint -> name [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p != U'\0'; p ++) { |
| 73 | if (*p == U'\"') |
| 74 | MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"'); // double any quotes within quotes |
| 75 | MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p); |
| 76 | } |
| 77 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\" ", constraint -> ranking, |
| 78 | U" ", constraint -> disharmony, U" ", constraint -> plasticity); |
| 79 | } |
| 80 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n\n", ourcxx . . $ `melder/melder.h:42:9`! numberOfCandidates, U" candidates"); |
| 81 | for (integercxx . . $ integer# icand = 1; icand <= ourcxx . . $ `melder/melder.h:42:9`! numberOfCandidates; icand ++) { |
| 82 | OTCandidate candidate = & ourcxx . . $ `melder/melder.h:42:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 83 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\n\t\""); |
| 84 | for (const char32cxx . . $ char32# *p = & candidate -> string [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0]; *p != U'\0'; p ++) { |
| 85 | if (*p == U'\"') |
| 86 | MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, U'\"'); // double any quotes within quotes |
| 87 | MelderFile_writeCharactercxx . . $ MelderFile_writeCharacter(a5a5190e8fc7020a). (file, *p); |
| 88 | } |
| 89 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U"\" "); |
| 90 | for (integercxx . . $ integer# icons = 1; icons <= candidate -> numberOfConstraints; icons ++) |
| 91 | MelderFile_writecxx . . $ MelderFile_write(291fa987bb2f47e8). (file, U" ", candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]); |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | void OTMulti_checkIndexcxx . . $ OTMulti_checkIndex(a34eed4b1c1d1bc5). (OTMulti me) { |
| 96 | if (mycxx . . $ `melder/melder.h:44:9`! index.sizecxx . . $ autovector#size. != 0) |
| 97 | return; |
| 98 | mycxx . . $ `melder/melder.h:44:9`! index =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). to_INTVECcxx . . $ to_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints); |
| 99 | OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (me); |
| 100 | } |
| 101 | |
| 102 | void structOTMulti :: v1_readText (MelderReadTextcxx . . $ MelderReadText# text, int formatVersion) { |
| 103 | OTMulti_Parent :: v1_readTextcxx . . $ structDaata#v1_readText(97c85d3b778168ad). (text, formatVersion); |
| 104 | if (formatVersion >= 1) { |
| 105 | try { |
| 106 | decisionStrategy = (kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#) texgete8cxx . . $ texgete8(5d13c7fbeaf5c6ca). (text, (enum_generic_getValuecxx . . $ enum_generic_getValue#) kOTGrammar_decisionStrategy_getValuecxx . . $ kOTGrammar_decisionStrategy_getValue(345d9c4981d3075b).); |
| 107 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 108 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Decision strategy not read."); |
| 109 | } |
| 110 | } |
| 111 | if (formatVersion >= 2) { |
| 112 | try { |
| 113 | leak = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text); |
| 114 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 115 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Trying to read leak."); |
| 116 | } |
| 117 | } |
| 118 | if ((ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text)) < 1) |
| 119 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No constraints."); |
| 120 | ourcxx . . $ `melder/melder.h:42:9`! constraints =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTConstraint> (ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints); |
| 121 | for (integercxx . . $ integer# icons = 1; icons <= ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; icons ++) { |
| 122 | OTConstraint constraint = & ourcxx . . $ `melder/melder.h:42:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 123 | constraint -> name =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (text); |
| 124 | constraint -> ranking = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text); |
| 125 | constraint -> disharmony = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text); |
| 126 | if (formatVersion < 2) { |
| 127 | constraint -> plasticity = 1.0; |
| 128 | } else { |
| 129 | try { |
| 130 | constraint -> plasticity = texgetr64cxx . . $ texgetr64(8233d77bc64f583c). (text); |
| 131 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 132 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Plasticity of constraint ", icons, U" not read."); |
| 133 | } |
| 134 | } |
| 135 | } |
| 136 | if ((numberOfCandidates = texgeti32cxx . . $ texgeti32(2ccfb320b77fcecd). (text)) < 1) |
| 137 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No candidates."); |
| 138 | ourcxx . . $ `melder/melder.h:42:9`! candidates =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structOTCandidate> (numberOfCandidates); |
| 139 | for (integercxx . . $ integer# icand = 1; icand <= numberOfCandidates; icand ++) { |
| 140 | OTCandidate candidate = & ourcxx . . $ `melder/melder.h:42:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 141 | candidate -> string =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). texgetw16cxx . . $ texgetw16(6d8daa32ac6455b9). (text); |
| 142 | candidate -> numberOfConstraints = ourcxx . . $ `melder/melder.h:42:9`! numberOfConstraints; // redundancy, needed for writing binary |
| 143 | candidate -> marks =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (candidate -> numberOfConstraints); |
| 144 | for (integercxx . . $ integer# icons = 1; icons <= candidate -> numberOfConstraints; icons ++) |
| 145 | candidate -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = texgeti16cxx . . $ texgeti16(df2c8a7d80e92f0e). (text); |
| 146 | } |
| 147 | OTMulti_checkIndexcxx . . $ OTMulti_checkIndex(a34eed4b1c1d1bc5). (this); |
| 148 | } |
| 149 | |
| 150 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (OTMulti, Daata, 2); |
| 151 | |
| 152 | integercxx . . $ integer# OTMulti_getConstraintIndexFromNamecxx . . $ OTMulti_getConstraintIndexFromName(71cea15ada5e2dac). (OTMulti me, conststring32cxx . . $ conststring32# name) { |
| 153 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 154 | if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), name)) |
| 155 | return icons; |
| 156 | return 0; |
| 157 | } |
| 158 | |
| 159 | void OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (OTMulti me) { |
| 160 | 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).(), |
| 161 | [me] (integercxx . . $ integer# icons, integercxx . . $ integer# jcons) { |
| 162 | OTConstraint 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]; |
| 163 | /* |
| 164 | Sort primarily by disharmony. |
| 165 | */ |
| 166 | if (ci -> disharmony > cj -> disharmony) |
| 167 | return true; |
| 168 | if (ci -> disharmony < cj -> disharmony) |
| 169 | return false; |
| 170 | /* |
| 171 | Tied constraints are sorted alphabetically. |
| 172 | */ |
| 173 | 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; |
| 174 | } |
| 175 | ); |
| 176 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 177 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 178 | constraint -> tiedToTheLeft = ( icons > 1 && |
| 179 | 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 ); |
| 180 | constraint -> tiedToTheRight = ( icons < mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints && |
| 181 | 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 ); |
| 182 | } |
| 183 | } |
| 184 | |
| 185 | void OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (OTMulti me, double evaluationNoise) { |
| 186 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 187 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 188 | constraint -> disharmony = constraint -> ranking + NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (0, evaluationNoise); |
| 189 | } |
| 190 | OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (me); |
| 191 | } |
| 192 | |
| 193 | int OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (OTMulti me, integercxx . . $ integer# icand1, integercxx . . $ integer# icand2) { |
| 194 | INTVECcxx . . $ INTVEC# marks1 = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand1]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 195 | INTVECcxx . . $ INTVEC# marks2 = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand2]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 196 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 197 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 198 | integercxx . . $ integer# numberOfMarks1 = marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 199 | integercxx . . $ integer# numberOfMarks2 = marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 200 | /* |
| 201 | Count tied constraints as one. |
| 202 | */ |
| 203 | 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) { |
| 204 | icons ++; |
| 205 | numberOfMarks1 += marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 206 | numberOfMarks2 += marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 207 | } |
| 208 | if (numberOfMarks1 < numberOfMarks2) |
| 209 | return -1; // candidate 1 is better than candidate 2 |
| 210 | if (numberOfMarks1 > numberOfMarks2) |
| 211 | return +1; // candidate 2 is better than candidate 1 |
| 212 | } |
| 213 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::HARMONIC_GRAMMARcxx . . $ kOTGrammar_decisionStrategy#HARMONIC_GRAMMAR. || |
| 214 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#MAXIMUM_ENTROPY.) |
| 215 | { |
| 216 | double disharmony1 = 0.0, disharmony2 = 0.0; |
| 217 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 218 | disharmony1 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 219 | disharmony2 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 220 | } |
| 221 | if (disharmony1 < disharmony2) |
| 222 | return -1; // candidate 1 is better than candidate 2 |
| 223 | if (disharmony1 > disharmony2) |
| 224 | return +1; // candidate 2 is better than candidate 1 |
| 225 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::LINEAR_OTcxx . . $ kOTGrammar_decisionStrategy#LINEAR_OT. || mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::NONNEGATIVE_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#NONNEGATIVE_MAXIMUM_ENTROPY.) { |
| 226 | double disharmony1 = 0.0, disharmony2 = 0.0; |
| 227 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 228 | if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony > 0.0) { |
| 229 | disharmony1 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 230 | disharmony2 += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 231 | } |
| 232 | } |
| 233 | if (disharmony1 < disharmony2) |
| 234 | return -1; // candidate 1 is better than candidate 2 |
| 235 | if (disharmony1 > disharmony2) |
| 236 | return +1; // candidate 2 is better than candidate 1 |
| 237 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_HGcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_HG. || |
| 238 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_MAXIMUM_ENTROPY.) |
| 239 | { |
| 240 | double disharmony1 = 0.0, disharmony2 = 0.0; |
| 241 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 242 | disharmony1 += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 243 | disharmony2 += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 244 | } |
| 245 | if (disharmony1 < disharmony2) |
| 246 | return -1; // candidate 1 is better than candidate 2 |
| 247 | if (disharmony1 > disharmony2) |
| 248 | return +1; // candidate 2 is better than candidate 1 |
| 249 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::POSITIVE_HGcxx . . $ kOTGrammar_decisionStrategy#POSITIVE_HG.) { |
| 250 | double disharmony1 = 0.0, disharmony2 = 0.0; |
| 251 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 252 | double constraintDisharmony = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony, 1.0); |
| 253 | disharmony1 += constraintDisharmony * marks1 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 254 | disharmony2 += constraintDisharmony * marks2 [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 255 | } |
| 256 | if (disharmony1 < disharmony2) |
| 257 | return -1; // candidate 1 is better than candidate 2 |
| 258 | if (disharmony1 > disharmony2) |
| 259 | return +1; // candidate 2 is better than candidate 1 |
| 260 | } else { |
| 261 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"Unimplemented decision strategy."); |
| 262 | } |
| 263 | return 0; // none of the comparisons found a difference between the two candidates; hence, they are equally good |
| 264 | } |
| 265 | |
| 266 | int OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (OTMulti me, integercxx . . $ integer# icand, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) { |
| 267 | conststring32cxx . . $ conststring32# string = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 268 | return (form1 [0] == U'\0' || str32strcxx . . $ str32str(2de17cd8f7c584a6). (string, form1)) && (form2 [0] == U'\0' || str32strcxx . . $ str32str(2de17cd8f7c584a6). (string, form2)); |
| 269 | } |
| 270 | |
| 271 | static void _OTMulti_fillInHarmoniescxx . . $ _OTMulti_fillInHarmonies(a640ef2c660cb9bb). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) { |
| 272 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) return; |
| 273 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 274 | OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 275 | INTVECcxx . . $ INTVEC# marks = candidate -> marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 276 | double disharmony = 0.0; |
| 277 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::HARMONIC_GRAMMARcxx . . $ kOTGrammar_decisionStrategy#HARMONIC_GRAMMAR. || |
| 278 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#MAXIMUM_ENTROPY.) |
| 279 | { |
| 280 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 281 | disharmony += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 282 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_HGcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_HG. || |
| 283 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_MAXIMUM_ENTROPY.) |
| 284 | { |
| 285 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 286 | disharmony += expcxx . . $ exp(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony) * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 287 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::LINEAR_OTcxx . . $ kOTGrammar_decisionStrategy#LINEAR_OT. || mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::NONNEGATIVE_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#NONNEGATIVE_MAXIMUM_ENTROPY.) { |
| 288 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 289 | if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony > 0.0) |
| 290 | disharmony += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 291 | } else if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::POSITIVE_HGcxx . . $ kOTGrammar_decisionStrategy#POSITIVE_HG.) { |
| 292 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 293 | double constraintDisharmony = stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. disharmony, 1.0); |
| 294 | disharmony += constraintDisharmony * marks [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 295 | } |
| 296 | } else { |
| 297 | Melder_crashcxx . . $ `melder/melder_error.h:98:9`! (U"_OTMulti_fillInHarmonies: unimplemented decision strategy."); |
| 298 | } |
| 299 | candidate -> harmony = - disharmony; |
| 300 | } |
| 301 | } |
| 302 | |
| 303 | static void _OTMulti_fillInProbabilitiescxx . . $ _OTMulti_fillInProbabilities(a640ef2c660cb9bb). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) { |
| 304 | double maximumHarmony = -1e308; |
| 305 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 306 | OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 307 | if (candidate -> harmony > maximumHarmony) |
| 308 | maximumHarmony = candidate -> harmony; |
| 309 | } |
| 310 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 311 | OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 312 | candidate -> probability = expcxx . . $ exp(fee4f1d22bc8e617). (candidate -> harmony - maximumHarmony); |
| 313 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate -> probability >= 0.0 && candidate -> probability <= 1.0); |
| 314 | } |
| 315 | double sumOfProbabilities = 0.0; |
| 316 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 317 | OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 318 | sumOfProbabilities += candidate -> probability; |
| 319 | } |
| 320 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (sumOfProbabilities > 0.0); // Because at least one of them is 1.0. |
| 321 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 322 | OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 323 | candidate -> probability /= sumOfProbabilities; |
| 324 | } |
| 325 | } |
| 326 | |
| 327 | class MelderError_OTMulti_NoMatchingCandidatecxx . . $ MelderError_OTMulti_NoMatchingCandidate#: public MelderErrorcxx . . $ MelderError# {}; |
| 328 | |
| 329 | integercxx . . $ integer# OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) { |
| 330 | try { |
| 331 | integercxx . . $ integer# icand_best = 0; |
| 332 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#MAXIMUM_ENTROPY. || |
| 333 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_MAXIMUM_ENTROPY. || |
| 334 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::NONNEGATIVE_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#NONNEGATIVE_MAXIMUM_ENTROPY.) |
| 335 | { |
| 336 | _OTMulti_fillInHarmoniescxx . . $ _OTMulti_fillInHarmonies(a640ef2c660cb9bb). (me, form1, form2); |
| 337 | _OTMulti_fillInProbabilitiescxx . . $ _OTMulti_fillInProbabilities(a640ef2c660cb9bb). (me, form1, form2); |
| 338 | const double cutOff = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, 1.0); |
| 339 | longdoublecxx . . $ longdouble# sumOfProbabilities = 0.0; |
| 340 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 341 | sumOfProbabilities += mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. probability; |
| 342 | if (sumOfProbabilities > cutOff) { |
| 343 | icand_best = icand; |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | } else { |
| 348 | integercxx . . $ integer# numberOfBestCandidates = 0; |
| 349 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 350 | if (icand_best == 0) { |
| 351 | icand_best = icand; |
| 352 | numberOfBestCandidates = 1; |
| 353 | } else { |
| 354 | int comparison = OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, icand_best); |
| 355 | if (comparison == -1) { |
| 356 | icand_best = icand; // the current candidate is the unique best candidate found so far |
| 357 | numberOfBestCandidates = 1; |
| 358 | } else if (comparison == 0) { |
| 359 | numberOfBestCandidates += 1; // the current candidate is equally good as the best found before |
| 360 | /* |
| 361 | Give all candidates that are equally good an equal chance to become the winner. |
| 362 | */ |
| 363 | if (Melder_debugcxx . . $ Melder_debug. == 41) |
| 364 | icand_best = icand_best; // keep first |
| 365 | else if (Melder_debugcxx . . $ Melder_debug. == 42) |
| 366 | icand_best = icand; // take last |
| 367 | else if (NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, numberOfBestCandidates) < 1.0) // default: take random |
| 368 | icand_best = icand; |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | } |
| 373 | if (icand_best == 0) { |
| 374 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"The forms ", form1, U" and ", form2, U" do not match any candidate."); |
| 375 | throw MelderError_OTMulti_NoMatchingCandidatecxx . . $ MelderError_OTMulti_NoMatchingCandidate# (); // BUG: NYI |
| 376 | } |
| 377 | return icand_best; |
| 378 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 379 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": winner not determined."); |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | static void OTMulti_modifyRankingscxx . . $ OTMulti_modifyRankings(3b28c6c0e24843da). (OTMulti me, integercxx . . $ integer# iwinner, integercxx . . $ integer# iloser, |
| 384 | kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy# updateRule, |
| 385 | double plasticity, double relativePlasticityNoise) |
| 386 | { |
| 387 | bool *grammarHasChanged = nullptr; // to be implemented |
| 388 | bool warnIfStalled = false; // to be implemented |
| 389 | if (iwinner == iloser) |
| 390 | return; |
| 391 | OTCandidate winner = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner], loser = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iloser]; |
| 392 | const double step = relativePlasticityNoise == 0.0 ? plasticity : NUMrandomGausscxx . . $ NUMrandomGauss(d8e7e0733fa41c87). (plasticity, relativePlasticityNoise * plasticity); |
| 393 | bool multiplyStepByNumberOfViolations = |
| 394 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::HARMONIC_GRAMMARcxx . . $ kOTGrammar_decisionStrategy#HARMONIC_GRAMMAR. || |
| 395 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::LINEAR_OTcxx . . $ kOTGrammar_decisionStrategy#LINEAR_OT. || |
| 396 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#MAXIMUM_ENTROPY. || |
| 397 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::POSITIVE_HGcxx . . $ kOTGrammar_decisionStrategy#POSITIVE_HG. || |
| 398 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_HGcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_HG. || |
| 399 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_MAXIMUM_ENTROPY. || |
| 400 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::NONNEGATIVE_MAXIMUM_ENTROPYcxx . . $ kOTGrammar_decisionStrategy#NONNEGATIVE_MAXIMUM_ENTROPY.; |
| 401 | if (Melder_debugcxx . . $ Melder_debug. != 0) { |
| 402 | /* |
| 403 | Perhaps override the standard update rule. |
| 404 | */ |
| 405 | if (Melder_debugcxx . . $ Melder_debug. == 26) |
| 406 | multiplyStepByNumberOfViolations = false; // OT-GLA |
| 407 | else if (Melder_debugcxx . . $ Melder_debug. == 27) |
| 408 | multiplyStepByNumberOfViolations = true; // HG-GLA |
| 409 | } |
| 410 | if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::SYMMETRIC_ONEcxx . . $ kOTGrammar_rerankingStrategy#SYMMETRIC_ONE.) { |
| 411 | const integercxx . . $ integer# icons = NUMrandomIntegercxx . . $ NUMrandomInteger(d0a0e4c270da0eca). (1, mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints); |
| 412 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 413 | double constraintStep = step * constraint -> plasticity; |
| 414 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 415 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 416 | if (loserMarks > winnerMarks) { |
| 417 | if (multiplyStepByNumberOfViolations) |
| 418 | constraintStep *= loserMarks - winnerMarks; |
| 419 | constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 420 | if (grammarHasChanged) |
| 421 | *grammarHasChanged = true; |
| 422 | } |
| 423 | if (winnerMarks > loserMarks) { |
| 424 | if (multiplyStepByNumberOfViolations) |
| 425 | constraintStep *= winnerMarks - loserMarks; |
| 426 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 427 | if (grammarHasChanged) |
| 428 | *grammarHasChanged = true; |
| 429 | } |
| 430 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::SYMMETRIC_ALLcxx . . $ kOTGrammar_rerankingStrategy#SYMMETRIC_ALL.) { |
| 431 | bool changed = false; |
| 432 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 433 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 434 | double constraintStep = step * constraint -> plasticity; |
| 435 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 436 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 437 | if (loserMarks > winnerMarks) { |
| 438 | if (multiplyStepByNumberOfViolations) |
| 439 | constraintStep *= loserMarks - winnerMarks; |
| 440 | constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 441 | changed = true; |
| 442 | } |
| 443 | if (winnerMarks > loserMarks) { |
| 444 | if (multiplyStepByNumberOfViolations) |
| 445 | constraintStep *= winnerMarks - loserMarks; |
| 446 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 447 | changed = true; |
| 448 | } |
| 449 | } |
| 450 | if (changed && mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_HGcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_HG.) { |
| 451 | longdoublecxx . . $ longdouble# sumOfWeights = 0.0; |
| 452 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 453 | sumOfWeights += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking; |
| 454 | const double averageWeight = double (sumOfWeights) / mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; |
| 455 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 456 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking -= averageWeight; |
| 457 | } |
| 458 | if (grammarHasChanged) |
| 459 | *grammarHasChanged = changed; |
| 460 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::SYMMETRIC_ALL_SKIPPABLEcxx . . $ kOTGrammar_rerankingStrategy#SYMMETRIC_ALL_SKIPPABLE.) { |
| 461 | bool changed = false; |
| 462 | integercxx . . $ integer# winningConstraints = 0, losingConstraints = 0; |
| 463 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 464 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 465 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 466 | if (loserMarks > winnerMarks) |
| 467 | losingConstraints ++; |
| 468 | if (winnerMarks > loserMarks) |
| 469 | winningConstraints ++; |
| 470 | } |
| 471 | if (winningConstraints != 0) for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 472 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 473 | double constraintStep = step * constraint -> plasticity; |
| 474 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 475 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 476 | if (loserMarks > winnerMarks) { |
| 477 | if (multiplyStepByNumberOfViolations) |
| 478 | constraintStep *= loserMarks - winnerMarks; |
| 479 | constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 480 | changed = true; |
| 481 | } |
| 482 | if (winnerMarks > loserMarks) { |
| 483 | if (multiplyStepByNumberOfViolations) |
| 484 | constraintStep *= winnerMarks - loserMarks; |
| 485 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 486 | changed = true; |
| 487 | } |
| 488 | } |
| 489 | if (changed && mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::EXPONENTIAL_HGcxx . . $ kOTGrammar_decisionStrategy#EXPONENTIAL_HG.) { |
| 490 | longdoublecxx . . $ longdouble# sumOfWeights = 0.0; |
| 491 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 492 | sumOfWeights += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking; |
| 493 | const double averageWeight = double (sumOfWeights) / mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; |
| 494 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 495 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking -= averageWeight; |
| 496 | } |
| 497 | if (grammarHasChanged) *grammarHasChanged = changed; |
| 498 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_UNCANCELLEDcxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_UNCANCELLED.) { |
| 499 | integercxx . . $ integer# winningConstraints = 0, losingConstraints = 0; |
| 500 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 501 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 502 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 503 | if (loserMarks > winnerMarks) |
| 504 | losingConstraints ++; |
| 505 | if (winnerMarks > loserMarks) |
| 506 | winningConstraints ++; |
| 507 | } |
| 508 | if (winningConstraints != 0) { |
| 509 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 510 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 511 | double constraintStep = step * constraint -> plasticity; |
| 512 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 513 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 514 | if (loserMarks > winnerMarks) { |
| 515 | if (multiplyStepByNumberOfViolations) |
| 516 | constraintStep *= loserMarks - winnerMarks; |
| 517 | constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / losingConstraints; |
| 518 | //constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * my leak) * winningConstraints; |
| 519 | if (grammarHasChanged) |
| 520 | *grammarHasChanged = true; |
| 521 | } |
| 522 | if (winnerMarks > loserMarks) { |
| 523 | if (multiplyStepByNumberOfViolations) |
| 524 | constraintStep *= winnerMarks - loserMarks; |
| 525 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / winningConstraints; |
| 526 | //constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * my leak) * losingConstraints; |
| 527 | if (grammarHasChanged) |
| 528 | *grammarHasChanged = true; |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_ALLcxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_ALL.) { |
| 533 | integercxx . . $ integer# winningConstraints = 0, losingConstraints = 0; |
| 534 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 535 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 536 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 537 | if (loserMarks > 0) |
| 538 | losingConstraints ++; |
| 539 | if (winnerMarks > 0) |
| 540 | winningConstraints ++; |
| 541 | } |
| 542 | if (winningConstraints != 0) for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 543 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 544 | double constraintStep = step * constraint -> plasticity; |
| 545 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 546 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 547 | if (loserMarks > 0) { |
| 548 | if (multiplyStepByNumberOfViolations) |
| 549 | constraintStep *= loserMarks - winnerMarks; |
| 550 | constraint -> ranking -= constraintStep * (1.0 + constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / losingConstraints; |
| 551 | if (grammarHasChanged) |
| 552 | *grammarHasChanged = true; |
| 553 | } |
| 554 | if (winnerMarks > 0) { |
| 555 | if (multiplyStepByNumberOfViolations) |
| 556 | constraintStep *= winnerMarks - loserMarks; |
| 557 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / winningConstraints; |
| 558 | if (grammarHasChanged) |
| 559 | *grammarHasChanged = true; |
| 560 | } |
| 561 | } |
| 562 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::EDCDcxx . . $ kOTGrammar_rerankingStrategy#EDCD. || updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::EDCD_WITH_VACATIONcxx . . $ kOTGrammar_rerankingStrategy#EDCD_WITH_VACATION.) { |
| 563 | /* |
| 564 | Determine the crucial winner mark. |
| 565 | */ |
| 566 | double pivotRanking; |
| 567 | bool equivalent = true; |
| 568 | integercxx . . $ integer# icons = 1; |
| 569 | for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 570 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // order is important, so indirect |
| 571 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 572 | if (loserMarks < winnerMarks) |
| 573 | break; |
| 574 | if (loserMarks > winnerMarks) |
| 575 | equivalent = false; |
| 576 | } |
| 577 | if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) { // completed the loop? |
| 578 | if (warnIfStalled && ! equivalent) |
| 579 | 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" |
| 580 | U"Correct output: ", loser -> string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\nLearner's output: ", winner -> string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 581 | return; |
| 582 | } |
| 583 | /* |
| 584 | Determine the stratum into which some constraints will be demoted. |
| 585 | */ |
| 586 | 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; |
| 587 | if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::EDCD_WITH_VACATIONcxx . . $ kOTGrammar_rerankingStrategy#EDCD_WITH_VACATION.) { |
| 588 | integercxx . . $ integer# numberOfConstraintsToDemote = 0; |
| 589 | for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 590 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 591 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 592 | if (loserMarks > winnerMarks) { |
| 593 | OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 594 | if (constraint -> ranking >= pivotRanking) |
| 595 | numberOfConstraintsToDemote += 1; |
| 596 | } |
| 597 | } |
| 598 | if (numberOfConstraintsToDemote > 0) { |
| 599 | for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 600 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 601 | if (constraint -> ranking < pivotRanking) { |
| 602 | constraint -> ranking -= numberOfConstraintsToDemote * step * constraint -> plasticity; |
| 603 | if (grammarHasChanged) |
| 604 | *grammarHasChanged = true; |
| 605 | } |
| 606 | } |
| 607 | } |
| 608 | } |
| 609 | /* |
| 610 | Demote all the uniquely violated constraints in the loser |
| 611 | that have rankings not lower than the pivot. |
| 612 | */ |
| 613 | for (icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 614 | integercxx . . $ integer# numberOfConstraintsDemoted = 0; |
| 615 | 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, so indirect |
| 616 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 617 | if (loserMarks > winnerMarks) { |
| 618 | OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 619 | double constraintStep = step * constraint -> plasticity; |
| 620 | if (constraint -> ranking >= pivotRanking) { |
| 621 | numberOfConstraintsDemoted += 1; |
| 622 | constraint -> ranking = pivotRanking - numberOfConstraintsDemoted * constraintStep; // this preserves the order of the demotees |
| 623 | if (grammarHasChanged) |
| 624 | *grammarHasChanged = true; |
| 625 | } |
| 626 | } |
| 627 | } |
| 628 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::DEMOTION_ONLYcxx . . $ kOTGrammar_rerankingStrategy#DEMOTION_ONLY.) { |
| 629 | /* |
| 630 | Determine the crucial loser mark. |
| 631 | */ |
| 632 | integercxx . . $ integer# crucialLoserMark; |
| 633 | OTConstraint offendingConstraint; |
| 634 | integercxx . . $ integer# icons = 1; |
| 635 | for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 636 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // order is important, so indirect |
| 637 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 638 | 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) |
| 639 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints."); |
| 640 | if (loserMarks < winnerMarks) { |
| 641 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 642 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Loser wins! Should never happen."); |
| 643 | } else { |
| 644 | // do nothing; the whole demotion-only idea does not really apply very well to non-OT decision strategies |
| 645 | } |
| 646 | } |
| 647 | if (loserMarks > winnerMarks) |
| 648 | break; |
| 649 | } |
| 650 | if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) { // completed the loop? |
| 651 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 652 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(OTGrammar_step:) Loser equals correct candidate: loser \"", |
| 653 | loser -> string.get(), U"\", winner \"", winner -> string.get(), U"\"."); |
| 654 | } else { |
| 655 | // do nothing |
| 656 | } |
| 657 | } else { |
| 658 | crucialLoserMark = icons; |
| 659 | /* |
| 660 | Demote the highest uniquely violated constraint in the loser. |
| 661 | */ |
| 662 | offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialLoserMark]]; |
| 663 | const double constraintStep = step * offendingConstraint -> plasticity; |
| 664 | offendingConstraint -> ranking -= constraintStep; |
| 665 | if (grammarHasChanged) |
| 666 | *grammarHasChanged = true; |
| 667 | } |
| 668 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_ALL_UP_HIGHEST_DOWNcxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_ALL_UP_HIGHEST_DOWN.) { |
| 669 | bool changed = false; |
| 670 | integercxx . . $ integer# numberOfUp = 0; |
| 671 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 672 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 673 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 674 | if (winnerMarks > loserMarks) |
| 675 | numberOfUp ++; |
| 676 | } |
| 677 | if (numberOfUp > 0) { |
| 678 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 679 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 680 | double constraintStep = step * constraint -> plasticity; |
| 681 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 682 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 683 | if (winnerMarks > loserMarks) { |
| 684 | if (multiplyStepByNumberOfViolations) |
| 685 | constraintStep *= winnerMarks - loserMarks; |
| 686 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / numberOfUp; |
| 687 | } |
| 688 | } |
| 689 | integercxx . . $ integer# winnerMarks = 0, loserMarks = 0; |
| 690 | integercxx . . $ integer# icons = 1; |
| 691 | for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 692 | winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; // order is important, so indirect |
| 693 | loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 694 | 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) |
| 695 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints."); |
| 696 | if (loserMarks < winnerMarks) { |
| 697 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 698 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Loser wins! Should never happen."); |
| 699 | } else { |
| 700 | // do nothing; the whole demotion-only idea does not really apply very well to non-OT decision strategies |
| 701 | } |
| 702 | } |
| 703 | if (loserMarks > winnerMarks) |
| 704 | break; |
| 705 | } |
| 706 | if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) { // completed the loop? |
| 707 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 708 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(OTGrammar_step:) Loser equals correct candidate: loser \"", |
| 709 | loser -> string.get(), U"\", winner \"", winner -> string.get(), U"\"."); |
| 710 | } else { |
| 711 | // do nothing |
| 712 | } |
| 713 | } else { |
| 714 | const integercxx . . $ integer# crucialLoserMark = icons; |
| 715 | /* |
| 716 | Demote the highest uniquely violated constraint in the loser. |
| 717 | */ |
| 718 | const OTConstraint offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialLoserMark]]; |
| 719 | double constraintStep = step * offendingConstraint -> plasticity; |
| 720 | if (multiplyStepByNumberOfViolations) |
| 721 | constraintStep *= winnerMarks - loserMarks; |
| 722 | offendingConstraint -> ranking -= /*numberOfUp **/ constraintStep * (1.0 - offendingConstraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 723 | } |
| 724 | } |
| 725 | if (grammarHasChanged) |
| 726 | *grammarHasChanged = changed; |
| 727 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_ALL_UP_HIGHEST_DOWN_2012cxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_ALL_UP_HIGHEST_DOWN_2012.) { |
| 728 | bool changed = false; |
| 729 | integercxx . . $ integer# numberOfUp = 0; |
| 730 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 731 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 732 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 733 | if (winnerMarks > loserMarks) |
| 734 | numberOfUp ++; |
| 735 | } |
| 736 | if (/*true ||*/ numberOfUp > 0) { |
| 737 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 738 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 739 | double constraintStep = step * constraint -> plasticity; |
| 740 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 741 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 742 | if (winnerMarks > loserMarks) { |
| 743 | if (multiplyStepByNumberOfViolations) |
| 744 | constraintStep *= winnerMarks - loserMarks; |
| 745 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) / (numberOfUp + 1); |
| 746 | } |
| 747 | } |
| 748 | integercxx . . $ integer# winnerMarks = 0, loserMarks = 0; |
| 749 | integercxx . . $ integer# icons = 1; |
| 750 | for (; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 751 | winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; /* Order is important, so indirect. */ |
| 752 | loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 753 | 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) |
| 754 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints."); |
| 755 | if (loserMarks < winnerMarks) { |
| 756 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 757 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning step: Loser wins! Should never happen."); |
| 758 | } else { |
| 759 | // do nothing; the whole demotion-only idea does not really apply very well to non-OT decision strategies |
| 760 | } |
| 761 | } |
| 762 | if (loserMarks > winnerMarks) |
| 763 | break; |
| 764 | } |
| 765 | if (icons > mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints) { // completed the loop? |
| 766 | if (mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 767 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"(OTGrammar_step:) Loser equals correct candidate: loser \"", |
| 768 | loser -> string.get(), U"\", winner \"", winner -> string.get(), U"\"."); |
| 769 | } else { |
| 770 | // do nothing |
| 771 | } |
| 772 | } else { |
| 773 | const integercxx . . $ integer# crucialLoserMark = icons; |
| 774 | /* |
| 775 | Demote the highest uniquely violated constraint in the loser. |
| 776 | */ |
| 777 | const OTConstraint offendingConstraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).crucialLoserMark]]; |
| 778 | double constraintStep = step * offendingConstraint -> plasticity; |
| 779 | if (multiplyStepByNumberOfViolations) |
| 780 | constraintStep *= winnerMarks - loserMarks; |
| 781 | offendingConstraint -> ranking -= /*numberOfUp **/ constraintStep * (1.0 - offendingConstraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 782 | } |
| 783 | } |
| 784 | if (grammarHasChanged) |
| 785 | *grammarHasChanged = changed; |
| 786 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_ALL_UP_HIGH_DOWNcxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_ALL_UP_HIGH_DOWN.) { |
| 787 | integercxx . . $ integer# numberOfDown = 0, numberOfUp = 0, lowestDemotableConstraint = 0; |
| 788 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 789 | 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 |
| 790 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 791 | if (loserMarks < winnerMarks) { |
| 792 | numberOfUp ++; |
| 793 | } else if (loserMarks > winnerMarks) { |
| 794 | if (numberOfUp == 0) { |
| 795 | numberOfDown ++; |
| 796 | lowestDemotableConstraint = icons; |
| 797 | } |
| 798 | } |
| 799 | } |
| 800 | if (numberOfUp > 0) { |
| 801 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 802 | const integercxx . . $ integer# constraintIndex = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 803 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; |
| 804 | double constraintStep = step * constraint -> plasticity; |
| 805 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; // the order is important, therefore indirect |
| 806 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; |
| 807 | if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]. tiedToTheRight) |
| 808 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints."); |
| 809 | if (loserMarks < winnerMarks) { |
| 810 | if (multiplyStepByNumberOfViolations) |
| 811 | constraintStep *= winnerMarks - loserMarks; |
| 812 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) * numberOfDown / (numberOfUp + 0.0); |
| 813 | } else if (loserMarks > winnerMarks) { |
| 814 | if (icons <= lowestDemotableConstraint) { |
| 815 | if (multiplyStepByNumberOfViolations) |
| 816 | constraintStep *= loserMarks - winnerMarks; |
| 817 | constraint -> ranking -= constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 818 | } |
| 819 | } |
| 820 | } |
| 821 | if (grammarHasChanged) |
| 822 | *grammarHasChanged = true; |
| 823 | } |
| 824 | } else if (updateRule == kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy#::WEIGHTED_ALL_UP_HIGH_DOWN_2012cxx . . $ kOTGrammar_rerankingStrategy#WEIGHTED_ALL_UP_HIGH_DOWN_2012.) { |
| 825 | integercxx . . $ integer# numberOfDown = 0, numberOfUp = 0, lowestDemotableConstraint = 0; |
| 826 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 827 | 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 |
| 828 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 829 | if (loserMarks < winnerMarks) { |
| 830 | numberOfUp ++; |
| 831 | } else if (loserMarks > winnerMarks) { |
| 832 | if (numberOfUp == 0) { |
| 833 | numberOfDown ++; |
| 834 | lowestDemotableConstraint = icons; |
| 835 | } |
| 836 | } |
| 837 | } |
| 838 | if (numberOfUp > 0) { |
| 839 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 840 | const integercxx . . $ integer# constraintIndex = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 841 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; |
| 842 | double constraintStep = step * constraint -> plasticity; |
| 843 | const integercxx . . $ integer# winnerMarks = winner -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; // the order is important, therefore indirect |
| 844 | const integercxx . . $ integer# loserMarks = loser -> marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]; |
| 845 | if (mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintIndex]. tiedToTheRight) |
| 846 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Demotion-only learning cannot handle tied constraints."); |
| 847 | if (loserMarks < winnerMarks) { |
| 848 | if (multiplyStepByNumberOfViolations) |
| 849 | constraintStep *= winnerMarks - loserMarks; |
| 850 | constraint -> ranking += constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak) * numberOfDown / (numberOfUp + 1.0); |
| 851 | } else if (loserMarks > winnerMarks) { |
| 852 | if (icons <= lowestDemotableConstraint) { |
| 853 | if (multiplyStepByNumberOfViolations) |
| 854 | constraintStep *= loserMarks - winnerMarks; |
| 855 | constraint -> ranking -= constraintStep * (1.0 - constraint -> ranking * mycxx . . $ `melder/melder.h:44:9`! leak); |
| 856 | } |
| 857 | } |
| 858 | } |
| 859 | if (grammarHasChanged) |
| 860 | *grammarHasChanged = true; |
| 861 | } |
| 862 | } |
| 863 | } |
| 864 | |
| 865 | int OTMulti_learnOnecxx . . $ OTMulti_learnOne(359a3fa70914d01b). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2, |
| 866 | enum kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy# updateRule, int direction, double plasticity, double relativePlasticityNoise) |
| 867 | { |
| 868 | integercxx . . $ integer# iloser = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, form2); |
| 869 | if (direction & OTMulti_LEARN_FORWARDcxx . . $ `gram/OTMulti.h:45:9`!) { |
| 870 | if (Melder_debugcxx . . $ Melder_debug. == 47) OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (me, 2.0); |
| 871 | integercxx . . $ integer# iwinner = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, U""); |
| 872 | if (! (Melder_debugcxx . . $ Melder_debug. == 47) || ! OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, iwinner, form2, U"")) |
| 873 | OTMulti_modifyRankingscxx . . $ OTMulti_modifyRankings(3b28c6c0e24843da). (me, iwinner, iloser, updateRule, plasticity, relativePlasticityNoise); |
| 874 | } |
| 875 | if (direction & OTMulti_LEARN_BACKWARDcxx . . $ `gram/OTMulti.h:46:9`!) { |
| 876 | if (Melder_debugcxx . . $ Melder_debug. == 47) OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (me, 2.0); |
| 877 | integercxx . . $ integer# iwinner = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form2, U""); |
| 878 | if (! (Melder_debugcxx . . $ Melder_debug. == 47) || ! OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, iwinner, form1, U"")) |
| 879 | OTMulti_modifyRankingscxx . . $ OTMulti_modifyRankings(3b28c6c0e24843da). (me, iwinner, iloser, updateRule, plasticity, relativePlasticityNoise); |
| 880 | } |
| 881 | return 1; |
| 882 | } |
| 883 | |
| 884 | static autoTablecxx . . $ autoTable# OTMulti_createHistorycxx . . $ OTMulti_createHistory(1a9b324616494c7b). (OTMulti me, integercxx . . $ integer# storeHistoryEvery, integercxx . . $ integer# numberOfData) |
| 885 | { |
| 886 | try { |
| 887 | integercxx . . $ integer# numberOfSamplingPoints = numberOfData / storeHistoryEvery; // e.g. 0, 20, 40, ... |
| 888 | autoTablecxx . . $ autoTable# thee = Table_createWithoutColumnNamescxx . . $ Table_createWithoutColumnNames(9861d2482f105183). (1 + numberOfSamplingPoints, 3 + mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints); |
| 889 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, U"Datum"); |
| 890 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 2, U"Form1"); |
| 891 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 3, U"Form2"); |
| 892 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 893 | Table_renameColumn_ecxx . . $ Table_renameColumn_e(f3de302d64cc2e6c). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 3 + icons, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 894 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 1, 0); |
| 895 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 2, U"(initial)"); |
| 896 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 3, U"(initial)"); |
| 897 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 898 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 3 + icons, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking); |
| 899 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 900 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 901 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": history not created."); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | static void OTMulti_updateHistorycxx . . $ OTMulti_updateHistory(7a0fb049d4d7803e). (OTMulti me, Tablecxx . . $ Table# thee, integercxx . . $ integer# storeHistoryEvery, integercxx . . $ integer# idatum, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) |
| 906 | { |
| 907 | try { |
| 908 | if (idatum % storeHistoryEvery == 0) { |
| 909 | integercxx . . $ integer# irow = 1 + idatum / storeHistoryEvery; |
| 910 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee, irow, 1, idatum); |
| 911 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee, irow, 2, form1); |
| 912 | Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee, irow, 3, form2); |
| 913 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 914 | Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee, irow, 3 + icons, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking); |
| 915 | } |
| 916 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 917 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": history not updated."); |
| 918 | } |
| 919 | } |
| 920 | |
| 921 | |
| 922 | void OTMulti_PairDistribution_learncxx . . $ OTMulti_PairDistribution_learn(cf6b7e47a2952806). (OTMulti me, PairDistributioncxx . . $ PairDistribution# thee, double evaluationNoise, enum kOTGrammar_rerankingStrategycxx . . $ kOTGrammar_rerankingStrategy# updateRule, int direction, |
| 923 | double initialPlasticity, integercxx . . $ integer# replicationsPerPlasticity, double plasticityDecrement, |
| 924 | integercxx . . $ integer# numberOfPlasticities, double relativePlasticityNoise, integercxx . . $ integer# storeHistoryEvery, autoTablecxx . . $ autoTable# *history_out) |
| 925 | { |
| 926 | integercxx . . $ integer# idatum = 0, numberOfData = numberOfPlasticities * replicationsPerPlasticity; |
| 927 | try { |
| 928 | double plasticity = initialPlasticity; |
| 929 | autoMelderMonitorcxx . . $ autoMelderMonitor# monitorcxx . . $ autoMelderMonitor#autoMelderMonitor(ff00d524ab0355ec). (U"Learning from partial pairs..."); |
| 930 | autoTablecxx . . $ autoTable# historycxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 931 | if (storeHistoryEvery) |
| 932 | history =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). OTMulti_createHistorycxx . . $ OTMulti_createHistory(1a9b324616494c7b). (me, storeHistoryEvery, numberOfData); |
| 933 | for (integercxx . . $ integer# iplasticity = 1; iplasticity <= numberOfPlasticities; iplasticity ++) { |
| 934 | for (integercxx . . $ integer# ireplication = 1; ireplication <= replicationsPerPlasticity; ireplication ++) { |
| 935 | conststring32cxx . . $ conststring32# form1, form2; |
| 936 | PairDistribution_peekPaircxx . . $ PairDistribution_peekPair(dc3b14082034b9b4). (thee, & form1, & form2); |
| 937 | ++ idatum; |
| 938 | if (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).() && idatum % (numberOfData / 400 + 1) == 0) { |
| 939 | integercxx . . $ integer# numberOfDrawnConstraints = mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints < 14 ? mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints : 14; |
| 940 | if (numberOfDrawnConstraints > 0) { |
| 941 | longdoublecxx . . $ longdouble# sumOfRankings = 0.0; |
| 942 | for (integercxx . . $ integer# icons = 1; icons <= numberOfDrawnConstraints; icons ++) |
| 943 | sumOfRankings += mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking; |
| 944 | double meanRanking = double (sumOfRankings) / numberOfDrawnConstraints; |
| 945 | Graphics_beginMovieFramecxx . . $ Graphics_beginMovieFrame(39e73bcf122a4f1d). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), nullptr); |
| 946 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0.0, numberOfData, meanRanking - 50.0, meanRanking + 50.0); |
| 947 | for (integercxx . . $ integer# icons = 1; icons <= numberOfDrawnConstraints; icons ++) { |
| 948 | Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), (double) icons / numberOfDrawnConstraints); |
| 949 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), |
| 950 | idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking, |
| 951 | idatum, mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]. ranking + 1); |
| 952 | } |
| 953 | Graphics_endMovieFramecxx . . $ Graphics_endMovieFrame(2514a1c07b6be5e2). (monitor.graphicscxx . . $ autoMelderMonitor#graphics(718154138b35588e).(), 0.0); |
| 954 | } |
| 955 | } |
| 956 | try { |
| 957 | Melder_monitorcxx . . $ Melder_monitor(71ac93a27c32a1fa). ((double) idatum / numberOfData, |
| 958 | U"Processing partial pair ", idatum, U" out of ", numberOfData, |
| 959 | U":\n ", form1, U" ", form2); |
| 960 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 961 | if (history_out) |
| 962 | *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); // so that we can inspect |
| 963 | throw; |
| 964 | } |
| 965 | OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (me, evaluationNoise); |
| 966 | try { |
| 967 | OTMulti_learnOnecxx . . $ OTMulti_learnOne(359a3fa70914d01b). (me, form1, form2, updateRule, direction, plasticity, relativePlasticityNoise); |
| 968 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 969 | if (history) |
| 970 | OTMulti_updateHistorycxx . . $ OTMulti_updateHistory(7a0fb049d4d7803e). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, form1, form2); |
| 971 | throw; |
| 972 | } |
| 973 | if (history) |
| 974 | OTMulti_updateHistorycxx . . $ OTMulti_updateHistory(7a0fb049d4d7803e). (me, history.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), storeHistoryEvery, idatum, form1, form2); |
| 975 | } |
| 976 | plasticity *= plasticityDecrement; |
| 977 | } |
| 978 | if (history_out) |
| 979 | *history_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). history.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); |
| 980 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 981 | if (idatum > 1) |
| 982 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"Only ", idatum - 1, U" input-output pairs out of ", numberOfData, U" were processed."); |
| 983 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": learning from partial pairs not completed."); |
| 984 | } |
| 985 | } |
| 986 | |
| 987 | static integercxx . . $ integer# OTMulti_crucialCellcxx . . $ OTMulti_crucialCell(1b1c089995731c1a). (OTMulti me, integercxx . . $ integer# icand, integercxx . . $ integer# iwinner, integercxx . . $ integer# numberOfOptimalCandidates, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2) |
| 988 | { |
| 989 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates < 2) return 0; // if there is only one candidate, all cells can be greyed |
| 990 | if (OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, iwinner) == 0) { // candidate equally good as winner? |
| 991 | if (numberOfOptimalCandidates > 1) { |
| 992 | /* All cells are important. */ |
| 993 | } else { |
| 994 | integercxx . . $ integer# secondBest = 0; |
| 995 | for (integercxx . . $ integer# jcand = 1; jcand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; jcand ++) { |
| 996 | if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, jcand, form1, form2) && OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, jcand, iwinner) != 0) { // a non-optimal candidate? |
| 997 | if (secondBest == 0) { |
| 998 | secondBest = jcand; // first guess |
| 999 | } else if (OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, jcand, secondBest) < 0) { |
| 1000 | secondBest = jcand; // better guess |
| 1001 | } |
| 1002 | } |
| 1003 | } |
| 1004 | if (secondBest == 0) return 0; // if all candidates are equally good, all cells can be greyed |
| 1005 | return OTMulti_crucialCellcxx . . $ OTMulti_crucialCell(1b1c089995731c1a). (me, secondBest, iwinner, 1, form1, form2); |
| 1006 | } |
| 1007 | } else { |
| 1008 | const constINTVECcxx . . $ constINTVEC# candidateMarks = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 1009 | const constINTVECcxx . . $ constINTVEC# winnerMarks = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner]. marks.getcxx . . $ autovector#get(e8d1da7fe68a6585).(); |
| 1010 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1011 | const integercxx . . $ integer# numberOfCandidateMarks = candidateMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 1012 | const integercxx . . $ integer# numberOfWinnerMarks = winnerMarks [cxx . . $ constvector#`operator[]`(e616e229aa94bfcf).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 1013 | if (numberOfCandidateMarks > numberOfWinnerMarks) |
| 1014 | return icons; |
| 1015 | } |
| 1016 | } |
| 1017 | return mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; // nothing grey |
| 1018 | } |
| 1019 | |
| 1020 | static double OTMulti_constraintWidthcxx . . $ OTMulti_constraintWidth(57927030c19dcc6f). (Graphicscxx . . $ Graphics# g, OTConstraint constraint, bool showDisharmony) { |
| 1021 | char32cxx . . $ char32# text [100], *newLine; |
| 1022 | double maximumWidth = ( showDisharmony ? 0.8 * Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (constraint -> disharmony, 1)) : 0.0 ), |
| 1023 | firstWidth, secondWidth; |
| 1024 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (text,100, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1025 | newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (text, U'\n'); |
| 1026 | if (newLine) { |
| 1027 | *newLine = U'\0'; |
| 1028 | firstWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, text); |
| 1029 | if (firstWidth > maximumWidth) |
| 1030 | maximumWidth = firstWidth; |
| 1031 | secondWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, newLine + 1); |
| 1032 | if (secondWidth > maximumWidth) |
| 1033 | maximumWidth = secondWidth; |
| 1034 | return maximumWidth; |
| 1035 | } |
| 1036 | firstWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, text); |
| 1037 | if (firstWidth > maximumWidth) |
| 1038 | maximumWidth = firstWidth; |
| 1039 | return maximumWidth; |
| 1040 | } |
| 1041 | |
| 1042 | void OTMulti_drawTableaucxx . . $ OTMulti_drawTableau(6da0ce92984dc4c7). (OTMulti me, Graphicscxx . . $ Graphics# g, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2, bool vertical, bool showDisharmonies) { |
| 1043 | integercxx . . $ integer# winner, winner1 = 0, winner2 = 0; |
| 1044 | double x, y, fontSize = Graphics_inqFontSizecxx . . $ Graphics_inqFontSize(f906975acce41a59). (g); |
| 1045 | MelderColourcxx . . $ MelderColour# colour = Graphics_inqColourcxx . . $ Graphics_inqColour(322ea1b2fa08ba06). (g); |
| 1046 | char32cxx . . $ char32# text [200]; |
| 1047 | bool bidirectional = form1 [0] != U'\0' && form2 [0] != U'\0'; |
| 1048 | try { |
| 1049 | winner = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, form2); |
| 1050 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1051 | Melder_clearErrorcxx . . $ Melder_clearError(49f6e7a06ebc5aa8). (); |
| 1052 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, 0.0, 1.0, 0.0, 1.0); |
| 1053 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1054 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, 0, 1, 0, 1); |
| 1055 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, 0.0, 0.5, U"(no matching candidates)"); |
| 1056 | return; |
| 1057 | } |
| 1058 | |
| 1059 | if (bidirectional) { |
| 1060 | winner1 = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, U""); |
| 1061 | winner2 = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form2, U""); |
| 1062 | } |
| 1063 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, 0.0, 1.0, 0.0, 1.0); |
| 1064 | const double margin = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 1.0); |
| 1065 | const double fingerWidth = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 7.0) * fontSize / 12.0; |
| 1066 | const double doubleLineDx = Graphics_dxMMtoWCcxx . . $ Graphics_dxMMtoWC(f042c24bcd87f07e). (g, 0.9); |
| 1067 | const double doubleLineDy = Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 0.9); |
| 1068 | const double rowHeight = Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 1.5 * fontSize * 25.4 / 72); |
| 1069 | const double descent = rowHeight * 0.5; |
| 1070 | 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 |
| 1071 | /* |
| 1072 | Compute the height of the header row. |
| 1073 | */ |
| 1074 | double headerHeight; |
| 1075 | if (vertical) { |
| 1076 | headerHeight = 0.0; |
| 1077 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1078 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1079 | const double constraintTextWidth = Graphics_textWidthcxx . . $ Graphics_textWidth(c49f17072ec643bd). (g, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1080 | if (constraintTextWidth > headerHeight) |
| 1081 | headerHeight = constraintTextWidth; |
| 1082 | } |
| 1083 | headerHeight += margin * 2; |
| 1084 | headerHeight *= worldAspectRatio; |
| 1085 | } else { |
| 1086 | headerHeight = rowHeight; |
| 1087 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1088 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1089 | if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n')) { |
| 1090 | headerHeight += 0.7 * rowHeight; |
| 1091 | break; |
| 1092 | } |
| 1093 | } |
| 1094 | } |
| 1095 | /* |
| 1096 | Compute longest candidate string. |
| 1097 | Also count the number of optimal candidates (if there are more than one, the fingers will be drawn in red). |
| 1098 | */ |
| 1099 | double candWidth = Graphics_textWidth_pscxx . . $ Graphics_textWidth_ps(e28a56f5afea616d). (g, form1, true) + Graphics_textWidth_pscxx . . $ Graphics_textWidth_ps(e28a56f5afea616d). (g, form2, true); |
| 1100 | integercxx . . $ integer# numberOfMatchingCandidates = 0; |
| 1101 | integercxx . . $ integer# numberOfOptimalCandidates = 0; |
| 1102 | integercxx . . $ integer# numberOfOptimalCandidates1 = 0; |
| 1103 | integercxx . . $ integer# numberOfOptimalCandidates2 = 0; |
| 1104 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) { |
| 1105 | if ((form1 [0] != U'\0' && OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, U"")) || |
| 1106 | (form2 [0] != U'\0' && OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form2, U"")) || |
| 1107 | (form1 [0] == U'\0' && form2 [0] == U'\0')) |
| 1108 | { |
| 1109 | const double width = Graphics_textWidth_pscxx . . $ Graphics_textWidth_ps(e28a56f5afea616d). (g, mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), true); |
| 1110 | if (width > candWidth) |
| 1111 | candWidth = width; |
| 1112 | numberOfMatchingCandidates ++; |
| 1113 | if (OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner) == 0) |
| 1114 | numberOfOptimalCandidates ++; |
| 1115 | if (winner1 != 0 && OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner1) == 0) |
| 1116 | numberOfOptimalCandidates1 ++; |
| 1117 | if (winner2 != 0 && OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner2) == 0) |
| 1118 | numberOfOptimalCandidates2 ++; |
| 1119 | } |
| 1120 | } |
| 1121 | candWidth += fingerWidth * (bidirectional ? 3 : 1) + margin * 3; |
| 1122 | /* |
| 1123 | Compute tableau width. |
| 1124 | */ |
| 1125 | longdoublecxx . . $ longdouble# tableauWidth = candWidth + doubleLineDx; |
| 1126 | if (vertical) { |
| 1127 | tableauWidth += rowHeight * mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints / worldAspectRatio; |
| 1128 | } else { |
| 1129 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1130 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1131 | tableauWidth += OTMulti_constraintWidthcxx . . $ OTMulti_constraintWidth(57927030c19dcc6f). (g, constraint, showDisharmonies); |
| 1132 | } |
| 1133 | tableauWidth += margin * 2 * mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; |
| 1134 | } |
| 1135 | /* |
| 1136 | Draw box. |
| 1137 | */ |
| 1138 | x = doubleLineDx; // left side of tableau |
| 1139 | y = 1.0 - doubleLineDy; |
| 1140 | if (showDisharmonies) |
| 1141 | y -= 0.6 * rowHeight; |
| 1142 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + tableauWidth, |
| 1143 | y - headerHeight - numberOfMatchingCandidates * rowHeight - doubleLineDy, y); |
| 1144 | /* |
| 1145 | Draw input. |
| 1146 | */ |
| 1147 | y -= headerHeight; |
| 1148 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1149 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * candWidth, y + 0.5 * headerHeight, form1, form2); |
| 1150 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + candWidth, y, y + headerHeight); |
| 1151 | /* |
| 1152 | Draw constraint names. |
| 1153 | */ |
| 1154 | x += candWidth + doubleLineDx; |
| 1155 | if (vertical) |
| 1156 | Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 90.0); |
| 1157 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1158 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]]; |
| 1159 | const double width = ( vertical ? rowHeight / worldAspectRatio : OTMulti_constraintWidthcxx . . $ OTMulti_constraintWidth(57927030c19dcc6f). (g, constraint, showDisharmonies) + margin * 2 ); |
| 1160 | if (str32chrcxx . . $ str32chr(328a9ede0fba853a). (constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U'\n') && ! vertical) { |
| 1161 | char32cxx . . $ char32# *newLine; |
| 1162 | Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (text,200, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1163 | newLine = str32chrcxx . . $ str32chr(328a9ede0fba853a). (text, U'\n'); |
| 1164 | *newLine = U'\0'; |
| 1165 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_TOPcxx . . $ `sys/Graphics.h:254:9`!); |
| 1166 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + headerHeight, text); |
| 1167 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1168 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y, newLine + 1); |
| 1169 | } else if (vertical) { |
| 1170 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1171 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + margin, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1172 | } else { |
| 1173 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1174 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + 0.5 * headerHeight, constraint -> name.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1175 | } |
| 1176 | if (showDisharmonies) { |
| 1177 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 0.8 * fontSize); |
| 1178 | if (vertical) |
| 1179 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1180 | else |
| 1181 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_BOTTOMcxx . . $ `sys/Graphics.h:252:9`!); |
| 1182 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + 0.5 * width, y + headerHeight, Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (constraint -> disharmony, 1)); |
| 1183 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize); |
| 1184 | } |
| 1185 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x, y + headerHeight); |
| 1186 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x + width, y); |
| 1187 | x += width; |
| 1188 | } |
| 1189 | if (vertical) |
| 1190 | Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 0.0); |
| 1191 | /* |
| 1192 | Draw candidates. |
| 1193 | */ |
| 1194 | y -= doubleLineDy; |
| 1195 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) |
| 1196 | if ((form1 [0] != U'\0' && OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, U"")) || |
| 1197 | (form2 [0] != U'\0' && OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form2, U"")) || |
| 1198 | (form1 [0] == U'\0' && form2 [0] == U'\0')) |
| 1199 | { |
| 1200 | const integercxx . . $ integer# crucialCell = OTMulti_crucialCellcxx . . $ OTMulti_crucialCell(1b1c089995731c1a). (me, icand, winner, numberOfOptimalCandidates, form1, form2); |
| 1201 | const bool candidateIsOptimal = ( OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner) == 0 ); |
| 1202 | const bool candidateIsOptimal1 = ( winner1 != 0 && OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner1) == 0 ); |
| 1203 | const bool candidateIsOptimal2 = ( winner2 != 0 && OTMulti_compareCandidatescxx . . $ OTMulti_compareCandidates(4671c39d186ec8da). (me, icand, winner2) == 0 ); |
| 1204 | /* |
| 1205 | Draw candidate transcription. |
| 1206 | */ |
| 1207 | x = doubleLineDx; |
| 1208 | y -= rowHeight; |
| 1209 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1210 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + candWidth - margin, y + descent, mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1211 | if (candidateIsOptimal) { |
| 1212 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1213 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, ( bidirectional ? 1.2 : 1.5 ) * fontSize); |
| 1214 | if (numberOfOptimalCandidates > 1) |
| 1215 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.); |
| 1216 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + margin, y + descent - Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 0.5) * fontSize / 12.0, bidirectional ? U"\\Vr" : U"\\pf"); |
| 1217 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour); |
| 1218 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize); |
| 1219 | } |
| 1220 | if (candidateIsOptimal1) { |
| 1221 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_LEFTcxx . . $ `sys/Graphics.h:249:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1222 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 1.5 * fontSize); |
| 1223 | if (numberOfOptimalCandidates1 > 1) |
| 1224 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.); |
| 1225 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + margin + fingerWidth, y + descent - Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 0.5) * fontSize / 12.0, U"\\pf"); |
| 1226 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour); |
| 1227 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize); |
| 1228 | } |
| 1229 | if (candidateIsOptimal2) { |
| 1230 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_RIGHTcxx . . $ `sys/Graphics.h:251:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1231 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, 1.5 * fontSize); |
| 1232 | if (numberOfOptimalCandidates2 > 1) |
| 1233 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, Melder_REDcxx . . $ Melder_RED.); |
| 1234 | Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 180); |
| 1235 | Graphics_textcxx . . $ Graphics_text(8e1820bb471fc8c8). (g, x + margin + fingerWidth * 2, y + descent - Graphics_dyMMtoWCcxx . . $ Graphics_dyMMtoWC(f042c24bcd87f07e). (g, 0.0) * fontSize / 12.0, U"\\pf"); |
| 1236 | Graphics_setTextRotationcxx . . $ Graphics_setTextRotation(2514a1c07b6be5e2). (g, 0); |
| 1237 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour); |
| 1238 | Graphics_setFontSizecxx . . $ Graphics_setFontSize(2514a1c07b6be5e2). (g, fontSize); |
| 1239 | } |
| 1240 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + candWidth, y, y + rowHeight); |
| 1241 | /* |
| 1242 | Draw grey cell backgrounds. |
| 1243 | */ |
| 1244 | if (! bidirectional && mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) { |
| 1245 | x = candWidth + 2 * doubleLineDx; |
| 1246 | Graphics_setGreycxx . . $ Graphics_setGrey(2514a1c07b6be5e2). (g, 0.9); |
| 1247 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1248 | integercxx . . $ integer# index = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1249 | OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; |
| 1250 | const double width = ( vertical ? rowHeight / worldAspectRatio : OTMulti_constraintWidthcxx . . $ OTMulti_constraintWidth(57927030c19dcc6f). (g, constraint, showDisharmonies) + margin * 2 ); |
| 1251 | if (icons > crucialCell) |
| 1252 | Graphics_fillRectanglecxx . . $ Graphics_fillRectangle(72bdb7937dbb13da). (g, x, x + width, y, y + rowHeight); |
| 1253 | x += width; |
| 1254 | } |
| 1255 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour); |
| 1256 | } |
| 1257 | /* |
| 1258 | Draw cell marks. |
| 1259 | */ |
| 1260 | x = candWidth + 2 * doubleLineDx; |
| 1261 | Graphics_setTextAlignmentcxx . . $ Graphics_setTextAlignment(a697afee548943ae). (g, Graphics_CENTREcxx . . $ `sys/Graphics.h:250:9`!, Graphics_HALFcxx . . $ `sys/Graphics.h:253:9`!); |
| 1262 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1263 | const integercxx . . $ integer# index = mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1264 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; |
| 1265 | const double width = ( vertical ? rowHeight / worldAspectRatio : OTMulti_constraintWidthcxx . . $ OTMulti_constraintWidth(57927030c19dcc6f). (g, constraint, showDisharmonies) + margin * 2 ); |
| 1266 | char32cxx . . $ char32# markString [40]; |
| 1267 | markString [0] = U'\0'; |
| 1268 | if (bidirectional && mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] > 0) { |
| 1269 | if ((candidateIsOptimal1 || candidateIsOptimal2) && ! candidateIsOptimal) |
| 1270 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\<-"); |
| 1271 | } |
| 1272 | if (bidirectional && mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] < 0) { |
| 1273 | if (candidateIsOptimal && ! candidateIsOptimal1) |
| 1274 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\<-"); |
| 1275 | if (candidateIsOptimal && ! candidateIsOptimal2) |
| 1276 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\<-"); |
| 1277 | } |
| 1278 | /* |
| 1279 | An exclamation mark can be drawn in this cell only if both of the following conditions are met: |
| 1280 | 1. the candidate is not optimal; |
| 1281 | 2. this is the crucial cell, i.e. the cells after it are drawn in grey. |
| 1282 | */ |
| 1283 | if (! bidirectional && icons == crucialCell && ! candidateIsOptimal && |
| 1284 | mycxx . . $ `melder/melder.h:44:9`! decisionStrategy == kOTGrammar_decisionStrategycxx . . $ kOTGrammar_decisionStrategy#::OPTIMALITY_THEORYcxx . . $ kOTGrammar_decisionStrategy#OPTIMALITY_THEORY.) |
| 1285 | { |
| 1286 | const integercxx . . $ integer# winnerMarks = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).winner]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; |
| 1287 | if (winnerMarks + 1 > 5) { |
| 1288 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (winnerMarks + 1)); |
| 1289 | } else { |
| 1290 | for (integercxx . . $ integer# imark = 1; imark <= winnerMarks + 1; imark ++) |
| 1291 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"*"); |
| 1292 | } |
| 1293 | for (integercxx . . $ integer# imark = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark < 0; imark ++) |
| 1294 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"+"); |
| 1295 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"!"); |
| 1296 | if (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] - (winnerMarks + 2) + 1 > 5) { |
| 1297 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] - (winnerMarks + 2) + 1)); |
| 1298 | } else { |
| 1299 | for (integercxx . . $ integer# imark = winnerMarks + 2; imark <= mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++) |
| 1300 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"*"); |
| 1301 | } |
| 1302 | } else { |
| 1303 | if (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] > 5) { |
| 1304 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index])); |
| 1305 | } else { |
| 1306 | for (integercxx . . $ integer# imark = 1; imark <= mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark ++) |
| 1307 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"*"); |
| 1308 | for (integercxx . . $ integer# imark = mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]; imark < 0; imark ++) |
| 1309 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"+"); |
| 1310 | } |
| 1311 | } |
| 1312 | if (bidirectional && mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] > 0) { |
| 1313 | if (candidateIsOptimal && ! candidateIsOptimal1) |
| 1314 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\->"); |
| 1315 | if (candidateIsOptimal && ! candidateIsOptimal2) |
| 1316 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\->"); |
| 1317 | } |
| 1318 | if (bidirectional && mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. marks [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index] < 0) { |
| 1319 | if ((candidateIsOptimal1 || candidateIsOptimal2) && ! candidateIsOptimal) |
| 1320 | str32catcxx . . $ str32cat(6ab934322573b179). (markString, U"\\->"); |
| 1321 | } |
| 1322 | Graphics_textcxx . . $ Graphics_text(bd267f534253e388). (g, x + 0.5 * width, y + descent, markString); |
| 1323 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (g, colour); |
| 1324 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y, x, y + rowHeight); |
| 1325 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, x, y + rowHeight, x + width, y + rowHeight); |
| 1326 | x += width; |
| 1327 | } |
| 1328 | } |
| 1329 | /* |
| 1330 | Draw box. |
| 1331 | */ |
| 1332 | x = doubleLineDx; // left side of tableau |
| 1333 | y = 1.0 - doubleLineDy; |
| 1334 | if (showDisharmonies) |
| 1335 | y -= 0.6 * rowHeight; |
| 1336 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x, x + tableauWidth, |
| 1337 | y - headerHeight - numberOfMatchingCandidates * rowHeight - doubleLineDy, y); |
| 1338 | } |
| 1339 | |
| 1340 | void OTMulti_resetcxx . . $ OTMulti_reset(8663bcc155b161db). (OTMulti me, double ranking) { |
| 1341 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) { |
| 1342 | const OTConstraint constraint = & mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons]; |
| 1343 | constraint -> disharmony = constraint -> ranking = ranking; |
| 1344 | } |
| 1345 | OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (me); |
| 1346 | } |
| 1347 | |
| 1348 | void OTMulti_setRankingcxx . . $ OTMulti_setRanking(92fa69f80755f0da). (OTMulti me, integercxx . . $ integer# constraint, double ranking, double disharmony) { |
| 1349 | try { |
| 1350 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint >= 1, |
| 1351 | U"The constraint number should be positive, not ", constraint, U"."); |
| 1352 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints, |
| 1353 | U"Constraint ", constraint, U" does not exist (there are only ", mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints, U" constraints)."); |
| 1354 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. ranking = ranking; |
| 1355 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. disharmony = disharmony; |
| 1356 | OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (me); |
| 1357 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1358 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": ranking not set."); |
| 1359 | } |
| 1360 | } |
| 1361 | |
| 1362 | void OTMulti_setConstraintPlasticitycxx . . $ OTMulti_setConstraintPlasticity(c3b8207962d96f28). (OTMulti me, integercxx . . $ integer# constraint, double plasticity) { |
| 1363 | try { |
| 1364 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint >= 1, |
| 1365 | U"The constraint number should be positive, not ", constraint, U"."); |
| 1366 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (constraint <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints, |
| 1367 | U"Constraint ", constraint, U" does not exist (there are only ", mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints, U" constraints)."); |
| 1368 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraint]. plasticity = plasticity; |
| 1369 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1370 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": constraint plasticity not set."); |
| 1371 | } |
| 1372 | } |
| 1373 | |
| 1374 | void OTMulti_removeConstraintcxx . . $ OTMulti_removeConstraint(53c7497ad62bed0). (OTMulti me, conststring32cxx . . $ conststring32# constraintName) { |
| 1375 | try { |
| 1376 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints <= 1) |
| 1377 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot remove last constraint."); |
| 1378 | integercxx . . $ integer# constraintToBeRemoved = OTMulti_getConstraintIndexFromNamecxx . . $ OTMulti_getConstraintIndexFromName(71cea15ada5e2dac). (me, constraintName); |
| 1379 | if (constraintToBeRemoved == 0) |
| 1380 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No constraint \"", constraintName, U"\"."); |
| 1381 | /* |
| 1382 | Remove the constraint while reusing the memory space. |
| 1383 | */ |
| 1384 | mycxx . . $ `melder/melder.h:44:9`! constraints [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).constraintToBeRemoved]. destroy (); |
| 1385 | mycxx . . $ `melder/melder.h:44:9`! constraints. removecxx . . $ autovector#remove(1624ee8275b10bda). (constraintToBeRemoved); |
| 1386 | mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints -= 1; // maintain invariant |
| 1387 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints == mycxx . . $ `melder/melder.h:44:9`! constraints.size); |
| 1388 | /* |
| 1389 | Shift tableau rows. |
| 1390 | */ |
| 1391 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) { |
| 1392 | const OTCandidate candidate = & mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]; |
| 1393 | candidate -> marks. removecxx . . $ autovector#remove(1624ee8275b10bda). (constraintToBeRemoved); |
| 1394 | candidate -> numberOfConstraints -= 1; // maintain invariant |
| 1395 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (candidate -> numberOfConstraints == candidate -> marks.size); |
| 1396 | } |
| 1397 | /* |
| 1398 | Rebuild index. |
| 1399 | */ |
| 1400 | mycxx . . $ `melder/melder.h:44:9`! index. resizecxx . . $ autovector#resize(d91e89fbd57cd1). (mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints); |
| 1401 | for (integercxx . . $ integer# icons = 1; icons <= mycxx . . $ `melder/melder.h:44:9`! numberOfConstraints; icons ++) |
| 1402 | mycxx . . $ `melder/melder.h:44:9`! index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icons] = icons; |
| 1403 | OTMulti_sortcxx . . $ OTMulti_sort(a34eed4b1c1d1bc5). (me); |
| 1404 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1405 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": constraint not removed."); |
| 1406 | } |
| 1407 | } |
| 1408 | |
| 1409 | autostring32cxx . . $ autostring32# OTMulti_generateOptimalFormcxx . . $ OTMulti_generateOptimalForm(334bc7481588a192). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2, double evaluationNoise) { |
| 1410 | try { |
| 1411 | OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (me, evaluationNoise); |
| 1412 | integercxx . . $ integer# winner = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, form2); |
| 1413 | return Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).winner]. string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1414 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1415 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": optimal form not generated."); |
| 1416 | } |
| 1417 | } |
| 1418 | |
| 1419 | autoStringscxx . . $ autoStrings# OTMulti_Strings_generateOptimalFormscxx . . $ OTMulti_Strings_generateOptimalForms(70a9d7a2ed2d09d6). (OTMulti me, Stringscxx . . $ Strings# thee, double evaluationNoise) { |
| 1420 | try { |
| 1421 | autoStringscxx . . $ autoStrings# outputs = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 1422 | integercxx . . $ integer# n = thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; |
| 1423 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. = n; |
| 1424 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (n); |
| 1425 | for (integercxx . . $ integer# i = 1; i <= n; i ++) |
| 1426 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). OTMulti_generateOptimalFormcxx . . $ OTMulti_generateOptimalForm(334bc7481588a192). (me, thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"", evaluationNoise); |
| 1427 | return outputscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1428 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1429 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", thee, U": optimal forms not generated."); |
| 1430 | } |
| 1431 | } |
| 1432 | |
| 1433 | autoStringscxx . . $ autoStrings# OTMulti_generateOptimalFormscxx . . $ OTMulti_generateOptimalForms(eddf49135c67c679). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2, integercxx . . $ integer# numberOfTrials, double evaluationNoise) { |
| 1434 | try { |
| 1435 | autoStringscxx . . $ autoStrings# outputs = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 1436 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. = numberOfTrials; |
| 1437 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (numberOfTrials); |
| 1438 | for (integercxx . . $ integer# i = 1; i <= numberOfTrials; i ++) |
| 1439 | outputs ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). OTMulti_generateOptimalFormcxx . . $ OTMulti_generateOptimalForm(334bc7481588a192). (me, form1, form2, evaluationNoise); |
| 1440 | return outputscxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1441 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1442 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": optimal forms not generated."); |
| 1443 | } |
| 1444 | } |
| 1445 | |
| 1446 | autoDistributionscxx . . $ autoDistributions# OTMulti_to_Distributioncxx . . $ OTMulti_to_Distribution(10993a2b6c47e40c). (OTMulti me, conststring32cxx . . $ conststring32# form1, conststring32cxx . . $ conststring32# form2, |
| 1447 | integercxx . . $ integer# numberOfTrials, double evaluationNoise) |
| 1448 | { |
| 1449 | try { |
| 1450 | integercxx . . $ integer# totalNumberOfOutputs = 0, iout = 0; |
| 1451 | /* |
| 1452 | Count the total number of outputs. |
| 1453 | */ |
| 1454 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) |
| 1455 | if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) |
| 1456 | totalNumberOfOutputs ++; |
| 1457 | /* |
| 1458 | Create the distribution. One row for every output form. |
| 1459 | */ |
| 1460 | autoDistributionscxx . . $ autoDistributions# thee = Distributions_createcxx . . $ Distributions_create(6e2acaa0535ba708). (totalNumberOfOutputs, 1); |
| 1461 | autoINTVECcxx . . $ autoINTVEC# index = raw_INTVECcxx . . $ raw_INTVEC(dab5d3ef28d6a25). (mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates); |
| 1462 | /* |
| 1463 | Set the row labels to the output strings. |
| 1464 | */ |
| 1465 | iout = 0; |
| 1466 | for (integercxx . . $ integer# icand = 1; icand <= mycxx . . $ `melder/melder.h:44:9`! numberOfCandidates; icand ++) { |
| 1467 | if (OTMulti_candidateMatchescxx . . $ OTMulti_candidateMatches(17cb9c47ac4309ff). (me, icand, form1, form2)) { |
| 1468 | thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).++ iout] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (mycxx . . $ `melder/melder.h:44:9`! candidates [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand]. string.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 1469 | index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).icand] = iout; |
| 1470 | } |
| 1471 | } |
| 1472 | /* |
| 1473 | Compute a number of outputs and store the results. |
| 1474 | */ |
| 1475 | for (integercxx . . $ integer# itrial = 1; itrial <= numberOfTrials; itrial ++) { |
| 1476 | OTMulti_newDisharmoniescxx . . $ OTMulti_newDisharmonies(8663bcc155b161db). (me, evaluationNoise); |
| 1477 | integercxx . . $ integer# iwinner = OTMulti_getWinnercxx . . $ OTMulti_getWinner(d0a56e89bef5a754). (me, form1, form2); |
| 1478 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).index [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iwinner]] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] += 1; |
| 1479 | } |
| 1480 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1481 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1482 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": distribution not computed."); |
| 1483 | } |
| 1484 | } |
| 1485 | |
| 1486 | /* End of file OTMulti.cpp */ |