Ejemplo n.º 1
0
height_parameters=GaussParameters(-0.1,{age:1},0.3)
height.set_density_parameters(height_parameters)

#Semantics: At small age: low alpha, high beta -> skew to the left: thin plants
#            At higher age: high alpha, low beta -> skew to the right: thick plants
diameter_parameters=BetaParameters(-10.0,{age:4.0},10.0,{age:-4.0})
diameter.set_density_parameters(diameter_parameters)


mcmc_ask=MCMC(bn,1000,convergence_test=ConvergenceTestSimpleCounting(500))


print "------PriorMarginal:------"


pm=mcmc_ask.calculate_PriorMarginal([age],NDGauss)
print pm
print "Ground truth: mu=0.5 C=[0.25]"
pm=mcmc_ask.calculate_PriorMarginal([height],NDGauss)
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)
Ejemplo n.º 2
0
#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)
print "Ground truth=[0.2, 0.8]\n"

print "-------MAP:-------"
hyp = mcmc_ask.calculate_MAP([alarm], evidence, ProbabilityTable)
print "MAP(alarm|burglary=intruder)=" + str(hyp)
print "Ground truth=\"Ringing\"\n"

hyp = mcmc_ask.calculate_MAP([burglary, alarm], {}, ProbabilityTable)
print "MAP(burglary,alarm)=" + str(hyp)
print "Ground truth=\"Safe\",\"Silent\"\n"
Ejemplo n.º 3
0
print "EarthquakeFT: " + str(factorTree.calculate_marginal([earthquake]))








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))
Ejemplo n.º 4
0
print "EarthquakeFT: " + str(factorTree.calculate_marginal([earthquake]))








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))
Ejemplo n.º 5
0
#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)
print "Ground truth=[0.2, 0.8]\n"

print "-------MAP:-------"
hyp=mcmc_ask.calculate_MAP([alarm],evidence,ProbabilityTable)
print "MAP(alarm|burglary=intruder)=" + str(hyp)
print "Ground truth=\"Ringing\"\n"

hyp=mcmc_ask.calculate_MAP([burglary,alarm],{},ProbabilityTable)
print "MAP(burglary,alarm)="+str(hyp)
print "Ground truth=\"Safe\",\"Silent\"\n"