示例#1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from thinkbayes import Pmf

pmf1 = Pmf()
for x in range(1, 6 + 1):
    pmf1.Set(x, 1 / 6.0)

pmf1.Print()

print("曲奇饼问题")
pmf2 = Pmf()
pmf2.Set('Bowl1', 0.5)
pmf2.Set('Bowl2', 0.5)

pmf2.Mult('Bowl1', 0.75)
pmf2.Mult('Bowl2', 0.5)

pmf2.Normalize()
print pmf2.Probs(pmf2.Values())
示例#2
0
from thinkbayes import Pmf

# make empty pmf
pmf = Pmf()
pmf.Set('Bowl 1', .5)  # P(Bowl 1)
pmf.Set('Bowl 2', .5)  # P(Bowl 2)
pmf.Print()

# picks vanilla cookie - update P of bowl with evidence
pmf.Mult('Bowl 1', .75)  # P(Vanilla | Bowl 1)
pmf.Mult('Bowl 2', .5)  # P(Vanilla | Bowl 2)
pmf.Print()

print pmf.Normalize()
pmf.Print()

# picks chocolate cookie - update the pmf with new evidence
pmf.Mult('Bowl 1', .25)  # P(Chocolate | Bowl 1)
pmf.Mult('Bowl 2', .5)  # P(Chocolate | Bowl 2)
pmf.Print()

print pmf.Normalize()
pmf.Print()