
    =h<                       S r SSKJr  SSKJrJrJr  SSKJr  SSK	J
r
  SSKrSSKJr  SS jrS	 r " S
 S5      r   SS jr   SS jr   SS jr  SS jr   SS jr   SS jr   SS jr   SS jr   SS jrg)z
Functions that are general enough to use for any model fitting. The idea is
to untie these from LikelihoodModel so that they may be re-used generally.
    )annotations)SP_LT_15SP_LT_17	SP_LT_116)Sequence)AnyN)optimizec           
        [        [        U R                  5       5      5      R                  [        U5      5      nU(       aC  SS KnUR                  SU SSR                  U5       SSR                  U5       S3[        5        g g )Nr   zzKeyword arguments have been passed to the optimizer that have no effect. The list of allowed keyword arguments for method z is: z, z<. The list of unsupported keyword arguments passed include: z&. After release 0.14, this will raise.)setlistkeys
differencewarningswarnjoinFutureWarning)kwargsallowedmethodextrar   s        mC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/base/optimizer.pycheck_kwargsr      s|    V[[]#$//W>EKheDIIg./ 011551A0B C--
 	
     c                .    X;  a  SU -  n[        U5      eg )NzUnknown fit method %s)
ValueError)r   methodsmessages      r   _check_methodr      s"    )F2!! r   c                  .    \ rS rSr  SS jrS rS rSrg)	Optimizer%   Nc                   UR                  S[        5       5      n/ SQnXR                  5       -  nUR                  5       n[	        X~5        [
        [        [        [        [        [        [        [        [        S.	nU(       a  UR                  U5        X   nU" XX4UXUXUS9u  nnXsXXUXS.	nUR                  U5        UUU4$ )a  
Fit function for any model with an objective function.

Parameters
----------
objective : function
    Objective function to be minimized.
gradient : function
    The gradient of the objective function.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
hessian : str, optional
    Method for computing the Hessian matrix, if applicable.
method : str {'newton','nm','bfgs','powell','cg','ncg','basinhopping',
    'minimize'}
    Method can be 'newton' for Newton-Raphson, 'nm' for Nelder-Mead,
    'bfgs' for Broyden-Fletcher-Goldfarb-Shanno, 'powell' for modified
    Powell's method, 'cg' for conjugate gradient, 'ncg' for Newton-
    conjugate gradient, 'basinhopping' for global basin-hopping
    solver, if available or a generic 'minimize' which is a wrapper for
    scipy.optimize.minimize. `method` determines which solver from
    scipy.optimize is used. The explicit arguments in `fit` are passed
    to the solver, with the exception of the basin-hopping solver. Each
    solver has several optional arguments that are not the same across
    solvers. See the notes section below (or scipy.optimize) for the
    available arguments and for the list of explicit arguments that the
    basin-hopping solver supports..
maxiter : int
    The maximum number of iterations to perform.
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.
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.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
optim_settings : dict
    A dictionary that contains the parameters passed to the solver.

Notes
-----
The 'basinhopping' solver ignores `maxiter`, `retall`, `full_output`
explicit arguments.

Optional arguments for the solvers (available in Results.mle_settings)::

    'newton'
        tol : float
            Relative error in params acceptable for convergence.
    'nm' -- Nelder Mead
        xtol : float
            Relative error in params acceptable for convergence
        ftol : float
            Relative error in loglike(params) acceptable for
            convergence
        maxfun : int
            Maximum number of function evaluations to make.
    'bfgs'
        gtol : float
            Stop when norm of gradient is less than gtol.
        norm : float
            Order of norm (np.inf is max, -np.inf is min)
        epsilon
            If fprime is approximated, use this value for the step
            size. Only relevant if LikelihoodModel.score is None.
    'lbfgs'
        m : int
            The maximum number of variable metric corrections used to
            define the limited memory matrix. (The limited memory BFGS
            method does not store the full hessian but uses this many
            terms in an approximation to it.)
        pgtol : float
            The iteration will stop when
            ``max{|proj g_i | i = 1, ..., n} <= pgtol`` where pg_i is
            the i-th component of the projected gradient.
        factr : float
            The iteration stops when
            ``(f^k - f^{k+1})/max{|f^k|,|f^{k+1}|,1} <= factr * eps``,
            where eps is the machine precision, which is automatically
            generated by the code. Typical values for factr are: 1e12
            for low accuracy; 1e7 for moderate accuracy; 10.0 for
            extremely high accuracy. See Notes for relationship to
            ftol, which is exposed (instead of factr) by the
            scipy.optimize.minimize interface to L-BFGS-B.
        maxfun : int
            Maximum number of iterations.
        epsilon : float
            Step size used when approx_grad is True, for numerically
            calculating the gradient
        approx_grad : bool
            Whether to approximate the gradient numerically (in which
            case func returns only the function value).
    'cg'
        gtol : float
            Stop when norm of gradient is less than gtol.
        norm : float
            Order of norm (np.inf is max, -np.inf is min)
        epsilon : float
            If fprime is approximated, use this value for the step
            size. Can be scalar or vector.  Only relevant if
            Likelihoodmodel.score is None.
    'ncg'
        fhess_p : callable f'(x,*args)
            Function which computes the Hessian of f times an arbitrary
            vector, p.  Should only be supplied if
            LikelihoodModel.hessian is None.
        avextol : float
            Stop when the average relative error in the minimizer
            falls below this amount.
        epsilon : float or ndarray
            If fhess is approximated, use this value for the step size.
            Only relevant if Likelihoodmodel.hessian is None.
    'powell'
        xtol : float
            Line-search error tolerance
        ftol : float
            Relative error in loglike(params) for acceptable for
            convergence.
        maxfun : int
            Maximum number of function evaluations to make.
        start_direc : ndarray
            Initial direction set.
    'basinhopping'
        niter : int
            The number of basin hopping iterations.
        niter_success : int
            Stop the run if the global minimum candidate remains the
            same for this number of iterations.
        T : float
            The "temperature" parameter for the accept or reject
            criterion. Higher "temperatures" mean that larger jumps
            in function value will be accepted. For best results
            `T` should be comparable to the separation (in function
            value) between local minima.
        stepsize : float
            Initial step size for use in the random displacement.
        interval : int
            The interval for how often to update the `stepsize`.
        minimizer : dict
            Extra keyword arguments to be passed to the minimizer
            `scipy.optimize.minimize()`, for example 'method' - the
            minimization method (e.g. 'L-BFGS-B'), or 'tol' - the
            tolerance for termination. Other arguments are mapped from
            explicit argument of `fit`:
            - `args` <- `fargs`
            - `jac` <- `score`
            - `hess` <- `hess`
    'minimize'
        min_method : str, optional
            Name of minimization method to use.
            Any method specific arguments can be passed directly.
            For a list of methods and their arguments, see
            documentation of `scipy.optimize.minimize`.
            If no method is specified, then BFGS is used.
extra_fit_funcs)	newtonnmbfgslbfgspowellcgncgbasinhoppingminimize)	r$   r%   r&   r'   r)   r*   r(   r+   r,   )dispmaxitercallbackretallfull_outputhess)		optimizerstart_paramsr.   r1   r-   fargsr/   r0   r#   )getdictr   lowerr   _fit_newton_fit_nm	_fit_bfgs
_fit_lbfgs_fit_cg_fit_ncg_fit_powell_fit_basinhopping_fit_minimizeupdate)self	objectivegradientr4   r5   r   hessianr   r.   r1   r-   r/   r0   r#   r   	fit_funcsfuncxoptretvalsoptim_settingss                       r   _fitOptimizer._fit&   s    j !**%6?/''))f& "!-%

	 _- Y,v"&($*")+g
 (.%,"&H$*P 	f%Wn,,r   c                    [         e)z
TODO: how to add constraints?

Something like
sm.add_constraint(Model, func)

or

model_instance.add_constraint(func)
model_instance.add_constraint("x1 + x2 = 2")
result = model_instance.fit()
NotImplementedErrorrC   paramss     r   _fit_constrainedOptimizer._fit_constrained  s
     "!r   c                    [         eNrO   rQ   s     r   _fit_regularizedOptimizer._fit_regularized  s
    
 "!r    )Nr$   d   TTNF)__name__
__module____qualname____firstlineno__rL   rS   rW   __static_attributes__rY   r   r   r    r    %   s    EI.3Z-x""r   r    c                   UR                  SS5        / SQnUR                  5        VVs0 s H  u  pX;  d  M  X_M     nnnX^S'   XnS'   / SQn/ SQnUS   U;   a  Sn
US   U;   a  Sn/ S	Qn[        (       d  US
/-  n[        (       d  US/-  n/ SQnSUR	                  5       ;   a  US   U;   a  US   nOSnSUR	                  5       ;   a  US   U;   a  US   nOSn[
        R                  " XX4S   XUUX~S9
nUR                  nSnU	(       as  [        US[        R                  5      nUR                  UUR                  UR                  UR                  S.nU(       a!  UR                  SUR!                  5       05        UU4$ s  snnf )a  
Fit using scipy minimize, where kwarg `min_method` defines the algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.

min_methodBFGS)r#   niterra   tolboundsconstraintsr-   r.   )Nelder-MeadPowellCGrb   COBYLASLSQP)rg   rh   rj   N)L-BFGS-BTNCrk   trust-constrrh   rg   )rj   rk   rn   re   rf   rY   )argsr   jacr2   re   rf   r/   optionsnitfopt
iterationsfcallswarnflag	convergedallvecs)
setdefaultitemsr   r   r   r	   r,   xgetattrnpnanfunnfevstatussuccessrB   values)fscorer4   r5   r   r-   r.   r/   r0   r1   r2   filter_optskvrq   no_hessno_jac
has_boundshas_constraintsre   rf   resrI   rJ   rr   s                            r   rA   rA     s   ^ lF+ ]K &G!2FtqtGGFO I IG0Flw&lv% >J8xj 
8}o%
9O6;;= VL%9Z%G!%&*>/*Q]+


A%|@T %[%-@C 55DGc5"&&)77# XX3:: #- NNIszz|45=] Hs
   FFc                   [        USS5        UR                  SS5      nUR                  SS5      nSn[        R                  n[        R                  " U5      nU(       a  X/nX:  Ga,  [        R
                  " [        R                  " UU-
  5      U:  5      (       a  [        R                  " U
" U5      5      n[        R                  " US:H  5      (       d.  U[        R                  " UR                  S   5      ==   U-  ss'   UnU[        R                  R                  UU" U5      5      -
  nU(       a  WR                  U5        Ub  U" U5        US	-  nX:  a7  [        R
                  " [        R                  " UU-
  5      U:  5      (       a  M  U " U/UQ76 nX:X  a1  S	nU(       a'  [        S
5        [        SU-  5        [        SU-  5        O0SnU(       a'  [        S5        [        SU-  5        [        SU-  5        U	(       aL  X" U/UQ76 X" U5      U
" U5      4u  nnnnnU(       + nUUUUUUS.nU(       a  UR                  SW05        UU4$ UnSnUU4$ )a#  
Fit using Newton-Raphson algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.
ridge_factor : float
    Regularization factor for Hessian matrix.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
)rd   ridge_factorr$   rd   g:0yE>r   绽|=r   N   z8Warning: Maximum number of iterations has been exceeded.z#         Current function value: %fz         Iterations: %dz%Optimization terminated successfully.z         Iterations %d)rt   ru   r   Hessianrw   rx   ry   )r   rz   r~   infasarrayanyabsalldiag_indicesshapelinalgsolveappendprintrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   rd   ru   	oldparams	newparamshistoryHfvalrw   rI   rt   rc   gopthoptrx   rJ   s                              r   r9   r9     sb   b 0(;


E4
(C$$^U;LJI

<(I(BFF266)2;3< ,=?B,C %D %DJJtI' vvla'((booaggaj)*l:*			53C DD	NN9%Ya
 BFF266)2;3< ,=?B,C %D %D YD  7$>?+j899:7$>?*Z78!1Y#7#7"E)$4Y)	tU	t !L	ut" )+ NNIw/0 = =r   c                   [        USS5        UR                  SS5      nUR                  S[        R                  5      nUR                  SS5      n[        R
                  " XXXUXiXXUS9nU	(       aK  U(       d  Uu  nnnnnnnOUu  nnnnnnnnU(       + nUUUUUUUS	.nU(       a  UR                  S
W05        X4$ UnSnX4$ )a  
Fit using Broyden-Fletcher-Goldfarb-Shannon algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
gtolnormepsilonr&   r   h㈵>r   r         P>)	ro   r   r   r   r.   r1   r-   r0   r/   )rt   r   Hinvrv   gcallsrw   rx   ry   N)r   rz   r~   r   r	   	fmin_bfgsrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   r   rJ   rI   rt   r   r   rv   r   rw   ry   rx   s                           r   r;   r;     s    ^ 4f=V%;<DVRVV,D	+ABG  %&*w)0&*HNG ?F<D$dFFH +2(T4tVXw L	t#vi9 NNIw/0
 = =r   c                  ^ [        USS5        UR                  SS/[        U5      -  5      nUR                  SS5        SnU Vs0 s H  oU;   d  M
  XU   _M     nnUR                  SS	5      nUR                  S
S5      mUR                  SS5      nU(       a  SnU(       a  U(       d  [	        S5      eU(       a  T(       a  [	        S5      eT(       a  U4S jnOU(       a  U nXS'   O	U(       a  U nUR                  5       n[        (       a  UUS'   [        R                  " WU4UUUUS.UD6nU	(       a,  Uu  nnnUS   nUS:H  nUS   nUS   nUS   nUUUUUUS.nUU4$ US   nSnUU4$ s  snf )a  
Fit using Limited-memory Broyden-Fletcher-Goldfarb-Shannon algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.

Notes
-----
Within the mle part of statsmodels, the log likelihood function and
its gradient with respect to the parameters do not have notationally
consistent sign.
)	mpgtolfactrmaxfunr   approx_gradre   loglike_and_scoreiprintr'   re   )NNr   r   )r   r   r   r   r   r   r   Fr   Nr   zRa finite-differences epsilon was provided even though we are not using approx_gradzagradient approximation was requested even though an analytic loglike_and_score function was givenc                6   > [        S T" U /UQ76  5       5      $ )Nc              3  &   #    U  H  o* v   M	     g 7frV   rY   ).0r|   s     r   	<genexpr>/_fit_lbfgs.<locals>.<lambda>.<locals>.<genexpr>  s     "H/G!2/Gs   )tuple)par   s     r   <lambda>_fit_lbfgs.<locals>.<lambda>  s    U"H/@/GQ/G"HHr   fprimer-   )r.   r/   ro   re   rw   gradfuncallsrr   )rt   r   rv   rw   rx   ru   )	r   rz   lenr6   r   copyr   r	   fmin_l_bfgs_b)r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   re   namesr|   extra_kwargsr   r   rH   extended_kwargsrJ   rI   rt   drw   rx   r   rv   ru   r   s                               @r   r<   r<   3  s   h l x,#l:K)KLF
h"
 HE*/?%Q;LAayL%L? **]E2K

#6=jjD)G  { D E 	E( % & 	& H	!&X	"'')Oy $$$  G dA
 Z=]	y:uX
'i!+- = qz=E @s   	E/	E/c                b   [        USS5        UR                  SS5      nUR                  SS5      nUR                  SS5      n[        R                  " XX;XUXUUS9nU	(       aE  U(       d	  Uu  nnnnnO	Uu  nnnnnnU(       + nUUUUUS	.nU(       a  UR	                  S
W05        X4$ UnSnX4$ )a  
Fit using Nelder-Mead algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
)xtolftolr   r%   r   -C6?r   r   N)	ro   r   r   r.   r   r1   r-   r0   r/   rs   ry   )r   rz   r	   fminrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   r   rJ   rI   rt   rc   rv   rw   ry   rx   s                         r   r:   r:     s    ^ 3T:VV,DVV,Dx.FmmA%!%v(3v%-/G 29/D$vx;B8D$vx L	u# )+ NNIw/0
 = =r   c                |   [        USS5        UR                  SS5      nUR                  S[        R                  5      nUR                  SS5      n[        R
                  " XXUXXXS9nU	(       aE  U(       d	  Uu  nnnnnO	Uu  nnnnnnU(       + nUUUUUS	.nU(       a  UR                  S
W05        X4$ UnSnX4$ )a  
Fit using Conjugate Gradient algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
r   r)   r   r   r   r   r   )r   r   r   r.   r1   r-   r0   r/   )rt   rv   r   rw   rx   ry   N)r   rz   r~   r   r	   fmin_cgrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   r   rJ   rI   rt   rv   r   rw   ry   rx   s                         r   r=   r=     s    ^ 4d;V%;<DVRVV,D	+ABGqt'.+6&,AG 3:0D$<C9D$' L	6V'iANNIw/0 = =r   c                h   [        USS5        UR                  SS5      nUR                  SS5      nUR                  SS5      n[        R                  " XXXUXXXS	9nU	(       aH  U(       d
  Uu  nnnnnnO
Uu  nnnnnnnU(       + nUUUUUUS
.nU(       a  UR	                  SW05        X4$ UnSnX4$ )a  
Fit using Newton Conjugate Gradient algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
)fhess_pavextolr   r*   r   Nr   r   r   r   )
r   fhessro   r   r   r.   r1   r-   r0   r/   )rt   rv   r   hcallsrw   rx   ry   )r   rz   r	   fmin_ncgrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   r   rJ   rI   rt   rv   r   r   rw   ry   rx   s                          r   r>   r>   K  s    ^ :EB	40G	+ABG	+ABG&*(/,7'-	BG
 ;B8D$  BD$' L	6V# )+ NNIw/0
 = =r   c                   [        USS5        UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      n[        R                  " XX;XUXXUS	9nU	(       aI  U(       d
  Uu  nnnnnnO
Uu  nnnnnnnU(       + nUUUUUUS
.nU(       a  UR	                  SW05        UU4$ UnSnUU4$ )a  
Fit using Powell's conjugate direction algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
)r   r   r   start_direcr(   r   r   r   r   Nr   )
ro   r   r   r.   r   r1   r-   r0   r/   direc)rt   r   ru   rv   rw   rx   ry   )r   rz   r	   fmin_powellrB   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   r   r   rJ   rI   rt   r   rc   rv   rw   ry   rx   s                           r   r?   r?     s   ^ BHMVV,DVV,Dx.F##M48K""1(,f/:*0)4	6G
 9@6D$ufh  @D$ufh L	%u# )+ NNIw/0
 = =r   c                   [        USS5        UR                  5        VVs0 s H  u  pX_M	     nnnUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S
5      nUR                  SS5      nUR                  S5      nUR                  S0 5      nUUS'   UUS'   UR                  SS5      nU(       a  US:w  a  U
US'   [        R
                  " XUXUUUUUUS9nUR                  nU	(       a9  UR                  UR                  UR                  SUR                  S   ;   S.nUU4$ SnUU4$ s  snnf )a  
Fit using Basin-hopping algorithm.

Parameters
----------
f : function
    Returns negative log likelihood given parameters.
score : function
    Returns gradient of negative log likelihood with respect to params.
start_params : array_like, optional
    Initial guess of the solution for the loglikelihood maximization.
    The default is an array of zeros.
fargs : tuple
    Extra arguments passed to the objective function, i.e.
    objective(x,*args)
kwargs : dict[str, Any]
    Extra keyword arguments passed to the objective function, i.e.
    objective(x,**kwargs)
disp : bool
    Set to True to print convergence messages.
maxiter : int
    The maximum number of iterations to perform.
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.
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.
hess : str, optional
    Method for computing the Hessian matrix, if applicable.

Returns
-------
xopt : ndarray
    The solution to the objective function
retvals : dict, None
    If `full_output` is True then this is a dictionary which holds
    information returned from the solver used. If it is False, this is
    None.
)rc   niter_successTstepsizeinterval	minimizerseedr+   rc   rZ   r   Nr   g      ?r   g      ?r   2   r   r   ro   rp   r   rl   r2   )	minimizer_kwargsrc   r   r   r   r-   r/   r   r   zcompleted successfullyr   )rt   ru   rv   rx   )r   r{   rz   r6   r	   r+   r|   r   rr   r   r   )r   r   r4   r5   r   r-   r.   r/   r0   r1   r2   r   r   rc   r   r   r   r   r   r   r   rJ   rI   s                          r   r@   r@     sp   ^ T
  &||~.~tqad~F.gs+E%%ot<M#s#A  S1H  R0H::fDzz+r2$V#U!!(D1F&J&#' ##A5E*/&'(-5)-/G 99DKK!++ll1W__Q5GG	
 = =? /s   E)r   zdict[str, Any]r   zSequence[str]r   str)TrZ   NFTN)TrZ   NFTNr   )__doc__
__future__r   statsmodels.compat.scipyr   r   r   collections.abcr   typingr   numpyr~   scipyr	   r   r   r    rA   r9   r;   r<   r:   r=   r>   r?   r@   rY   r   r   <module>r      s    # B B $   
"q" q"p ?C5:)-aH =A38:?eP ;?16%)GT JMCGCL 9=/4#'FR 9=/4#'FR :>05$(HV =A38'+IX CG9>-1Sr   