
    >hs                     <    S r SSKr/ SQrSS jrS rS r  S	S jrg)
z*
Linear Algebra solvers and other helpers
    N)logdet_symmstationary_solvetransf_constraintsmatrix_sqrtc                    SSK Jn  U(       a2  [        R                  " X R                  :H  5      (       d  [        S5      eUR                  U SS9u  p4S[        R                  " [        R                  " UR                  5       5      5      -  $ )z
Return log(det(m)) asserting positive definiteness of m.

Parameters
----------
m : array_like
    2d array that is positive-definite (and symmetric)

Returns
-------
logdet : float
    The log-determinant of m.
r   linalgzm is not symmetric.T)lower   )
scipyr	   npallT
ValueError
cho_factorsumlogdiagonal)m
check_symmr	   c_s        kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\statsmodels/tools/linalg.pyr   r   
   se     vva33h233Qd+DARVVBFF1::<()))    c           
         U SS nUR                   nUR                   S:X  a	  USS2S4   nUSS2SS24   n[        S[        U5      5       GH  nU SU SSS2   nXSS24   [        R                  " Xd5      -
  S[        R                  " XbSSS2   5      -
  -  nU[        R
                  " USSS2   U5      -
  n[        R                  " XSSS24   4SS9nU[        U5      S-
  :X  a    OxX   n	U	[        R                  " Xb5      -
  S[        R                  " XbSSS2   5      -
  -  nX'USSS2   -  -
  n[        R                  " U[        R                  U   45      nGM     US:X  a	  USS2S4   nU$ )a  
Solve a linear system for a Toeplitz correlation matrix.

A Toeplitz correlation matrix represents the covariance of a
stationary series with unit variance.

Parameters
----------
r : array_like
    A vector describing the coefficient matrix.  r[0] is the first
    band next to the diagonal, r[1] is the second band, etc.
b : array_like
    The right-hand side for which we are solving, i.e. we solve
    Tx = b and return b, where T is the Toeplitz coefficient matrix.

Returns
-------
The solution to the linear system.
r      N)axis)ndimrangelenr   dotouterconcatenater_)
rbdbdimxjrfazrns
             r   r   r       sa   * 
1QB
&&Cvv{agJ	!A#q&	A1c!fqVDbD\!tWrvvb}$RVVB4R4-A)ABDbD1%%NNAqz?3A
?T"&&. QttH)=%=>2dd8O^^QaM*  axadGHr   c                     SSK Jn  U R                  S   nUR                  [        R
                  " U 5      5      u  p4USS2US24   nU$ )a  use QR to get transformation matrix to impose constraint

Parameters
----------
constraints : ndarray, 2-D
    restriction matrix with one constraints in rows

Returns
-------
transf : ndarray
    transformation matrix to reparameterize so that constraint is
    imposed

Notes
-----
This is currently and internal helper function for GAM.
API not stable and will most likely change.

The code for this function was taken from patsy spline handling, and
corresponds to the reparameterization used by Wood in R's mgcv package.

See Also
--------
statsmodels.base._constraints.TransformRestriction : class to impose
    constraints by reparameterization used by `_fit_constrained`.
r   r   N)r   r	   shapeqrr   	transpose)constraintsr	   r   qr   transfs         r   r   r   P   sD    8 !A99R\\+./DAq!"uXFMr   c                 ^   [         R                  R                  U 5      u  pVn[         R                  " Xd* :  5      (       a  SSKnUR                  S5        U(       d  Xd:  n	SXfU:  '   OXd:  n	SXfU:  '   [         R                  " Xi   5      n
U(       a  S[         R                  " Xi   5      -  n
U(       aK  [         R                  " USS2U	4   [         R                  " [         R                  " U
5      Xy   5      5      nU$ [         R                  " [         R                  " U
5      Xy   5      nU$ )an  matrix square root for symmetric matrices

Usage is for decomposing a covariance function S into a square root R
such that

    R' R = S if inverse is False, or
    R' R = pinv(S) if inverse is True

Parameters
----------
mat : array_like, 2-d square
    symmetric square matrix for which square root or inverse square
    root is computed.
    There is no checking for whether the matrix is symmetric.
    A warning is issued if some singular values are negative, i.e.
    below the negative of the threshold.
inverse : bool
    If False (default), then the matrix square root is returned.
    If inverse is True, then the matrix square root of the inverse
    matrix is returned.
full : bool
    If full is False (default, then the square root has reduce number
    of rows if the matrix is singular, i.e. has singular values below
    the threshold.
nullspace : bool
    If nullspace is true, then the matrix square root of the null space
    of the matrix is returned.
threshold : float
    Singular values below the threshold are dropped.

Returns
-------
msqrt : ndarray
    matrix square root or square root of inverse matrix.
r   Nz!some singular values are negativer   )	r   r	   svdanywarningswarnsqrtr"   diag)matinversefull	nullspace	thresholdusvr:   masksqrt_sr'   s               r   r   r   t   s    L iimmC GA!	vva*n9:}i-}i-WWQWFRWWQW%%FF1QW:rvvbggfoqw?@ H FF2776?AG,Hr   )F)FFFgV瞯<)__doc__numpyr   __all__r   r   r   r    r   r   <module>rL      s5    *,-`!H ;@:r   