#NEWLINE# def fit_l1_slsqp( f , score , start_params , args , kwargs , disp = False , maxiter = 1000 , callback = None , retall = False , full_output = False , hess = None ) : #NEWLINE# #INDENT# '\n    Solve the l1 regularized problem using scipy.optimize.fmin_slsqp().\n\n    Specifically:  We convert the convex but non-smooth problem\n\n    .. math:: \\min_\\beta f(\\beta) + \\sum_k\\alpha_k |\\beta_k|\n\n    via the transformation to the smooth, convex, constrained problem in twice\n    as many variables (adding the "added variables" :math:`u_k`)\n\n    .. math:: \\min_{\\beta,u} f(\\beta) + \\sum_k\\alpha_k u_k,\n\n    subject to\n\n    .. math:: -u_k \\leq \\beta_k \\leq u_k.\n\n    Parameters\n    ----------\n    All the usual parameters from LikelhoodModel.fit\n    alpha : non-negative scalar or numpy array (same size as parameters)\n        The weight multiplying the l1 penalty term\n    trim_mode : \'auto, \'size\', or \'off\'\n        If not \'off\', trim (set to zero) parameters that would have been zero\n            if the solver reached the theoretical minimum.\n        If \'auto\', trim params using the Theory above.\n        If \'size\', trim params if they have very small absolute value\n    size_trim_tol : float or \'auto\' (default = \'auto\')\n        For use when trim_mode === \'size\'\n    auto_trim_tol : float\n        For sue when trim_mode == \'auto\'.  Use\n    qc_tol : float\n        Print warning and don\'t allow auto trim when (ii) in "Theory" (above)\n        is violated by this much.\n    qc_verbose : Boolean\n        If true, print out a full QC report upon failure\n    acc : float (default 1e-6)\n        Requested accuracy as used by slsqp\n    ' #NEWLINE# start_params = np . array ( start_params ) . ravel ( 'F' ) #NEWLINE# k_params = len ( start_params ) #NEWLINE# x0 = np . append ( start_params , np . fabs ( start_params ) ) #NEWLINE# alpha = np . array ( kwargs [ 'alpha_rescaled' ] ) . ravel ( 'F' ) #NEWLINE# alpha = ( alpha * np . ones ( k_params ) ) #NEWLINE# assert ( alpha . min ( ) >= 0 ) #NEWLINE# disp_slsqp = _get_disp_slsqp ( disp , retall ) #NEWLINE# acc = kwargs . setdefault ( 'acc' , 1e-10 ) #NEWLINE# func = ( lambda x_full : _objective_func ( f , x_full , k_params , alpha , * args ) ) #NEWLINE# f_ieqcons_wrap = ( lambda x_full : _f_ieqcons ( x_full , k_params ) ) #NEWLINE# fprime_wrap = ( lambda x_full : _fprime ( score , x_full , k_params , alpha ) ) #NEWLINE# fprime_ieqcons_wrap = ( lambda x_full : _fprime_ieqcons ( x_full , k_params ) ) #NEWLINE# results = fmin_slsqp ( func , x0 , f_ieqcons = f_ieqcons_wrap , fprime = fprime_wrap , acc = acc , iter = maxiter , disp = disp_slsqp , full_output = full_output , fprime_ieqcons = fprime_ieqcons_wrap ) #NEWLINE# params = np . asarray ( results [ 0 ] [ : k_params ] ) #NEWLINE# qc_tol = kwargs [ 'qc_tol' ] #NEWLINE# qc_verbose = kwargs [ 'qc_verbose' ] #NEWLINE# passed = l1_solvers_common . qc_results ( params , alpha , score , qc_tol , qc_verbose ) #NEWLINE# trim_mode = kwargs [ 'trim_mode' ] #NEWLINE# size_trim_tol = kwargs [ 'size_trim_tol' ] #NEWLINE# auto_trim_tol = kwargs [ 'auto_trim_tol' ] #NEWLINE# ( params , trimmed ) = l1_solvers_common . do_trim_params ( params , k_params , alpha , start_params , passed , trim_mode , size_trim_tol , auto_trim_tol ) #NEWLINE# if full_output : #NEWLINE# #INDENT# ( x_full , fx , its , imode , smode ) = results #NEWLINE# fopt = func ( np . asarray ( x_full ) ) #NEWLINE# converged = ( 'True' if ( imode == 0 ) else smode ) #NEWLINE# iterations = its #NEWLINE# gopt = float ( 'nan' ) #NEWLINE# hopt = float ( 'nan' ) #NEWLINE# retvals = { #NEWLINE# #INDENT# 'fopt' : fopt , #NEWLINE# 'converged' : converged , #NEWLINE# 'iterations' : iterations , #NEWLINE# 'gopt' : gopt , #NEWLINE# 'hopt' : hopt , #NEWLINE# 'trimmed' : trimmed , #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# if full_output : #NEWLINE# #INDENT# return ( params , retvals ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return params