Repository for a workshop on Bayesian statistics
"""This file contains code for use with "Think Bayes",1by Allen B. Downey, available from greenteapress.com23Copyright 2012 Allen B. Downey4License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html5"""67from __future__ import print_function, division89import thinkbayes10import thinkplot111213class Train(thinkbayes.Suite):14"""Represents hypotheses about how many trains the company has.1516The likelihood function for the train problem is the same as17for the Dice problem.18"""19def Likelihood(self, data, hypo):20"""Computes the likelihood of the data under the hypothesis.2122hypo: number of trains the carrier operates23data: the number of the observed train24"""25if hypo < data:26return 027else:28return 1.0/hypo29303132def main():33hypos = range(100, 1001)34suite = Train(hypos)3536suite.Update(321)37print('Posterior mean', suite.Mean())38print('Posterior MLE', suite.MaximumLikelihood())39print('Posterior CI 90', suite.CredibleInterval(90))4041thinkplot.PrePlot(1)42thinkplot.Pmf(suite)43thinkplot.Show(xlabel='Number of trains',44ylabel='Probability',45legend=False)464748if __name__ == '__main__':49main()505152