support/models.py
def l_imp(self, w, X, C, lam=0):
        '''
        Implementation of the multi-class logistic regression
        loss function.
        '''
        
        # Input:
        # w is a (d_para x 1) matrix of weights.
        # X is a (k x d_feat) matrix of k observations.
        # C is a (k x nc) matrix giving a binarized encoding of the
        # class labels for each observation; each row a one-hot vector.
        # lam is a non-negative regularization parameter.
        # NOTE: k can be anything, the training/test sample size.

        # Output:
        # A vector of length k with losses evaluated at k points.

        k = X.shape[0]

        # Initialize and populate the activations.
        A = np.zeros(k*self.nc).reshape( (self.nc, k) )
        A[:-1,:] = np.dot(w.reshape((self.nc-1,self.d_feat)), # reshape w.
                          np.transpose(X)) # leave last row as zeros.

        # Raw activations of all the correct weights.
        cvec = np.sum(A*np.transpose(C), axis=0)
        
        # Compute the negative log-likelihoods.
        err = np.log(np.sum(np.exp(A), axis=0)) - cvec

        # Return the losses (all data points), with penalty if needed.
        if (lam > 0):
            return err + lam * np.linalg.norm(W)**2
        else:
            return err

        Implementation of the multi-class logistic regression
        loss function.
        
Implementation of the multi-class logistic regression
loss function.
Implementation of the multi - class logistic regression loss function .
def l_imp(self, w, X, C, lam=0):
        k = X.shape[0]
        A = np.zeros(k*self.nc).reshape( (self.nc, k) )
        A[:-1,:] = np.dot(w.reshape((self.nc-1,self.d_feat)), 
                          np.transpose(X)) 
        cvec = np.sum(A*np.transpose(C), axis=0)
        err = np.log(np.sum(np.exp(A), axis=0)) - cvec
        if (lam > 0):
            return err + lam * np.linalg.norm(W)**2
        else:
            return err
def l_imp ( self , w , X , C , lam = 0 ) : k = X . shape [ 0 ] A = np . zeros ( k * self . nc ) . reshape ( ( self . nc , k ) ) A [ : - 1 , : ] = np . dot ( w . reshape ( ( self . nc - 1 , self . d_feat ) ) , np . transpose ( X ) ) cvec = np . sum ( A * np . transpose ( C ) , axis = 0 ) err = np . log ( np . sum ( np . exp ( A ) , axis = 0 ) ) - cvec if ( lam > 0 ) : return err + lam * np . linalg . norm ( W ) ** 2 else : return err
Implementation of the multi-class logistic regression
loss function.
Implementation of the multi - class logistic regression loss function .
'''
        Implementation of the multi-class logistic regression
        loss function.
        ''' # Input: # w is a (d_para x 1) matrix of weights. # X is a (k x d_feat) matrix of k observations. # C is a (k x nc) matrix giving a binarized encoding of the # class labels for each observation; each row a one-hot vector. # lam is a non-negative regularization parameter. # NOTE: k can be anything, the training/test sample size. # Output: # A vector of length k with losses evaluated at k points. # Initialize and populate the activations. # reshape w. # leave last row as zeros. # Raw activations of all the correct weights. # Compute the negative log-likelihoods. # Return the losses (all data points), with penalty if needed.
self
w
X
C
lam