| 1 | /* Distributions_and_Strings.cpp |
| 2 | * |
| 3 | * Copyright (C) 1997-2011,2014,2015,2016,2017 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 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 "Distributions_and_Strings.h"cxx . . $ `<file>/stat/Distributions_and_Strings.h`/ |
| 20 | |
| 21 | autoStringscxx . . $ autoStrings# Distributions_to_Stringscxx . . $ Distributions_to_Strings(6c7e0bf0aaa8b4ce). (Distributionscxx . . $ Distributions# me, integercxx . . $ integer# column, integercxx . . $ integer# numberOfStrings) { |
| 22 | try { |
| 23 | autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 24 | thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = numberOfStrings; |
| 25 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (numberOfStrings); |
| 26 | for (integercxx . . $ integer# istring = 1; istring <= numberOfStrings; istring ++) { |
| 27 | conststring32cxx . . $ conststring32# string; |
| 28 | Distributions_peekcxx . . $ Distributions_peek(70b1239ea03afa). (me, column, & string, nullptr); |
| 29 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).istring] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (string); |
| 30 | } |
| 31 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 32 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 33 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": Strings not generated."); |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | autoStringscxx . . $ autoStrings# Distributions_to_Strings_exactcxx . . $ Distributions_to_Strings_exact(b2276db93996b546). (Distributionscxx . . $ Distributions# me, integercxx . . $ integer# column) { |
| 38 | try { |
| 39 | integercxx . . $ integer# total = 0; |
| 40 | integercxx . . $ integer# istring = 0; |
| 41 | if (column > mycxx . . $ `melder/melder.h:44:9`! numberOfColumnscxx . . $ structTableOfReal#numberOfColumns.) |
| 42 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No column ", column, U"."); |
| 43 | if (mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. < 1) |
| 44 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No candidates."); |
| 45 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; irow ++) { |
| 46 | double value = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).column]; |
| 47 | if (value != Melder_roundDowncxx . . $ Melder_roundDown(447c67c6676f75c3). (value)) |
| 48 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Non-integer value ", value, U" in row ", irow, U"."); |
| 49 | if (value < 0.0) |
| 50 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Found a negative value ", value, U" in row ", irow, U"."); |
| 51 | total += value; |
| 52 | } |
| 53 | if (total <= 0) |
| 54 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Column total not positive."); |
| 55 | autoStringscxx . . $ autoStrings# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Strings); |
| 56 | thycxx . . $ `melder/melder.h:45:9`! numberOfStringscxx . . $ structStrings#numberOfStrings. = total; |
| 57 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. =cxx . . $ _autostringautovector#`operator=`(150f7ba7aac25b7e). autoSTRVECcxx . . $ autoSTRVEC# (total); |
| 58 | for (integercxx . . $ integer# irow = 1; irow <= mycxx . . $ `melder/melder.h:44:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows.; irow ++) { |
| 59 | integercxx . . $ integer# number = mycxx . . $ `melder/melder.h:44:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).irow] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).column]; |
| 60 | conststring32cxx . . $ conststring32# string = mycxx . . $ `melder/melder.h:44:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).irow].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 61 | if (! string) |
| 62 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No string in row ", irow, U"."); |
| 63 | for (integercxx . . $ integer# i = 1; i <= number; i ++) |
| 64 | thycxx . . $ `melder/melder.h:45:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).++ istring] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (string); |
| 65 | } |
| 66 | Strings_randomizecxx . . $ Strings_randomize(1f79c244d2d6c1ef). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 67 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 68 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 69 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": Strings not generated."); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | autoDistributionscxx . . $ autoDistributions# Strings_to_Distributionscxx . . $ Strings_to_Distributions(51ca0faf08ce563). (Stringscxx . . $ Strings# me) { |
| 74 | try { |
| 75 | autoDistributionscxx . . $ autoDistributions# thee = Distributions_createcxx . . $ Distributions_create(6e2acaa0535ba708). (mycxx . . $ `melder/melder.h:44:9`! numberOfStringscxx . . $ structStrings#numberOfStrings., 1); |
| 76 | integercxx . . $ integer# idist = 0; |
| 77 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! numberOfStringscxx . . $ structStrings#numberOfStrings.; i ++) { |
| 78 | conststring32cxx . . $ conststring32# string = mycxx . . $ `melder/melder.h:44:9`! stringscxx . . $ structStrings#strings. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).i].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 79 | integercxx . . $ integer# where = 0; |
| 80 | integercxx . . $ integer# j = 1; |
| 81 | for (; j <= idist; j ++) { |
| 82 | if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).j].getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), string)) { |
| 83 | where = j; |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | if (where) { |
| 88 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).j] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] += 1.0; |
| 89 | } else { |
| 90 | thycxx . . $ `melder/melder.h:45:9`! rowLabelscxx . . $ structTableOfReal#rowLabels. [cxx . . $ _autostringautovector#`operator[]`(f191be2b65019068).++ idist] =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (string); |
| 91 | thycxx . . $ `melder/melder.h:45:9`! datacxx . . $ structTableOfReal#data. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).idist] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = 1.0; |
| 92 | } |
| 93 | } |
| 94 | thycxx . . $ `melder/melder.h:45:9`! numberOfRowscxx . . $ structTableOfReal#numberOfRows. = idist; |
| 95 | TableOfReal_sortByLabelcxx . . $ TableOfReal_sortByLabel(cfadf70b559ed315). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, 0); |
| 96 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 97 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 98 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": distribution not computed."); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | /* End of file Distributions_and_Strings.cpp */ |