forked from AllenDowney/ThinkBayes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dice.py
41 lines (28 loc) · 861 Bytes
/
dice.py
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
"""This file contains code for use with "Think Bayes",
by Allen B. Downey, available from greenteapress.com
Copyright 2012 Allen B. Downey
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
"""
from thinkbayes import Suite
class Dice(Suite):
"""Represents hypotheses about which die was rolled."""
def Likelihood(self, data, hypo):
"""Computes the likelihood of the data under the hypothesis.
hypo: integer number of sides on the die
data: integer die roll
"""
if hypo < data:
return 0
else:
return 1.0/hypo
def main():
suite = Dice([4, 6, 8, 12, 20])
suite.Update(6)
print 'After one 6'
suite.Print()
for roll in [4, 8, 7, 7, 2]:
suite.Update(roll)
print 'After more rolls'
suite.Print()
if __name__ == '__main__':
main()