forked from AllenDowney/ThinkBayes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
train2.py
48 lines (33 loc) · 1004 Bytes
/
train2.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
42
43
44
45
46
47
48
"""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 dice import Dice
import thinkplot
class Train(Dice):
"""The likelihood function for the train problem is the same as
for the Dice problem."""
def Mean(suite):
total = 0
for hypo, prob in suite.Items():
total += hypo * prob
return total
def MakePosterior(high, dataset):
hypos = xrange(1, high+1)
suite = Train(hypos)
suite.name = str(high)
for data in dataset:
suite.Update(data)
thinkplot.Pmf(suite)
return suite
def main():
dataset = [30, 60, 90]
for high in [500, 1000, 2000]:
suite = MakePosterior(high, dataset)
print high, suite.Mean()
thinkplot.Save(root='train2',
xlabel='Number of trains',
ylabel='Probability')
if __name__ == '__main__':
main()