def draw(self,inputNames = None, outputNames = None): ml.draw(self.Vs, self.W, inputNames, outputNames)
def draw(self,inputNames = None, outputNames = None): ml.draw(self.Vs+[self.W], inputNames, outputNames)
def draw(self,inputNames = None, outputNames = None): weightMatrices = [layer.W for layer in self.layers] ml.draw(weightMatrices, inputNames, outputNames)
def draw(self, inputNames = None, outputNames = None): ml.draw(self.Vs, self.W, inputNames, outputNames)
plt.legend(('Train Target','Train NN Output'),loc='lower right', prop={'size':9}) plt.subplot(nPlotRows,1,3) plt.plot(Xtest,Ttest) plt.plot(Xtest,Ytest) plt.legend(('Test Target','Test NN Output'),loc='lower right', prop={'size':9}) colors = ('blue','green','red','black','cyan','orange') for i in range(len(nnet.nhs)): plt.subplot(nPlotRows,1,i+4) plt.plot(X,Z[i]) #,color=colors[i]) plt.ylabel('Hidden Unit Outputs') plt.text(8,0, 'Layer {}'.format(i+1)) plt.subplot(nPlotRows,1,nPlotRows) ml.draw(nnet.Vs,nnet.W,['x'],['sine']) plt.draw() # Now train multiple nets to compare error for different numbers of hidden layers def experiment(hs,nReps,nIter,X,T,Xtest,Ytest): results = [] for i in range(nReps): nnet = NeuralNetwork(1,hs,1) nnet.train(X,T,weightPrecision=0,errorPrecision=0,nIterations=nIter) # print "SCG stopped after",nnet.getNumberOfIterations(),"iterations:",nnet.reason (Y,Z) = nnet.use(X, allOutputs=True) Ytest = nnet.use(Xtest) rmsetrain = np.sqrt(np.mean((Y-T)**2)) rmsetest = np.sqrt(np.mean((Ytest-Ttest)**2)) results.append([rmsetrain,rmsetest])