def main(): pmf_dice = Pmf() pmf_dice.Set(Die(6),2) pmf_dice.Set(Die(8),3) pmf_dice.Set(Die(12),1) pmf_dice.Set(Die(20),1) mix = Pmf() for die, weight in pmf_dice.Items(): for outcome, prob in die.Items(): mix.Incr(outcome, weight*prob) mix.Normalize() thinkplot.PrePlot(1) thinkplot.Pmf(mix) thinkplot.Save(root='dice_Mix_self3',xlabel='',ylabel='Probability',formats=['pdf'])
def Likelihood(self, data, hypo): mix = self.mixes[hypo] like = mix[data] return like hypos = ['Bowl 1', 'Bowl 2'] pmf = Cookie(hypos) # Cookie provides an Update method that takes data as a parameter and updates the probabilities: # Update loops through each hypothesis in the suite and muiltiplies its probability by the likelihood # of the data under the hypothesis. pmf.Update('vanilla') for hypo, prob in pmf.Items(): print(hypo, prob) print('\n') dataset = ['vanilla', 'chocolate', 'vanilla'] for data in dataset: pmf.Update(data) # The lines below will show different probabilities. for data, prob in pmf.Items(): print(data, prob) print('\n') print('The Monty Hall Problem:')
from thinkbayes import Pmf pmf = Pmf() pmf.Set('b1', 0.5) pmf.Set('b2', 0.5) print pmf.Items() pmf.Mult('b1', 0.75) pmf.Mult('b2', 0.5) print pmf.Items() pmf.Normalize() print pmf.Items() print pmf.Prob('b1')