support/models.py
def g_imp(self, w, X, y, lam_l1=0, lam_l2=0):
        '''
        Gradient of the above loss function.
        '''
        # Args:
        # w is a (d x 1) matrix taking real values.
        # X is a (k x d) matrix of n observations.
        # y is a (k x 1) matrix taking real values.
        # lam_* are parameters for l1/l2 regularization.
        
        # Output: (n x d) matrix of gradient vecs at each point.

        # Compute regularization terms if required.
        # note: transpose is because we need to add to all rows.
        if lam_l1 > 0:
            g_l1reg = lam_l1 * (np.sign(w)).transpose()
        else:
            g_l1reg = 0
        if lam_l2 > 0:
            g_l2reg = 2 * lam_l2 * w.transpose() # grad of squared l2 norm.
        else:
            g_l2reg = 0

        return -(y-np.dot(X,w)) * X + g_l1reg + g_l2reg

        Gradient of the above loss function.
        
Gradient of the above loss function.
Gradient of the above loss function .
def g_imp(self, w, X, y, lam_l1=0, lam_l2=0):
        if lam_l1 > 0:
            g_l1reg = lam_l1 * (np.sign(w)).transpose()
        else:
            g_l1reg = 0
        if lam_l2 > 0:
            g_l2reg = 2 * lam_l2 * w.transpose() 
        else:
            g_l2reg = 0
        return -(y-np.dot(X,w)) * X + g_l1reg + g_l2reg
def g_imp ( self , w , X , y , lam_l1 = 0 , lam_l2 = 0 ) : if lam_l1 > 0 : g_l1reg = lam_l1 * ( np . sign ( w ) ) . transpose ( ) else : g_l1reg = 0 if lam_l2 > 0 : g_l2reg = 2 * lam_l2 * w . transpose ( ) else : g_l2reg = 0 return - ( y - np . dot ( X , w ) ) * X + g_l1reg + g_l2reg
Gradient of the above loss function.
Gradient of the above loss function .
'''
        Gradient of the above loss function.
        ''' # Args: # w is a (d x 1) matrix taking real values. # X is a (k x d) matrix of n observations. # y is a (k x 1) matrix taking real values. # lam_* are parameters for l1/l2 regularization. # Output: (n x d) matrix of gradient vecs at each point. # Compute regularization terms if required. # note: transpose is because we need to add to all rows. # grad of squared l2 norm.
self
w
X
y
lam_l1
lam_l2