(self,inputs,targets,eta,niterations)
Train the thing
Train the thing
Train the thing
def mlptrain(self,inputs,targets,eta,niterations):
        """ Train the thing """    
        # Add the inputs that match the bias node
        inputs = np.concatenate((inputs,-np.ones((self.ndata,1))),axis=1)
        change = range(self.ndata)
    
        updatew1 = np.zeros((np.shape(self.weights1)))
        updatew2 = np.zeros((np.shape(self.weights2)))
            
        for n in range(niterations):
    
            self.outputs = self.mlpfwd(inputs)

            error = 0.5*np.sum((self.outputs-targets)**2)
            if (np.mod(n,100)==0):
                print "Iteration: ",n, " Error: ",error    

            # Different types of output neurons
            if self.outtype == 'linear':
            	deltao = (self.outputs-targets)/self.ndata
            elif self.outtype == 'logistic':
            	deltao = self.beta*(self.outputs-targets)*self.outputs*(1.0-self.outputs)
            elif self.outtype == 'softmax':
                deltao = (self.outputs-targets)*(self.outputs*(-self.outputs)+self.outputs)/self.ndata 
            else:
            	print "error"
            
            deltah = self.hidden*self.beta*(1.0-self.hidden)*(np.dot(deltao,np.transpose(self.weights2)))
                      
            updatew1 = eta*(np.dot(np.transpose(inputs),deltah[:,:-1])) + self.momentum*updatew1
            updatew2 = eta*(np.dot(np.transpose(self.hidden),deltao)) + self.momentum*updatew2
            self.weights1 -= updatew1
            self.weights2 -= updatew2
def mlptrain ( self , inputs , targets , eta , niterations ) : # Add the inputs that match the bias node inputs = np . concatenate ( ( inputs , - np . ones ( ( self . ndata , 1 ) ) ) , axis = 1 ) change = range ( self . ndata ) updatew1 = np . zeros ( ( np . shape ( self . weights1 ) ) ) updatew2 = np . zeros ( ( np . shape ( self . weights2 ) ) ) for n in range ( niterations ) : self . outputs = self . mlpfwd ( inputs ) error = 0.5 * np . sum ( ( self . outputs - targets ) ** 2 ) if ( np . mod ( n , 100 ) == 0 ) : print "Iteration: " , n , " Error: " , error # Different types of output neurons if self . outtype == 'linear' : deltao = ( self . outputs - targets ) / self . ndata elif self . outtype == 'logistic' : deltao = self . beta * ( self . outputs - targets ) * self . outputs * ( 1.0 - self . outputs ) elif self . outtype == 'softmax' : deltao = ( self . outputs - targets ) * ( self . outputs * ( - self . outputs ) + self . outputs ) / self . ndata else : print "error" deltah = self . hidden * self . beta * ( 1.0 - self . hidden ) * ( np . dot ( deltao , np . transpose ( self . weights2 ) ) ) updatew1 = eta * ( np . dot ( np . transpose ( inputs ) , deltah [ : , : - 1 ] ) ) + self . momentum * updatew1 updatew2 = eta * ( np . dot ( np . transpose ( self . hidden ) , deltao ) ) + self . momentum * updatew2 self . weights1 -= updatew1 self . weights2 -= updatew2