Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download

📚 The CoCalc Library - books, templates and other resources

Views: 96161
License: OTHER
1
"""This file contains code for use with "Think Bayes",
2
by Allen B. Downey, available from greenteapress.com
3
4
Copyright 2012 Allen B. Downey
5
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
6
"""
7
8
from thinkbayes import Suite
9
10
11
class Dice(Suite):
12
"""Represents hypotheses about which die was rolled."""
13
14
def Likelihood(self, data, hypo):
15
"""Computes the likelihood of the data under the hypothesis.
16
17
hypo: integer number of sides on the die
18
data: integer die roll
19
"""
20
if hypo < data:
21
return 0
22
else:
23
return 1.0/hypo
24
25
26
def main():
27
suite = Dice([4, 6, 8, 12, 20])
28
29
suite.Update(6)
30
print 'After one 6'
31
suite.Print()
32
33
for roll in [4, 8, 7, 7, 2]:
34
suite.Update(roll)
35
36
print 'After more rolls'
37
suite.Print()
38
39
40
if __name__ == '__main__':
41
main()
42
43