forked from sequitur-g2p/sequitur-g2p
-
Notifications
You must be signed in to change notification settings - Fork 0
/
testProbability.cc
116 lines (105 loc) · 3.4 KB
/
testProbability.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/*
* $Id:$
*
* Copyright (c) 2004-2005 RWTH Aachen University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 2 (June
* 1991) as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, you will find it at
* http://www.gnu.org/licenses/gpl.html, or write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
* USA.
*
* Should a provision of no. 9 and 10 of the GNU General Public License
* be invalid or become invalid, a valid provision is deemed to have been
* agreed upon which comes closest to what the parties intended
* commercially. In any case guarantee/warranty shall be limited to gross
* negligent actions or intended actions or fraudulent concealment.
*/
#include <Core/Assertions.hh>
#include "probability.hh"
int main(int argc, char *argv[]) {
Probability p, p1, p2;
LogProbability s, s1, s2;
// default constructor
hope(p == Probability::impossible());
hope(s == LogProbability::impossible());
// certainty
p = Probability::certain();
hope(p == Probability::certain());
hope(p.complement() == Probability::impossible());
s = LogProbability::certain();
hope(s == LogProbability::certain());
hope(s.complement() == LogProbability::impossible());
p = LogProbability::certain();
s = Probability::certain();
hope(p == Probability::certain());
hope(s == LogProbability::certain());
// impossibility
p = Probability::impossible();
s = p; p = s;
hope(p == Probability::impossible());
hope(s <= LogProbability::impossible());
p1 = Probability::impossible();
p2 = Probability(0.1);
p = p1 * p2;
hope(p == Probability::impossible());
p = p1 / p2;
hope(p == Probability::impossible());
p = p2 + p1;
hope(p == p2);
p = p2 - p1;
hope(p == p2);
hope(p1.entropy() == 0.0);
p1 = Probability::certain();
p2 = Probability(0.1);
p = p1 * p2;
hope(p == p2);
p = p2 / p1;
hope(p == p2);
// p = p2 + p1;
// hope(p == p2);
p = p1 - p2;
hope(p == p2.complement());
hope(p1.entropy() == 0.0);
s1 = LogProbability::impossible();
s2 = LogProbability(0.1);
s = s1 * s2;
hope(s <= LogProbability::impossible());
s = s1 / s2;
hope(s.probability() <= 0.0);
s = s2 + s1;
hope(s == s2);
s = s2 - s1;
hope(s == s2);
hope(s1.entropy() == 0.0);
s1 = LogProbability::certain();
s2 = Probability(0.1);
s = s1 * s2;
hope(s == s2);
s = s2 / s1;
hope(s == s2);
s = s2 + s1;
hope(s >= s2);
s = s1 - s2;
hope(s == s2.complement());
hope(s1.entropy() == 0.0);
p1 = s1 = Probability(0.2);
p2 = s2 = Probability(0.1);
p = p1 + p2; s = s1 + s2;
hope(p.probability() == s.probability());
p = p1 - p2; s = s1 - s2;
hope(equal_fpp(p.probability(), s.probability()));
p = p1 * p2; s = s1 * s2;
hope(equal_fpp(p.probability(), s.probability()));
p = p1 / p2; s = s1 / s2;
hope(equal_fpp(p.probability(), s.probability()));
}