'Fit the model using a regularized maximum likelihood.
The regularization method AND the solver used is determined by the
argument method.
Parameters
start_params : array-like, optional
Initial guess of the solution for the loglikelihood maximization.
The default is an array of zeros.
method : \'l1\' or \'l1_cvxopt_cp\'
See notes for details.
maxiter : Integer or \'defined_by_method\'
Maximum number of iterations to perform.
If \'defined_by_method\', then use method defaults (see notes).
full_output : bool
Set to True to have all available output in the Results object\'s
mle_retvals attribute. The output is dependent on the solver.
See LikelihoodModelResults notes section for more information.
disp : bool
Set to True to print convergence messages.
fargs : tuple
Extra arguments passed to the likelihood function, i.e.,
loglike(x,*args)
callback : callable callback(xk)
Called after each iteration, as callback(xk), where xk is the
current parameter vector.
retall : bool
Set to True to return list of solutions at each iteration.
Available in Results object\'s mle_retvals attribute.
alpha : non-negative scalar or numpy array (same size as parameters)
The weight multiplying the l1 penalty term
trim_mode : \'auto, \'size\', or \'off\'
If not \'off\', trim (set to zero) parameters that would have been
zero if the solver reached the theoretical minimum.
If \'auto\', trim params using the Theory above.
If \'size\', trim params if they have very small absolute value
size_trim_tol : float or \'auto\' (default = \'auto\')
For use when trim_mode == \'size\'
auto_trim_tol : float
For sue when trim_mode == \'auto\'.  Use
qc_tol : float
Print warning and don\'t allow auto trim when (ii) (above) is
violated by this much.
qc_verbose : Boolean
If true, print out a full QC report upon failure
Notes
Extra parameters are not penalized if alpha is given as a scalar.
An example is the shape parameter in NegativeBinomial `nb1` and `nb2`.
Optional arguments for the solvers (available in Results.mle_settings)::
\'l1\'
acc : float (default 1e-6)
Requested accuracy as used by slsqp
\'l1_cvxopt_cp\'
abstol : float
absolute accuracy (default: 1e-7).
reltol : float
relative accuracy (default: 1e-6).
feastol : float
tolerance for feasibility conditions (default: 1e-7).
refinement : int
number of iterative refinement steps when solving KKT
equations (default: 1).
Optimization methodology
With :math:`L` the negative log likelihood, we solve the convex but
non-smooth problem
.. math:: \min_\beta L(\beta) + \sum_k\alpha_k |\beta_k|
via the transformation to the smooth, convex, constrained problem
in twice as many variables (adding the "added variables" :math:`u_k`)
.. math:: \min_{\beta,u} L(\beta) + \sum_k\alpha_k u_k,
subject to
.. math:: -u_k \leq \beta_k \leq u_k.
With :math:`\partial_k L` the derivative of :math:`L` in the
:math:`k^{th}` parameter direction, theory dictates that, at the
minimum, exactly one of two conditions holds:
(i) :math:`|\partial_k L| = \alpha_k`  and  :math:`\beta_k \neq 0`
(ii) :math:`|\partial_k L| \leq \alpha_k`  and  :math:`\beta_k = 0`'

def fit_regularized(self, start_params=None, method='l1', maxiter='defined_by_method', full_output=1, disp=True, callback=None, alpha=0, trim_mode='auto', auto_trim_tol=0.01, size_trim_tol=0.0001, qc_tol=0.03, qc_verbose=False, **kwargs):

    if (method in ['l1', 'l1_cvxopt_cp']):
        cov_params_func = self.cov_params_func_l1
    else:
        raise Exception(('argument    method    ==    %s,    which    is    not    handled' % method))
    alpha = np.array(alpha)
    assert (alpha.min() >= 0)
    try:
        kwargs['alpha'] = alpha
    except TypeError:
        kwargs = dict(alpha=alpha)
    kwargs['alpha_rescaled'] = (kwargs['alpha'] / float(self.endog.shape[0]))
    kwargs['trim_mode'] = trim_mode
    kwargs['size_trim_tol'] = size_trim_tol
    kwargs['auto_trim_tol'] = auto_trim_tol
    kwargs['qc_tol'] = qc_tol
    kwargs['qc_verbose'] = qc_verbose
    if (maxiter == 'defined_by_method'):
        if (method == 'l1'):
            maxiter = 1000
        elif (method == 'l1_cvxopt_cp'):
            maxiter = 70
    extra_fit_funcs = {'l1': fit_l1_slsqp}
    if (have_cvxopt and (method == 'l1_cvxopt_cp')):
        from statsmodels.base.l1_cvxopt import fit_l1_cvxopt_cp
        extra_fit_funcs['l1_cvxopt_cp'] = fit_l1_cvxopt_cp
    elif (method.lower() == 'l1_cvxopt_cp'):
        message = 'Attempt    to    use    l1_cvxopt_cp    failed    since    cvxopt    could    not    be    imported'
    if (callback is None):
        callback = self._check_perfect_pred
    else:
        pass
    mlefit = super(DiscreteModel, self).fit(start_params=start_params, method=method, maxiter=maxiter, full_output=full_output, disp=disp, callback=callback, extra_fit_funcs=extra_fit_funcs, cov_params_func=cov_params_func, **kwargs)
    return mlefit
