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'))
"""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'))
import sys sys.path.insert(0, '/Users/carol/python/ThinkBayes2/thinkbayes2/') import numpy as np import matplotlib.pyplot as plt 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)
# 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'))
from __future__ import print_function, division import sys sys.path.append("../lib/ThinkBayes2/code/") from thinkbayes2 import Suite, Pmf, SampleSum, MakeMixture import thinkplot from simulationDD02 import Die pmf_dice = Pmf() pmf_dice.Set(Die(4), 2) pmf_dice.Set(Die(6), 3) pmf_dice.Set(Die(8), 2) pmf_dice.Set(Die(12), 1) pmf_dice.Set(Die(20), 1) pmf_dice.Normalize() print(pmf_dice) print("#################################################") mix = Pmf() for die, weight in pmf_dice.Items(): for outcome, prob in die.Items(): mix.Incr(outcome, weight * prob) #Shorthand for above #mix = MakeMixture(pmf_dice) print(mix) thinkplot.Hist(mix) thinkplot.Save(root='bar', xlabel='Mixture over a set of dice', ylabel='Probability', formats=['pdf'])
from thinkbayes2 import Pmf if __name__ == '__main__': pmf = Pmf() for x in range(1, 7): pmf.Set(x, 1 / 6.0) pmf.Print()
# -*- 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)