DMelt:AI/2 Bayesian Neural Net

From HandWiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
Member


Bayesian network

This section is devoted to the Bayesian Neural Network (also known as Bayesian belief network). It is a model for reasoning about uncertainty. See Bayesian network article.

Using GUI

Dmelt provides a GUI to perform Bayesian network. For example, here is a simple code to run such networks:

from jhplot import *

# start GUI
HBayes()

Java / Python codding

DataMelt contains Java libraries for Bayesian network using a programmatic fashion. This library uses the Encog engine from Heaton Research.

Below we show a simple Bayesian network using Java libraries and Python:

# This example is based on http://www.heatonresearch.com/
# Encog(tm) Java Examples v3.3
# http://www.heatonresearch.com/encog/
# https://github.com/encog/encog-java-examples
# http://www.apache.org/licenses/LICENSE-2.0
 
 
from org.encog.ml.bayesian import BayesianNetwork,BayesianEvent
from org.encog.ml.bayesian import EventType
from org.encog.ml.bayesian.query.enumerate import EnumerationQuery
from org.encog.ml.bayesian.query.sample import SamplingQuery
 
## build build the bayesian network structure
net=BayesianNetwork()
rained=net.createEvent("rained")
evenTemperatures=net.createEvent("temperature")
gardenGrew=net.createEvent("gardenGrew")
plentyOfCarrots=net.createEvent("carrots")
plentyOfTomatoes=net.createEvent("Tomatoes")

net.createDependency(rained, gardenGrew)
net.createDependency(evenTemperatures, gardenGrew)
net.createDependency(gardenGrew, plentyOfCarrots)
net.createDependency(gardenGrew, plentyOfTomatoes)
net.finalizeStructure()
	
# build the truth tales
rained.getTable().addLine(0.2, True)
evenTemperatures.getTable().addLine(0.5, True)
gardenGrew.getTable().addLine(0.9, True, True, True)
gardenGrew.getTable().addLine(0.7, True, False, True)
gardenGrew.getTable().addLine(0.5, True, True, False)
gardenGrew.getTable().addLine(0.1, True, False, False)
plentyOfCarrots.getTable().addLine(0.8, True, True)
plentyOfCarrots.getTable().addLine(0.2, True, False)
plentyOfTomatoes.getTable().addLine(0.6, True, True)
plentyOfTomatoes.getTable().addLine(0.1, True, False)

# validate the network
net.validate()
		
# display basic stats
print net.toString()
print "Parameter count: ", net.calculateParameterCount()
	

# query=SamplingQuery(net)	
query= EnumerationQuery(net)
query.defineEventType(rained, EventType.Evidence)
query.defineEventType(evenTemperatures, EventType.Evidence)
query.defineEventType(plentyOfCarrots, EventType.Outcome)
query.setEventValue(rained, True)
query.setEventValue(evenTemperatures, True)
query.setEventValue(plentyOfCarrots, True)
query.execute()
print query.toString()