Esempio n. 1
0
print pm
print ""


print "------PosteriorMarginal:------"
pm=mcmc_ask.calculate_PosteriorMarginal([age,height],{age:EvEqual(2)},NDGauss)
print "P(age,height|age=2):"
print pm
print "Ground truth: age=2, height=mu:1.9,C=0.3"
print ""

pm=mcmc_ask.calculate_PosteriorMarginal([age,height],{age:EvLower(0.1)},NDGauss)
print "P(age,height|age<0.1):"
print pm
print "Ground truth: age=0:0.1, height=mu:-0.1:0.0,C=0.3"
print ""

print "------PropabilityOfEvidence------"
poe=mcmc_ask.calculate_PoE({age:EvLower(0.347)})
print "Probabilty that age is lower than it's median:"
print "p(age<0.347)="+str(poe)
print "Ground truth=0.5"
print ""

print "------MAP------"
map_hypothesis=mcmc_ask.calculate_MAP([height,diameter],{},NDGauss)
print map_hypothesis



Esempio n. 2
0
#Parametrize the network
burglary_cpt = numpy.array([0.2, 0.8])
burglary.set_probability_table(burglary_cpt, [burglary])

alarm_cpt = numpy.array([[0.8, 0.15, 0.05], [0.05, 0.9, 0.05]])
alarm.set_probability_table(alarm_cpt, [burglary, alarm])

#Get some inference object
mcmc_ask = MCMC(bn, 5000, transition_model=GibbsTransitionModel())

#Do some Inferences
evidence = {burglary: EvEq("Intruder")}

print "-------ProbabilityOfEvidence:-------"
poe = mcmc_ask.calculate_PoE(evidence)
print "p(evidence=Intruder)=" + str(poe)
print "Ground truth=0.2\n"

print "-------PosteriorMarginal:-------"
pm = mcmc_ask.calculate_PosteriorMarginal([alarm], evidence, ProbabilityTable)
print "P(alarm|burglary=Intruder)=" + str(pm)
print "Ground truth=[0.8, 0.15, 0.05]\n"

print "-------PriorMarginal:-------"
pm = mcmc_ask.calculate_PriorMarginal([alarm], ProbabilityTable)
print "P(Alarm)= " + str(pm)
print "Ground truth=[0.2, 0.75, 0.05]\n"

pm = mcmc_ask.calculate_PriorMarginal([burglary], ProbabilityTable)
print "P(Burglary)= " + str(pm)
Esempio n. 3
0
mcmc_ask=MCMC(bn,1000)

print "====MCMC===="

print "Prior Marginal:"

print "AlarmFT: " + str(mcmc_ask.calculate_PriorMarginal([alarm],ProbabilityTable))
print "John_CallsFT: " + str(mcmc_ask.calculate_PriorMarginal([john_calls],ProbabilityTable))
print "Baum_CallsFT: " + str(mcmc_ask.calculate_PriorMarginal([baum_calls],ProbabilityTable))
print "BurglaryFT: " + str(mcmc_ask.calculate_PriorMarginal([burglary],ProbabilityTable))
print "EarthquakeFT: " + str(mcmc_ask.calculate_PriorMarginal([earthquake],ProbabilityTable))

evidences = {alarm: EvEq("Ringing"),earthquake: EvEq("Calm")}

print "PoE: " + str(mcmc_ask.calculate_PoE(evidences))

print "Posterior Marginal (alarm->ringing , earthquake->calm):"

print "AlarmFT: " + str(mcmc_ask.calculate_PosteriorMarginal([alarm],evidences,ProbabilityTable))
print "John_CallsFT: " + str(mcmc_ask.calculate_PosteriorMarginal([john_calls],evidences,ProbabilityTable))
print "Baum_CallsFT: " + str(mcmc_ask.calculate_PosteriorMarginal([baum_calls],evidences,ProbabilityTable))
print "BurglaryFT: " + str(mcmc_ask.calculate_PosteriorMarginal([burglary],evidences,ProbabilityTable))
print "EarthquakeFT: " + str(mcmc_ask.calculate_PosteriorMarginal([earthquake],evidences,ProbabilityTable))




#evidence={burglary:"Intruder"}

Esempio n. 4
0
mcmc_ask=MCMC(bn,1000)

print "====MCMC===="

print "Prior Marginal:"

print "AlarmFT: " + str(mcmc_ask.calculate_PriorMarginal([alarm],ProbabilityTable))
print "John_CallsFT: " + str(mcmc_ask.calculate_PriorMarginal([john_calls],ProbabilityTable))
print "Baum_CallsFT: " + str(mcmc_ask.calculate_PriorMarginal([baum_calls],ProbabilityTable))
print "BurglaryFT: " + str(mcmc_ask.calculate_PriorMarginal([burglary],ProbabilityTable))
print "EarthquakeFT: " + str(mcmc_ask.calculate_PriorMarginal([earthquake],ProbabilityTable))

evidences = {alarm: EvEq("Ringing"),earthquake: EvEq("Calm")}

print "PoE: " + str(mcmc_ask.calculate_PoE(evidences))

print "Posterior Marginal (alarm->ringing , earthquake->calm):"

print "AlarmFT: " + str(mcmc_ask.calculate_PosteriorMarginal([alarm],evidences,ProbabilityTable))
print "John_CallsFT: " + str(mcmc_ask.calculate_PosteriorMarginal([john_calls],evidences,ProbabilityTable))
print "Baum_CallsFT: " + str(mcmc_ask.calculate_PosteriorMarginal([baum_calls],evidences,ProbabilityTable))
print "BurglaryFT: " + str(mcmc_ask.calculate_PosteriorMarginal([burglary],evidences,ProbabilityTable))
print "EarthquakeFT: " + str(mcmc_ask.calculate_PosteriorMarginal([earthquake],evidences,ProbabilityTable))




#evidence={burglary:"Intruder"}

Esempio n. 5
0
#Parametrize the network
burglary_cpt=numpy.array([0.2,0.8])
burglary.set_probability_table(burglary_cpt, [burglary])

alarm_cpt=numpy.array([[0.8,0.15,0.05],[0.05,0.9,0.05]])
alarm.set_probability_table(alarm_cpt, [burglary,alarm])


#Get some inference object
mcmc_ask=MCMC(bn,5000,transition_model=GibbsTransitionModel())

#Do some Inferences
evidence={burglary:EvEq("Intruder")}

print "-------ProbabilityOfEvidence:-------" 
poe=mcmc_ask.calculate_PoE(evidence)
print "p(evidence=Intruder)="+str(poe)
print "Ground truth=0.2\n"

print "-------PosteriorMarginal:-------"
pm=mcmc_ask.calculate_PosteriorMarginal([alarm],evidence,ProbabilityTable)
print "P(alarm|burglary=Intruder)="+str(pm)
print "Ground truth=[0.8, 0.15, 0.05]\n"

print "-------PriorMarginal:-------"
pm=mcmc_ask.calculate_PriorMarginal([alarm],ProbabilityTable)
print "P(Alarm)= " + str(pm)
print "Ground truth=[0.2, 0.75, 0.05]\n"

pm=mcmc_ask.calculate_PriorMarginal([burglary],ProbabilityTable)
print "P(Burglary)= " + str(pm)