Backpropagation neural net (all steps). Create data and train.
Code: "neural_net_all.py". Programming language: Python DMelt Version 1. Last modified: 10/24/2015. License: Pro
https://datamelt.org/code/cache/neural_net_all_4865.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.


# (c) Chekanov

from java.util import Random
from jhplot  import *
from jhplot.io import *


# creating simple data with 3 inputs
fin=PND('Input Data'); out=PND('Output value')
r= Random()
for i in range(200):    
    x1=0.4*r.nextDouble()+0.2    
    x2=0.5*r.nextDouble()
    x3=1/(r.nextDouble()+1)
    fin.add([x1,x2,x3])    # 3 values with input
    out.add([x1+x2/x3])    # 1 output from 3 inputs
d={'input':fin,'out':out}
Serialized.write(d,'data.jser') # serialize data into a file


net = HNeuralNet() # create a neural net 
net.addFeedForwardLayer(3)
net.addFeedForwardLayer(5)
net.addFeedForwardLayer(1) # output layer 
net.reset()
net.save("test.eg")
net.showNetwork()


# get data back from the file
d=IO.read('data.jser')
input=d['input'].getRows('input',0,100)
out=d['out'].getRows('result',0,100)
net = HNeuralNet()
net.read("test.eg") # read NN from a file 

# train data
net.setData(input, out)
print net.trainBackpropagation(1,30000,0.002,0.02,0.0001)

print "Epoch error=",net.getEpochError()
net.save("test.eg")
net.showNetwork()

Ads help maintain this website.