def retrieveEstimationError(self,x,target): #setting number of inputs and number of outputs in the neural network _ , xColumns = x.shape _ , targetColumns = target.shape self.neuralNetwork.n_in = xColumns self.neuralNetwork.n_out = targetColumns self.neuralNetwork.initialize_weights() self.neuralNetwork.backpropagation(x,target,maxIterations=self.maxIterations) # Network result after training estimation = self.neuralNetwork.feed_forward(x) estimationError = EstimationError(estimatedValues=estimation,targetValues=target) estimationError.computeErrors() totalError = estimationError.getTotalError() return totalError
target = numpy.array([[0] ,[1] ,[1] ,[0]]) #setting number of inputs and number of outputs in the neural network _ , xColumns = x.shape _ , targetColumns = target.shape neuralNetwork = NeuralNetwork(learning_rate=0.1,n_in=xColumns,n_hidden=2,n_out=targetColumns,activation='tanh',momentum=0.9) neuralNetwork.initialize_weights() neuralNetwork.backpropagation(x,target,maxIterations=10000, batch=False) # Network result after training estimation = neuralNetwork .feed_forward(x) printSeparator = "----------------" print "Estimated values:" print estimation print printSeparator print "Target values:" print target print printSeparator estimationError = EstimationError(estimatedValues=estimation,targetValues=target) estimationError.computeErrors() totalError = estimationError.getTotalError() print "Total Error: %s" %(totalError)