Debian Codegraph @

stat/PairDistribution.cpp

raw symbols SCIP
1 /* PairDistribution.cpp
2 *
3 * Copyright (C) 1997-2013,2015-2019,2021,2022,2024,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 #include "PairDistribution.h"cxx . . $ `<file>/stat/PairDistribution.h`/
20
21 #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/
22 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
23 #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/
24 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
25 #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/
26 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
27 #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/
28 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
29 #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/
30 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
31 #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/
32 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
33 #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/
34 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
35 #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/
36 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
37 #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/
38 #include "PairDistribution_def.h"cxx . . $ `<file>/stat/PairDistribution_def.h`/
39
40 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PairProbability, Daata, 0);
41
42 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PairDistribution, Daata, 0);
43
44 void structPairDistributioncxx . . $ structPairDistribution# :: v1_infocxx . . $ structPairDistribution#v1_info(49f6e7a06ebc5aa8). () {
45 PairDistribution_Parentcxx . . $ PairDistribution_Parent# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). ();
46 MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of pairs: ", pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.);
47 }
48
49 autoPairProbabilitycxx . . $ autoPairProbability# PairProbability_createcxx . . $ PairProbability_create(61c9bcc35f83ae44). (conststring32cxx . . $ conststring32# string1, conststring32cxx . . $ conststring32# string2, double weight) {
50 autoPairProbabilitycxx . . $ autoPairProbability# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PairProbability);
51 mycxx . . $ `melder/melder.h:44:9`! string1cxx . . $ structPairProbability#string1. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (string1);
52 mycxx . . $ `melder/melder.h:44:9`! string2cxx . . $ structPairProbability#string2. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (string2);
53 mycxx . . $ `melder/melder.h:44:9`! weightcxx . . $ structPairProbability#weight. = weight;
54 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
55 }
56
57 autoPairDistributioncxx . . $ autoPairDistribution# PairDistribution_createcxx . . $ PairDistribution_create(55fbb411edc59193). () {
58 try {
59 autoPairDistributioncxx . . $ autoPairDistribution# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PairDistribution);
60 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
61 } catch (MelderErrorcxx . . $ MelderError#) {
62 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"PairDistribution not created.");
63 }
64 }
65
66 int PairProbability_comparecxx . . $ PairProbability_compare(bdb62c02b82eb03b). (PairProbabilitycxx . . $ PairProbability# me, PairProbabilitycxx . . $ PairProbability# thee) noexcept {
67 return str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), thycxx . . $ `melder/melder.h:45:9`! string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
68 }
69
70 static void PairDistribution_checkSpecifiedPairNumbercxx . . $ PairDistribution_checkSpecifiedPairNumber(275f091f9bbaa312). (PairDistributioncxx . . $ PairDistribution# me, const integercxx . . $ integer# pairNumber) {
71 if (pairNumber < 1)
72 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": the specified pair number is ", pairNumber, U", but should be at least 1.");
73 if (pairNumber > mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.)
74 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": the specified pair number is ", pairNumber, U", but should be at most my number of pairs (", mycxx . . $ `melder/melder.h:44:9`! pairs.size, U").");
75 }
76
77 conststring32cxx . . $ conststring32# PairDistribution_getString1cxx . . $ PairDistribution_getString1(9d358ed8aaa1445e). (PairDistributioncxx . . $ PairDistribution# me, const integercxx . . $ integer# pairNumber) {
78 try {
79 PairDistribution_checkSpecifiedPairNumbercxx . . $ PairDistribution_checkSpecifiedPairNumber(275f091f9bbaa312). (me, pairNumber);
80 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairNumber];
81 return prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
82 } catch (MelderErrorcxx . . $ MelderError#) {
83 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": string1 not retrieved.");
84 }
85 }
86
87 conststring32cxx . . $ conststring32# PairDistribution_getString2cxx . . $ PairDistribution_getString2(9d358ed8aaa1445e). (PairDistributioncxx . . $ PairDistribution# me, const integercxx . . $ integer# pairNumber) {
88 try {
89 PairDistribution_checkSpecifiedPairNumbercxx . . $ PairDistribution_checkSpecifiedPairNumber(275f091f9bbaa312). (me, pairNumber);
90 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairNumber];
91 return prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
92 } catch (MelderErrorcxx . . $ MelderError#) {
93 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": string2 not retrieved.");
94 }
95 }
96
97 double PairDistribution_getWeightcxx . . $ PairDistribution_getWeight(64a74e9b997efd24). (PairDistributioncxx . . $ PairDistribution# me, const integercxx . . $ integer# pairNumber) {
98 try {
99 PairDistribution_checkSpecifiedPairNumbercxx . . $ PairDistribution_checkSpecifiedPairNumber(275f091f9bbaa312). (me, pairNumber);
100 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairNumber];
101 return prob -> weightcxx . . $ structPairProbability#weight.;
102 } catch (MelderErrorcxx . . $ MelderError#) {
103 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": weight not retrieved.");
104 }
105 }
106
107 void PairDistribution_setWeightcxx . . $ PairDistribution_setWeight(fdc411a4b78b11fc). (PairDistributioncxx . . $ PairDistribution# me, const integercxx . . $ integer# pairNumber, const double newWeight) {
108 try {
109 PairDistribution_checkSpecifiedPairNumbercxx . . $ PairDistribution_checkSpecifiedPairNumber(275f091f9bbaa312). (me, pairNumber);
110 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairNumber];
111 prob -> weightcxx . . $ structPairProbability#weight. = newWeight;
112 } catch (MelderErrorcxx . . $ MelderError#) {
113 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": weight not changed.");
114 }
115 }
116
117 void PairDistribution_addcxx . . $ PairDistribution_add(abae96e3399dd15c). (PairDistributioncxx . . $ PairDistribution# me, conststring32cxx . . $ conststring32# string1, conststring32cxx . . $ conststring32# string2, const double weight) {
118 autoPairProbabilitycxx . . $ autoPairProbability# pair = PairProbability_createcxx . . $ PairProbability_create(61c9bcc35f83ae44). (string1, string2, weight);
119 mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs.. addItem_movecxx . . $ CollectionOf#addItem_move(bcc0cff787be24fe). (paircxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
120 }
121
122 void PairDistribution_removeZeroWeightscxx . . $ PairDistribution_removeZeroWeights(2b5cf2283919bbe5). (PairDistributioncxx . . $ PairDistribution# me) {
123 for (integercxx . . $ integer# ipair = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair > 0; ipair --) {
124 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
125 if (prob -> weightcxx . . $ structPairProbability#weight. <= 0.0) {
126 mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs.. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (ipair);
127 }
128 }
129 }
130
131 void PairDistribution_swapInputsAndOutputscxx . . $ PairDistribution_swapInputsAndOutputs(2b5cf2283919bbe5). (PairDistributioncxx . . $ PairDistribution# me) {
132 for (integercxx . . $ integer# ipair = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair > 0; ipair --) {
133 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
134 stdcxx . . $ std/::swapcxx . . $ std/swap(c75b8fd57d7c2e06). (prob -> string1cxx . . $ structPairProbability#string1., prob -> string2cxx . . $ structPairProbability#string2.);
135 }
136 }
137
138 static double PairDistributions_getTotalWeight_checkPositivecxx . . $ PairDistributions_getTotalWeight_checkPositive(6c57cf506e796c46). (PairDistributioncxx . . $ PairDistribution# me) {
139 longdoublecxx . . $ longdouble# totalWeight = 0.0;
140 for (integercxx . . $ integer# ipair = 1; ipair <= mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
141 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
142 totalWeight += prob -> weightcxx . . $ structPairProbability#weight.;
143 }
144 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (totalWeight > 0.0,
145 me, U": the total probability weight is ", Melder_half (double (totalWeight)),
146 U" but should be greater than zero for this operation."
147 );
148 return double (totalWeight);
149 }
150
151 void PairDistribution_to_Stringsescxx . . $ PairDistribution_to_Stringses(203364d26e54801f). (PairDistributioncxx . . $ PairDistribution# me, integercxx . . $ integer# nout, autoStringscxx . . $ autoStrings# *strings1_out, autoStringscxx . . $ autoStrings# *strings2_out) {
152 try {
153 const integercxx . . $ integer# nin = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.;
154 if (nin < 1)
155 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No candidates.");
156 if (nout < 1)
157 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Number of generated string pairs should be positive.");
158 const double total = PairDistributions_getTotalWeight_checkPositivecxx . . $ PairDistributions_getTotalWeight_checkPositive(6c57cf506e796c46). (me);
159 autoStringscxx . . $ autoStrings# strings1 = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
160 strings1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. = nout;
161 strings1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (nout);
162 autoStringscxx . . $ autoStrings# strings2 = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings);
163 strings2 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). numberOfStringscxx . . $ structStrings#numberOfStrings. = nout;
164 strings2 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (nout);
165 for (integercxx . . $ integer# iout = 1; iout <= nout; iout ++) {
166 integercxx . . $ integer# iin;
167 do {
168 const double rand = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0, total);
169 longdoublecxx . . $ longdouble# sum = 0.0;
170 for (iin = 1; iin <= nin; iin ++) {
171 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iin];
172 sum += prob -> weightcxx . . $ structPairProbability#weight.;
173 if (rand <= sum) break;
174 }
175 } while (iin > nin); /* Guard against rounding errors. */
176 PairProbabilitycxx . . $ PairProbability# const prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iin];
177 if (! prob -> string1cxx . . $ structPairProbability#string1. || ! prob -> string2cxx . . $ structPairProbability#string2.)
178 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No string in probability pair ", iin, U".");
179 strings1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).iout] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
180 strings2 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).iout] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
181 }
182 *strings1_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). strings1.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
183 *strings2_out =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). strings2.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
184 } catch (MelderErrorcxx . . $ MelderError#) {
185 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": generation of Stringses not performed.");
186 }
187 }
188
189 void PairDistribution_peekPaircxx . . $ PairDistribution_peekPair(dc3b14082034b9b4). (PairDistributioncxx . . $ PairDistribution# me, conststring32cxx . . $ conststring32# *out_string1, conststring32cxx . . $ conststring32# *out_string2) {
190 try {
191 *out_string1 = *out_string2 = nullptr;
192 longdoublecxx . . $ longdouble# total = 0.0;
193 const integercxx . . $ integer# nin = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.;
194 PairProbabilitycxx . . $ PairProbability# prob;
195 if (nin < 1) Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No candidates.");
196 integercxx . . $ integer# iin;
197 for (iin = 1; iin <= nin; iin ++) {
198 prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iin];
199 total += prob -> weightcxx . . $ structPairProbability#weight.;
200 }
201 do {
202 const double rand = NUMrandomUniformcxx . . $ NUMrandomUniform(d8e7e0733fa41c87). (0.0, double (total));
203 longdoublecxx . . $ longdouble# sum = 0.0;
204 for (iin = 1; iin <= nin; iin ++) {
205 prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iin];
206 sum += prob -> weightcxx . . $ structPairProbability#weight.;
207 if (rand <= sum) break;
208 }
209 } while (iin > nin); // guard against rounding errors
210 prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iin];
211 if (! prob -> string1cxx . . $ structPairProbability#string1. || ! prob -> string2cxx . . $ structPairProbability#string2.) Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No string in probability pair ", iin, U".");
212 *out_string1 = prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
213 *out_string2 = prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
214 } catch (MelderErrorcxx . . $ MelderError#) {
215 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": pair not peeked.");
216 }
217 }
218
219 static double PairDistribution_getFractionCorrectcxx . . $ PairDistribution_getFractionCorrect(32e5b14594d22583). (PairDistributioncxx . . $ PairDistribution# me, int which) {
220 try {
221 longdoublecxx . . $ longdouble# correct = 0.0;
222 integercxx . . $ integer# pairmin = 1, ipair;
223 autoPairDistributioncxx . . $ autoPairDistribution# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me);
224 thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sortcxx . . $ CollectionOf#sort(3e1711cf2889fa6c). (PairProbability_comparecxx . . $ PairProbability_compare(bdb62c02b82eb03b).);
225 double total = PairDistributions_getTotalWeight_checkPositivecxx . . $ PairDistributions_getTotalWeight_checkPositive(6c57cf506e796c46). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
226 do {
227 integercxx . . $ integer# pairmax = pairmin;
228 const conststring32cxx . . $ conststring32# firstInput = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairmin] -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
229 for (ipair = pairmin + 1; ipair <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
230 PairProbabilitycxx . . $ PairProbability# const prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
231 if (! str32equcxx . . $ `melder/melder_str32.h:122:9`! (prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), firstInput)) {
232 pairmax = ipair - 1;
233 break;
234 }
235 }
236 if (ipair > thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.) pairmax = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.;
237 if (which == 0) {
238 double pmax = 0.0;
239 for (ipair = pairmin; ipair <= pairmax; ipair ++) {
240 PairProbabilitycxx . . $ PairProbability# const prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
241 const double p = prob -> weightcxx . . $ structPairProbability#weight. / total;
242 if (p > pmax) pmax = p;
243 }
244 correct += pmax;
245 } else {
246 longdoublecxx . . $ longdouble# sum = 0.0, p2 = 0.0;
247 for (ipair = pairmin; ipair <= pairmax; ipair ++) {
248 PairProbabilitycxx . . $ PairProbability# const prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
249 const double p = prob -> weightcxx . . $ structPairProbability#weight. / total;
250 sum += p;
251 p2 += p * p;
252 }
253 correct += p2 / sum;
254 }
255 pairmin = pairmax + 1;
256 } while (pairmin <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.);
257 return double (correct);
258 } catch (MelderErrorcxx . . $ MelderError#) {
259 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": could not compute my fraction correct.");
260 }
261 }
262
263 double PairDistribution_getFractionCorrect_maximumLikelihoodcxx . . $ PairDistribution_getFractionCorrect_maximumLikelihood(6c57cf506e796c46). (PairDistributioncxx . . $ PairDistribution# me) {
264 return PairDistribution_getFractionCorrectcxx . . $ PairDistribution_getFractionCorrect(32e5b14594d22583). (me, 0);
265 }
266
267 double PairDistribution_getFractionCorrect_probabilityMatchingcxx . . $ PairDistribution_getFractionCorrect_probabilityMatching(6c57cf506e796c46). (PairDistributioncxx . . $ PairDistribution# me) {
268 return PairDistribution_getFractionCorrectcxx . . $ PairDistribution_getFractionCorrect(32e5b14594d22583). (me, 1);
269 }
270
271 double PairDistribution_Distributions_getFractionCorrectcxx . . $ PairDistribution_Distributions_getFractionCorrect(990537a7dcd26bd7). (PairDistributioncxx . . $ PairDistribution# me, Distributionscxx . . $ Distributions# dist, integercxx . . $ integer# column) {
272 try {
273 longdoublecxx . . $ longdouble# correct = 0.0;
274 integercxx . . $ integer# pairmin = 1;
275 char32cxx . . $ char32# string [1000];
276 Distributions_checkSpecifiedColumnNumberWithinRangecxx . . $ Distributions_checkSpecifiedColumnNumberWithinRange(1941a5510fdd3f26). (dist, column);
277 autoPairDistributioncxx . . $ autoPairDistribution# thee = Data_copycxx . . $ Data_copy(97a542a26794c80e). (me);
278 thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sortcxx . . $ CollectionOf#sort(3e1711cf2889fa6c). (PairProbability_comparecxx . . $ PairProbability_compare(bdb62c02b82eb03b).);
279 double total = PairDistributions_getTotalWeight_checkPositivecxx . . $ PairDistributions_getTotalWeight_checkPositive(6c57cf506e796c46). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
280 do {
281 integercxx . . $ integer# pairmax = pairmin, ipair;
282 longdoublecxx . . $ longdouble# sum = 0.0, sumDist = 0.0;
283 const conststring32cxx . . $ conststring32# firstInput = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).pairmin] -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).();
284 for (ipair = pairmin + 1; ipair <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
285 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
286 if (! str32equcxx . . $ `melder/melder_str32.h:122:9`! (prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), firstInput)) {
287 pairmax = ipair - 1;
288 break;
289 }
290 }
291 if (ipair > thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.) pairmax = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.;
292 for (ipair = pairmin; ipair <= pairmax; ipair ++) {
293 PairProbabilitycxx . . $ PairProbability# prob = thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
294 const double p = prob -> weightcxx . . $ structPairProbability#weight. / total;
295 double pout = 0.0;
296 Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (string, 1000, prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U" \\-> ", prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
297 for (integercxx . . $ integer# idist = 1; idist <= dist -> numberOfRowscxx . . $ structTableOfReal#numberOfRows.; idist ++) {
298 if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (string, dist -> rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).idist].getcxx . . $ _autostring#get(5a2a78a048fb49a8).())) {
299 pout = dist -> datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).idist] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).column];
300 break;
301 }
302 }
303 sum += p * pout;
304 }
305 Melder_sprintcxx . . $ Melder_sprint(2b992b0fb5123bdf). (string, 1000, firstInput, U" \\-> ");
306 const integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (string);
307 for (integercxx . . $ integer# idist = 1; idist <= dist -> numberOfRowscxx . . $ structTableOfReal#numberOfRows.; idist ++)
308 if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (string, dist -> rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).idist].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), length))
309 sumDist += dist -> datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).idist] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).column];
310 if (sumDist != 0.0) correct += sum / sumDist;
311 pairmin = pairmax + 1;
312 } while (pairmin <= thycxx . . $ `melder/melder.h:45:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.);
313 return double (correct);
314 } catch (MelderErrorcxx . . $ MelderError#) {
315 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" & ", dist, U": could not compute our fraction correct.");
316 }
317 }
318
319 autoTablecxx . . $ autoTable# PairDistribution_to_Tablecxx . . $ PairDistribution_to_Table(93a2c9003af948da). (PairDistributioncxx . . $ PairDistribution# me) {
320 try {
321 autoTablecxx . . $ autoTable# thee = Table_createWithColumnNamescxx . . $ Table_createWithColumnNames(41b41b537590f3f4). (mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.,
322 autoSTRVECcxx . . $ _conststringvector#_conststringvector(93d9e701af42cb0d). ({ U"string1", U"string2", U"weight" }).getcxx . . $ _autostringautovector#get(9d56076a9ef7dd02).());
323 for (integercxx . . $ integer# ipair = 1; ipair <= mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..sizecxx . . $ CollectionOf#size.; ipair ++) {
324 PairProbabilitycxx . . $ PairProbability# prob = mycxx . . $ `melder/melder.h:44:9`! pairscxx . . $ structPairDistribution#pairs..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipair];
325 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ipair, 1, prob -> string1cxx . . $ structPairProbability#string1..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
326 Table_setStringValuecxx . . $ Table_setStringValue(309228d4a4a76ab1). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ipair, 2, prob -> string2cxx . . $ structPairProbability#string2..getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
327 Table_setNumericValuecxx . . $ Table_setNumericValue(adcc5027476b94a0). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ipair, 3, prob -> weightcxx . . $ structPairProbability#weight.);
328 }
329 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
330 } catch (MelderErrorcxx . . $ MelderError#) {
331 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Table.");
332 }
333 }
334
335 /* End of file PairDistribution.cpp */