Skip to content
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (32 sloc) 1.15 KB
from import buildNetwork
from pybrain.supervised.trainers import BackpropTrainer
class neuralnet:
def __init__(self, *args):
if len(args) >=2 :
self.nnet = buildNetwork(*args)
self.inputdimension = args[0]
self.outputdimension = args[len(args)-1]
print self.nnet
print "Number of layers must be greater than or equal to two\n"
# Loads the training data into neural network before training.
def loadTrainingData(self, trainingdataset):
if trainingdataset.getDimension('input') == self.inputdimension and \
trainingdataset.getDimension('target') == self.outputdimension:
self.trainer = BackpropTrainer(self.nnet, trainingdataset)
return 1
print "Dataset-Network size mismatch\n"
return 0
# Train the neural network 'n' times with loaded training data.
def teach(self, n):
for i in range (1, n+1):
print self.trainer.train()
# Activate the Neural Network with test data. Returns calculated output.
def activate(self, testdata):
if testdata.size == self.inputdimension:
return self.nnet.acivate(testdata)
print "Test data error\n"
return 0
Jump to Line
Something went wrong with that request. Please try again.