Bayesian networks using Encog Java and simple logic
Code: "neural_net_bayesian_k2.py". Programming language: Python DMelt Version 1. Last modified: 10/25/2015. License: Pro
https://datamelt.org/code/cache/neural_net_bayesian_k2_3952.py
To run this script using the DMelt IDE, copy the above URL link to the menu [File]→[Read script from URL] of the DMelt IDE.


# 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.data  import MLDataSet
from org.encog.ml.data.basic import BasicMLDataSet
from org.encog.ml.bayesian import BayesianNetwork,BayesianEvent
from org.encog.ml.bayesian.training import TrainBayesian;
from org.encog.ml.bayesian.training import BayesianInit;

DATA=[[1, 0, 0],[1, 1, 1],[0, 0, 1],[1, 1, 1], [0, 0, 0],
      [0, 1, 1],[1, 1, 1],[0, 0, 0],[1, 1, 1],[0, 0, 0]]

net=BayesianNetwork()
data=BasicMLDataSet(DATA,None)
net.createEvent("x1")
net.createEvent("x2")
net.createEvent("x3")
net.finalizeStructure()

train=TrainBayesian(net,data,10)
train.setInitNetwork(BayesianInit.InitEmpty)
train.iteration()

p=net.performQuery("P(+x2|+x1)") #  0.71
print "x2 probability : ",net.getEvent("x2").getTable().findLine(1, [1])
print "Calculated P(+x2|+x1): ", p
print "Final network structure: ", net.toString()

Ads help maintain this website.