Ticket #1118: lasso_lbfgs.diff

File lasso_lbfgs.diff, 1.4 KB (added by lanz, 2 years ago)

Another optimization function. Note that the parameter t here is not the same as before.

  • Orange/regression/lasso.py

    diff --git a/Orange/regression/lasso.py b/Orange/regression/lasso.py
    a b  
    6666    """ 
    6767 
    6868    def __init__(self, name='lasso regression', t=1, s=None, tol=0.001, \ 
    69                  n_boot=100, n_perm=100, imputer=None, continuizer=None): 
     69                 n_boot=0, n_perm=0, imputer=None, continuizer=None): 
    7070        """ 
    7171        :param name: name of the linear model, default 'lasso regression' 
    7272        :type name: string 
     
    139139        import scipy.optimize 
    140140 
    141141        # objective function to be minimized 
    142         objective = lambda beta: numpy.linalg.norm(y - numpy.dot(X, beta)) 
     142        objective = lambda beta: (numpy.sum((y - numpy.dot(X, beta)) ** 2) + 
     143                                  t * numpy.linalg.norm(beta, 1)) 
    143144        # initial guess for the regression parameters 
    144         beta_init = numpy.random.random(m) 
    145         # constraints for the regression coefficients 
    146         cnstr = lambda beta: t - numpy.sum(numpy.abs(beta)) 
     145        beta_init = numpy.zeros(m) 
    147146        # optimal solution 
    148         coefficients = scipy.optimize.fmin_cobyla(objective, beta_init, cnstr, iprint=0) 
    149  
     147        coefficients, val, _ = scipy.optimize.fmin_l_bfgs_b(objective, 
     148            beta_init, approx_grad=1, disp=0) 
    150149        # set small coefficients to 0 
    151150        def set_2_0(c): return c if abs(c) > self.tol else 0 
    152151        coefficients = numpy.array(map(set_2_0, coefficients))