Example #1
0
def main():
    pmf = Pmf()

    pmf.Set('Bowl 1', 0.5)
    pmf.Set('Bowl 2', 0.5)

    pmf.Mult('Bowl 1', 0.75)
    pmf.Mult('Bowl 2', 0.5)

    pmf.Normalize()

    print(pmf.Prob('Bowl 1'))
    print(pmf.Prob('Bowl 2'))
Example #2
0
"""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 __future__ import print_function, division

from thinkbayes2 import Pmf

pmf = Pmf()
pmf.Set('Bowl 1', 0.5)
pmf.Set('Bowl 2', 0.5)

pmf.Mult('Bowl 1', 0.75)
pmf.Mult('Bowl 2', 0.5)

pmf.Normalize()

print(pmf.Prob('Bowl 1'))
Example #3
0
from thinkbayes2 import Pmf, Suite, CredibleInterval, Beta

# PMF for 6-sided die
pmf = Pmf()
for x in [1, 2, 3, 4, 5, 6]:
    pmf.Set(x, 1 / 6)
print(pmf)

# How to build up a pmf from a list of strings
pmf2 = Pmf()
for word in ['a', 'in', 'or', 'to', 'a', 'me', 'in']:
    pmf2.Incr(word, 1)
pmf2.Normalize()
print(pmf2)
print("Probability of letter a:", pmf2.Prob(
    'a'))  # Typo p12 print pmf.Prob('the') should read print(pmf.Prob('the'))

# PMF for the Cookie problem
pmf = Pmf()
# Prior:
pmf.Set("Bowl 1", 0.5)
pmf.Set("Bowl 2", 0.5)
# Posterior:
# First multiply prior by likelihood
pmf.Mult("Bowl 1", 0.75)
pmf.Mult("Bowl 2", 0.5)
# Then normalise (we can do this because the hypotheses are mutually exclusive and collectively exhaustive,
# i.e. only one of the hypotheses can be true and there can be no other hypothesis)
pmf.Normalize()
print(pmf)
Example #4
0
# http://www.greenteapress.com/thinkbayes/thinkbayes.pdf
# http://thinkbayes.com/thinkbayes.py
# python -m pip install scipy numpy matplotlib pandas

from thinkbayes2 import Pmf

pmf = Pmf()

pmf.Set('tazon1', 0.5)
pmf.Set('tazon2', 0.5)

pmf.Mult('tazon1', 0.75)
pmf.Mult('tazon2', 0.5)

pmf.Normalize()

print(pmf.Prob('tazon1'))
Example #5
0
# -*- coding: utf-8 -*-
"""
Created on Tue Apr 17 12:08:20 2018

@author: QJ
"""

###Think Bayes
from thinkbayes2 import Pmf
pmf = Pmf()
for x in [1, 2, 3, 4, 5, 6]:
    pmf.Set(x, 1 / 6.0)
pmf.Set('Bowl1', 0.5)
pmf.Set('Bowl2', 0.5)
pmf.Mult('Bowl1', 0.75)
pmf.Mult('Bowl2', 0.5)
print pmf.Prob('Bowl 1')
print(pmf)