support/models.py
def l_imp(self, w, X, y, lam_l1=0, lam_l2=0):
        '''
        Implementation of (regularized) squared error as
        loss function under a linear model.
        '''
        # 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 1) losses at each point.

        # Compute regularization terms if required.
        if lam_l1 > 0:
            l1reg = lam_l1 * np.sum(np.abs(w)) # l1 norm
        else:
            l1reg = 0
        if lam_l2 > 0:
            l2reg = lam_l2 * np.sum(w*w) # squared l2
        else:
            l2reg = 0

        return (np.dot(X,w)-y)**2 / 2 + l1reg + l2reg

        Implementation of (regularized) squared error as
        loss function under a linear model.
        
Implementation of (regularized) squared error as
loss function under a linear model.
Implementation of ( regularized ) squared error as loss function under a linear model .
def l_imp(self, w, X, y, lam_l1=0, lam_l2=0):
        if lam_l1 > 0:
            l1reg = lam_l1 * np.sum(np.abs(w)) 
        else:
            l1reg = 0
        if lam_l2 > 0:
            l2reg = lam_l2 * np.sum(w*w) 
        else:
            l2reg = 0
        return (np.dot(X,w)-y)**2 / 2 + l1reg + l2reg
def l_imp ( self , w , X , y , lam_l1 = 0 , lam_l2 = 0 ) : if lam_l1 > 0 : l1reg = lam_l1 * np . sum ( np . abs ( w ) ) else : l1reg = 0 if lam_l2 > 0 : l2reg = lam_l2 * np . sum ( w * w ) else : l2reg = 0 return ( np . dot ( X , w ) - y ) ** 2 / 2 + l1reg + l2reg
Implementation of (regularized) squared error as
loss function under a linear model.
Implementation of ( regularized ) squared error as loss function under a linear model .
'''
        Implementation of (regularized) squared error as
        loss function under a linear model.
        ''' # 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 1) losses at each point. # Compute regularization terms if required. # l1 norm # squared l2
self
w
X
y
lam_l1
lam_l2