def main(): # d6 = Die(6) # d8 = Die(8) d6 = Pmf() print type(d6) d6.Set(Die(6), 2) print type(d6) d8 = Pmf() d8.Set(Die(8), 3) d12 = Pmf() d12.Set(Die(12), 1) d20 = Pmf() d20.Set(Die(20), 1) mix = Pmf() for dice in [d6, d8, d12, d20]: # print type(dice) for die, weight in dice.Items(): # print type(die) for outcome, prob in die.Items(): mix.Incr(outcome, weight * prob) mix.Normalize() thinkplot.PrePlot(1) thinkplot.Pmf(mix) thinkplot.Save(root='dice_Mix_self2', xlabel='', ylabel='Probability', formats=['pdf'])
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 main(): d6 = Die(6) d8 = Die(8) d12 = Die(12) d16 = Die(16) d20 = Die(20) mix = Pmf() for die in [d6, d8, d12, d16, d20]: for outcome, prob in die.Items(): mix.Incr(outcome, prob) mix.Normalize() thinkplot.PrePlot(1) thinkplot.Pmf(mix) thinkplot.Save(root='dice_Mix_self1', xlabel='sum of dice', ylabel='Probability', formats=['pdf'])
# introducing pmf. pmf = Pmf() for x in [1, 2, 3, 4, 5, 6]: pmf.Set(x, 1./6) # re-introducing pmf. word_list = ['atirei', 'o', 'pau', 'atirei', 'gato', 'gato'] pmf = Pmf() for word in word_list: pmf.Incr(word, 1) pmf.Normalize() print(pmf.Prob('gato')) # the cookie problemm pmf = Pmf() pmf.Set("bowl 1", .5) pmf.Set("bowl 2", .5)