
    >h                     >    S r SSKrSSKJr  SSKJr  Sr    SS jrg)a  

Created on Mon Mar 18 15:48:23 2013
Author: Josef Perktold

TODO:
  - test behavior if nans or infs are encountered during the evaluation.
    now partially robust to nans, if increasing can be determined or is given.
  - rewrite core loop to use for...except instead of while.

    N)optimize)HolderFc                    XpUb  UnOUb  US:  a  [        S5      eUnOSnUb  UnO&Ub  US:  a  [        S5      eUnO[        SUS-
  5      nUc  [        XS-   5      nUb  UGc-  UGc)  X:  d   eU " U/UQ76 nU " U/UQ76 n[        R                  " [        R                  " UU-
  5      5      S:  a  US:X  a  US:X  a  S	nU " U/UQ76 nUU:  nX-
  n[        R
                  " U5      (       aB  S
 H1  nUUU-  -   nU " U/UQ76 n[        R
                  " U5      (       a  M1    O   [        S5      e[        R
                  " U5      (       aB  S
 H1  nUUU-  -   nU " U/UQ76 n[        R
                  " U5      (       a  M1    O   [        S5      eUU:  nU(       d  XpXpSnUc6  US:w  a0  UnU " U/UQ76 S:  a!  UnX-  nUU:  a  OUS-  nU " U/UQ76 S:  a  M!  Uc6  US:w  a0  UnU " U/UQ76 S:  a!  UnX-  nUU:  a  OUS-  nU " U/UQ76 S:  a  M!  UU:  aS  U " U/UQ76 nU " U/UQ76 n[        R
                  " U5      (       a&  [        R
                  " U5      (       a  [        S5      e[        R                  " XXXIUS9nU(       a]  US   n[        US   R                  US   R                  US   R                  US   R                  US   R                  UX4X4US9	nUU4$ U$ )aM	  find the root of a function in one variable by expanding and brentq

Assumes function ``func`` is monotonic.

Parameters
----------
func : callable
    function for which we find the root ``x`` such that ``func(x) = 0``
low : float or None
    lower bound for brentq
upp : float or None
    upper bound for brentq
args : tuple
    optional additional arguments for ``func``
xtol : float
    parameter x tolerance given to brentq
start_low : float (positive) or None
    starting bound for expansion with increasing ``x``. It needs to be
    positive. If None, then it is set to 1.
start_upp : float (negative) or None
    starting bound for expansion with decreasing ``x``. It needs to be
    negative. If None, then it is set to -1.
increasing : bool or None
    If None, then the function is evaluated at the initial bounds to
    determine wether the function is increasing or not. If increasing is
    True (False), then it is assumed that the function is monotonically
    increasing (decreasing).
max_it : int
    maximum number of expansion steps.
maxiter_bq : int
    maximum number of iterations of brentq.
factor : float
    expansion factor for step of shifting the bounds interval, default is
    10.
full_output : bool, optional
    If full_output is False, the root is returned. If full_output is True,
    the return value is (x, r), where x is the root, and r is a
    RootResults object.


Returns
-------
x : float
    root of the function, value at which ``func(x) = 0``.
info : RootResult (optional)
    returned if ``full_output`` is True.
    attributes:

     - start_bounds : starting bounds for expansion stage
     - brentq_bounds : bounds used with ``brentq``
     - iterations_expand : number of iterations in expansion stage
     - converged : True if brentq converged.
     - flag : return status, 'converged' if brentq converged
     - function_calls : number of function calls by ``brentq``
     - iterations : number of iterations in ``brentq``


Notes
-----
If increasing is None, then whether the function is monotonically
increasing or decreasing is inferred from evaluating the function at the
initial bounds. This can fail if there is numerically no variation in the
data in this range. In this case, using different starting bounds or
directly specifying ``increasing`` can make it possible to move the
expansion in the right direction.

If

r   zstart_upp needs to be positiveg      ?zstart_low needs to be negativeg      gV瞯<   g:0yE>)g      ?g      ?g      ?z{could not determine whether function is increasing based on starting interval.
specify increasing or change starting boundszzcould not determine whether function isincreasing based on starting interval.
specify increasing or change starting boundszsmax_it reached
the function values at boths bounds are NaN
change the starting bounds, set boundsor increase max_it)argsxtolmaxiterfull_output)	root
iterationsfunction_calls	convergedflagiterations_expandstart_boundsbrentq_bounds
increasing)
ValueErrorminmaxnpabsisnanr   brentqr   r   r   r   r   r   )funclowuppr   r	   	start_low	start_uppr   max_it
maxiter_bqfactorr   leftrightsuslf_lowf_uppdeltafractionsl_su_n_itresvalinfos                             pC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/tools/rootfinding.pybrentq_expandingr3      sh   T % 		q==>>
		q==>>b2g {"W 
#+J,>wwR$R$ 66"&&'(50R2X"'BOdOE%-J 88E?? .8e++S(4(xx	 . ! "* + + 88E??-8e++S(4(xx	 . ! "* + +
 em
BeD|a4$!#ENDv~AID 4$!# }q5 4 1$DOEv~AID 5 4 1$ v~ R$R$88E??rxx 2 3 3
 //$e#&13C !fQ1v((q600!f&&Q"-! Dy
    )NN gh㈵>NNNd   r6   
   F)	__doc__numpyr   scipyr   statsmodels.tools.testingr   DEBUGr3   r5   r4   r2   <module>r=      s/   
   , >B@D8:!&Hr4   