Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
allendowney
GitHub Repository: allendowney/thinkbayes2
Path: blob/master/scripts/electorate.py
1901 views
1
"""This file contains code for use with "Think Bayes",
2
by Allen B. Downey, available from greenteapress.com
3
4
Copyright 2014 Allen B. Downey
5
License: GNU GPLv3 http://www.gnu.org/licenses/gpl.html
6
"""
7
8
from __future__ import print_function, division
9
10
import numpy
11
import thinkbayes2
12
import thinkplot
13
14
15
class Electorate(thinkbayes2.Suite):
16
"""Represents hypotheses about the state of the electorate."""
17
18
def Likelihood(self, data, hypo):
19
"""Computes the likelihood of the data under the hypothesis.
20
21
hypo:
22
data:
23
"""
24
like = 1
25
return like
26
27
28
def main():
29
hypos = numpy.linspace(0, 100, 101)
30
suite = Electorate(hypos)
31
32
thinkplot.Pdf(suite, label='prior')
33
34
data = 1.1, 3.7, 53
35
suite.Update(data)
36
37
thinkplot.Pdf(suite, label='posterior')
38
thinkplot.Show()
39
40
41
if __name__ == '__main__':
42
main()
43
44