
    M/Ph                        d dl Zd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ  ej        dej        z            Z ej        d          Z ej        ej                  ZdZd Zd#d	Zd$dZ G d d          Z G d d          Z G d d          ZdZdZdZdZeeedZeeedZ G d de          Z e            Z G d de          Z dZ!dZ"dZ#e!e"edZ$de#edZ% G d de          Z& G d  d!e          Z' e&            Z(d"D ]RZ)e&j*        e)         Z+e'j*        e)         Z, ej-        e+j.        e%          e,_.         ej-        e+j.        e$          e+_.        SdS )%    N)doccer)gammaln)check_random_state)mvn   a  random_state : {None, int, np.random.RandomState, np.random.Generator}, optional
    Used for drawing random variates.
    If `seed` is `None` the `~np.random.RandomState` singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used, seeded
    with seed.
    If `seed` is already a ``RandomState`` or ``Generator`` instance,
    then that object is used.
    Default is None.
c                 T    |                                  } | j        dk    r| d         } | S )z`
    Remove single-dimensional entries from array and convert to scalar,
    if necessary.

    r    )squeezendim)outs    h/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/statsmodels/compat/_scipy_multivariate_t.py_squeeze_outputr       s*     ++--C
x1}}"gJ    c                     ||}|dv rE| j         j                                        }ddd}||         t          j        |          j        z  }|t          j        t          |                     z  }|S )a  
    Determine which eigenvalues are "small" given the spectrum.

    This is for compatibility across various linear algebra functions
    that should agree about whether or not a Hermitian matrix is numerically
    singular and what is its numerical matrix rank.
    This is designed to be compatible with scipy.linalg.pinvh.

    Parameters
    ----------
    spectrum : 1d ndarray
        Array of eigenvalues of a Hermitian matrix.
    cond, rcond : float, optional
        Cutoff for small eigenvalues.
        Singular values smaller than rcond * largest_eigenvalue are
        considered zero.
        If None or -1, suitable machine precision is used.

    Returns
    -------
    eps : float
        Magnitude cutoff for numerical negligibility.

    N)Ng     @@g    .A)fd)dtypecharlowernpfinfoepsmaxabs)spectrumcondrcondtfactorr   s         r   _eigvalsh_to_epsr!   ,   st    2 zN%%''%%ay28A;;?*
H&&
&CJr   h㈵>c                 R    t          j        fd| D             t                    S )a  
    A helper function for computing the pseudoinverse.

    Parameters
    ----------
    v : iterable of numbers
        This may be thought of as a vector of eigenvalues or singular values.
    eps : float
        Values with magnitude no greater than eps are considered negligible.

    Returns
    -------
    v_pinv : 1d float ndarray
        A vector of pseudo-inverted numbers.

    c                 D    g | ]}t          |          k    rd nd|z  S )r      )r   ).0xr   s     r   
<listcomp>z_pinv_1d.<locals>.<listcomp>`   s/    <<<Q#a&&C--QQQqS<<<r   r   )r   arrayfloat)vr   s    `r   _pinv_1dr-   O   s/    " 8<<<<!<<<EJJJJr   c                   4    e Zd ZdZ	 	 ddZed             ZdS )_PSDaN  
    Compute coordinated functions of a symmetric positive semidefinite matrix.

    This class addresses two issues.  Firstly it allows the pseudoinverse,
    the logarithm of the pseudo-determinant, and the rank of the matrix
    to be computed using one call to eigh instead of three.
    Secondly it allows these functions to be computed in a way
    that gives mutually compatible results.
    All of the functions are computed with a common understanding as to
    which of the eigenvalues are to be considered negligibly small.
    The functions are designed to coordinate with scipy.linalg.pinvh()
    but not necessarily with np.linalg.det() or with np.linalg.matrix_rank().

    Parameters
    ----------
    M : array_like
        Symmetric positive semidefinite matrix (2-D).
    cond, rcond : float, optional
        Cutoff for small eigenvalues.
        Singular values smaller than rcond * largest_eigenvalue are
        considered zero.
        If None or -1, suitable machine precision is used.
    lower : bool, optional
        Whether the pertinent array data is taken from the lower
        or upper triangle of M. (Default: lower)
    check_finite : bool, optional
        Whether to check that the input matrices contain only finite
        numbers. Disabling may give a performance gain, but may result
        in problems (crashes, non-termination) if the inputs do contain
        infinities or NaNs.
    allow_singular : bool, optional
        Whether to allow a singular matrix.  (Default: True)

    Notes
    -----
    The arguments are similar to those of scipy.linalg.pinvh().

    NTc                 d   t           j                            |||          \  }}t          |||          }	t	          j        |          |	 k     rt          d          |||	k             }
t          |
          t          |          k     r!|st          j                            d          t          ||	          }t	          j
        |t	          j        |                    }t          |
          | _        || _        t	          j        t	          j        |
                    | _        d | _        d S )N)r   check_finitez.the input matrix must be positive semidefinitezsingular matrix)scipylinalgeighr!   r   min
ValueErrorlenLinAlgErrorr-   multiplysqrtrankUsumloglog_pdet_pinv)selfMr   r   r   r1   allow_singularsur   r   s_pinvr<   s                r   __init__z_PSD.__init__   s    
 |  %l KK1q$..6!99tMNNNa#gJq66CFF??>?)''(9:::!S!!K276??++ FF	rvayy)) 


r   c                 p    | j         )t          j        | j        | j        j                  | _         | j         S N)r@   r   dotr<   TrA   s    r   pinvz	_PSD.pinv   s+    :11DJzr   )NNTTT)__name__
__module____qualname____doc__rG   propertyrM   r	   r   r   r/   r/   c   sV        % %N 8<37   0   X  r   r/   c                   `     e Zd ZdZd fd	Zed             Zej        d             Zd Z xZ	S )multi_rv_genericzd
    Class which encapsulates common functionality between all multivariate
    distributions.

    Nc                 p    t                                                       t          |          | _        d S rI   )superrG   r   _random_staterA   seed	__class__s     r   rG   zmulti_rv_generic.__init__   s/    /55r   c                     | j         S )a   Get or set the RandomState object for generating random variates.

        This can be either None, int, a RandomState instance, or a
        np.random.Generator instance.

        If None (or np.random), use the RandomState singleton used by
        np.random.
        If already a RandomState or Generator instance, use it.
        If an int, use a new RandomState instance seeded with seed.

        )rW   rL   s    r   random_statezmulti_rv_generic.random_state   s     !!r   c                 .    t          |          | _        d S rI   r   rW   rA   rY   s     r   r\   zmulti_rv_generic.random_state   s    /55r   c                 2    |t          |          S | j        S rI   r^   )rA   r\   s     r   _get_random_statez"multi_rv_generic._get_random_state   s    #%l333%%r   rI   )
rN   rO   rP   rQ   rG   rR   r\   setterra   __classcell__rZ   s   @r   rT   rT      s         
6 6 6 6 6 6 " " X" 6 6 6& & & & & & &r   rT   c                   H    e Zd ZdZed             Zej        d             ZdS )multi_rv_frozenzj
    Class which encapsulates common functionality between all frozen
    multivariate distributions.
    c                     | j         j        S rI   )_distrW   rL   s    r   r\   zmulti_rv_frozen.random_state   s    z''r   c                 8    t          |          | j        _        d S rI   )r   rh   rW   r_   s     r   r\   zmulti_rv_frozen.random_state   s    #5d#;#;
   r   N)rN   rO   rP   rQ   rR   r\   rb   r	   r   r   rf   rf      sX          ( ( X( < < < < <r   rf   a   mean : array_like, optional
    Mean of the distribution (default zero)
cov : array_like, optional
    Covariance matrix of the distribution (default one)
allow_singular : bool, optional
    Whether to allow a singular covariance matrix.  (Default: False)
a2  Setting the parameter `mean` to `None` is equivalent to having `mean`
    be the zero-vector. The parameter `cov` can be a scalar, in which case
    the covariance matrix is the identity times that value, a vector of
    diagonal entries for the covariance matrix, or a two-dimensional
    array_like.
     z>See class definition for a detailed description of parameters.)_mvn_doc_default_callparams_mvn_doc_callparams_note_doc_random_statec                   |     e Zd ZdZd fd	ZddZd Zd Zd	 Zdd
Z	ddZ
d Z	 	 ddZ	 	 ddZddZddZ xZS )multivariate_normal_gena  
    A multivariate normal random variable.

    The `mean` keyword specifies the mean. The `cov` keyword specifies the
    covariance matrix.

    Methods
    -------
    ``pdf(x, mean=None, cov=1, allow_singular=False)``
        Probability density function.
    ``logpdf(x, mean=None, cov=1, allow_singular=False)``
        Log of the probability density function.
    ``cdf(x, mean=None, cov=1, allow_singular=False, maxpts=1000000*dim, abseps=1e-5, releps=1e-5)``
        Cumulative distribution function.
    ``logcdf(x, mean=None, cov=1, allow_singular=False, maxpts=1000000*dim, abseps=1e-5, releps=1e-5)``
        Log of the cumulative distribution function.
    ``rvs(mean=None, cov=1, size=1, random_state=None)``
        Draw random samples from a multivariate normal distribution.
    ``entropy()``
        Compute the differential entropy of the multivariate normal.

    Parameters
    ----------
    x : array_like
        Quantiles, with the last axis of `x` denoting the components.
    %(_mvn_doc_default_callparams)s
    %(_doc_random_state)s

    Alternatively, the object may be called (as a function) to fix the mean
    and covariance parameters, returning a "frozen" multivariate normal
    random variable:

    rv = multivariate_normal(mean=None, cov=1, allow_singular=False)
        - Frozen object with the same methods but holding the given
          mean and covariance fixed.

    Notes
    -----
    %(_mvn_doc_callparams_note)s

    The covariance matrix `cov` must be a (symmetric) positive
    semi-definite matrix. The determinant and inverse of `cov` are computed
    as the pseudo-determinant and pseudo-inverse, respectively, so
    that `cov` does not need to have full rank.

    The probability density function for `multivariate_normal` is

    .. math::

        f(x) = \frac{1}{\sqrt{(2 \pi)^k \det \Sigma}}
               \exp\left( -\frac{1}{2} (x - \mu)^T \Sigma^{-1} (x - \mu) \right),

    where :math:`\mu` is the mean, :math:`\Sigma` the covariance matrix,
    and :math:`k` is the dimension of the space where :math:`x` takes values.

    .. versionadded:: 0.14.0

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from scipy.stats import multivariate_normal

    >>> x = np.linspace(0, 5, 10, endpoint=False)
    >>> y = multivariate_normal.pdf(x, mean=2.5, cov=0.5); y
    array([ 0.00108914,  0.01033349,  0.05946514,  0.20755375,  0.43939129,
            0.56418958,  0.43939129,  0.20755375,  0.05946514,  0.01033349])
    >>> fig1 = plt.figure()
    >>> ax = fig1.add_subplot(111)
    >>> ax.plot(x, y)

    The input quantiles can be any shape of array, as long as the last
    axis labels the components.  This allows us for instance to
    display the frozen pdf for a non-isotropic random variable in 2D as
    follows:

    >>> x, y = np.mgrid[-1:1:.01, -1:1:.01]
    >>> pos = np.dstack((x, y))
    >>> rv = multivariate_normal([0.5, -0.2], [[2.0, 0.3], [0.3, 0.5]])
    >>> fig2 = plt.figure()
    >>> ax2 = fig2.add_subplot(111)
    >>> ax2.contourf(x, y, rv.pdf(pos))

    Nc                     t                                          |           t          j        | j        t
                    | _        d S rI   )rV   rG   r   	docformatrQ   mvn_docdict_paramsrX   s     r   rG   z multivariate_normal_gen.__init__T  s6    '6HIIr   r%   Fc                 (    t          ||||          S )z
        Create a frozen multivariate normal distribution.

        See `multivariate_normal_frozen` for more information.

        )rC   rY   )multivariate_normal_frozen)rA   meancovrC   rY   s        r   __call__z multivariate_normal_gen.__call__X  s%     *$9G/35 5 5 	5r   c                    |a|<|d}n}t          j        |t                    }|j        dk     rd}nT|j        d         }nFt          j        |t                    }|j        }n#t          j        |          st          d          |t          j        |          }t          j        |t                    }|d}t          j        |t                    }|dk    rd|_        d	|_        |j        dk    s|j        d         |k    rt          d
|z            |j        dk    r|t          j	        |          z  }n|j        dk    rt          j
        |          }n|j        dk    rl|j        ||fk    r_|j        \  }}||k    rdt          |j                  z  }n(d}|t          |j                  t          |          fz  }t          |          |j        dk    rt          d|j        z            |||fS )z
        Infer dimensionality from mean or covariance matrix, ensure that
        mean and covariance are full vector resp. matrix.

        Nr%   r)   r   r   z.Dimension of random variable must be a scalar.      ?r%   r%   r%   z+Array 'mean' must be a vector of length %d.HArray 'cov' must be square if it is two dimensional, but cov.shape = %s.zTDimension mismatch: array 'cov' is of shape %s, but 'mean' is a vector of length %d.>Array 'cov' must be at most two-dimensional, but cov.ndim = %d)r   asarrayr+   r   shapesizeisscalarr6   zeroseyediagstrr7   )rA   dimru   rv   rowscolsmsgs          r   _process_parametersz+multivariate_normal_gen._process_parametersc  s    ;|;CC*S666Cx!||!ilz$e444i;s## .  "- . . .
 <8C==Dz$e,,,;CjE***!88DJCI9>>TZ]c11J ! " " "8q==s#CCX]]'#,,CCX]]syS#J66JD$t||.03CI??S^^SYY77S//!X\\ 247H= > > > D#~r   c                     t          j        |t                    }|j        dk    r|t           j                 }n>|j        dk    r3|dk    r|ddt           j        f         }n|t           j        ddf         }|S zm
        Adjust quantiles array so that last axis labels the components of
        each data point.

        r)   r   r%   Nr   r~   r+   r   newaxisrA   r'   r   s      r   _process_quantilesz*multivariate_normal_gen._process_quantiles  ss     Jq&&&6Q;;"*AAVq[[axxaaam$bj!!!m$r   c                     ||z
  }t          j        t          j        t          j        ||                    d          }d|t          z  |z   |z   z  S )a  
        Parameters
        ----------
        x : ndarray
            Points at which to evaluate the log of the probability
            density function
        mean : ndarray
            Mean of the distribution
        prec_U : ndarray
            A decomposition such that np.dot(prec_U, prec_U.T)
            is the precision matrix, i.e. inverse of the covariance matrix.
        log_det_cov : float
            Logarithm of the determinant of the covariance matrix
        rank : int
            Rank of the covariance matrix.

        Notes
        -----
        As this function does no argument checking, it should not be
        called directly; use 'logpdf' instead.

        r   axisg      )r   r=   squarerJ   _LOG_2PI)rA   r'   ru   prec_Ulog_det_covr;   devmahas           r   _logpdfzmultivariate_normal_gen._logpdf  sP    . $hvbisF 3 3442>>>th4t;<<r   c                     |                      d||          \  }}}|                     ||          }t          ||          }|                     |||j        |j        |j                  }t          |          S )a  
        Log of the multivariate normal probability density function.

        Parameters
        ----------
        x : array_like
            Quantiles, with the last axis of `x` denoting the components.
        %(_mvn_doc_default_callparams)s

        Returns
        -------
        pdf : ndarray or scalar
            Log of the probability density function evaluated at `x`

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        NrC   )r   r   r/   r   r<   r?   r;   r   rA   r'   ru   rv   rC   r   psdr   s           r   logpdfzmultivariate_normal_gen.logpdf  su    ( 11$cBBT3##As++3~666ll1dCE3<BBs###r   c           	         |                      d||          \  }}}|                     ||          }t          ||          }t          j        |                     |||j        |j        |j                            }t          |          S )a  
        Multivariate normal probability density function.

        Parameters
        ----------
        x : array_like
            Quantiles, with the last axis of `x` denoting the components.
        %(_mvn_doc_default_callparams)s

        Returns
        -------
        pdf : ndarray or scalar
            Probability density function evaluated at `x`

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        Nr   )
r   r   r/   r   expr   r<   r?   r;   r   r   s           r   pdfzmultivariate_normal_gen.pdf  s    ( 11$cBBT3##As++3~666fT\\!T35#,IIJJs###r   c                    	 t          j        j        t           j                   		fd}t          j        |d|          }t          |          S )a  
        Parameters
        ----------
        x : ndarray
            Points at which to evaluate the cumulative distribution function.
        mean : ndarray
            Mean of the distribution
        cov : array_like
            Covariance matrix of the distribution
        maxpts: integer
            The maximum number of points to use for integration
        abseps: float
            Absolute error tolerance
        releps: float
            Relative error tolerance

        Notes
        -----
        As this function does no argument checking, it should not be
        called directly; use 'cdf' instead.

        .. versionadded:: 1.0.0

        c           	      D    t          j        |           d         S )Nr   )r   mvnun)x_sliceabsepsrv   r   maxptsru   relepss    r   <lambda>z.multivariate_normal_gen._cdf.<locals>.<lambda>  s-    5'4+166"C "CCD"F r   r   )r   fullr   infapply_along_axisr   )
rA   r'   ru   rv   r   r   r   func1dr   r   s
     `````  @r   _cdfzmultivariate_normal_gen._cdf  s{    2 
RVG,,F F F F F F F F F!&"a00s###r   r"   c           
          |                      d||          \  }}}|                     ||          }t          ||           |sd|z  }t          j        |                     ||||||                    }	|	S )a  
        Log of the multivariate normal cumulative distribution function.

        Parameters
        ----------
        x : array_like
            Quantiles, with the last axis of `x` denoting the components.
        %(_mvn_doc_default_callparams)s
        maxpts: integer, optional
            The maximum number of points to use for integration
            (default `1000000*dim`)
        abseps: float, optional
            Absolute error tolerance (default 1e-5)
        releps: float, optional
            Relative error tolerance (default 1e-5)

        Returns
        -------
        cdf : ndarray or scalar
            Log of the cumulative distribution function evaluated at `x`

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        .. versionadded:: 1.0.0

        Nr   @B )r   r   r/   r   r>   r   
rA   r'   ru   rv   rC   r   r   r   r   r   s
             r   logcdfzmultivariate_normal_gen.logcdf#  s    < 11$cBBT3##As++S0000 	#s]FfTYYq$VVVDDEE
r   c                     |                      d||          \  }}}|                     ||          }t          ||           |sd|z  }|                     ||||||          }	|	S )a  
        Multivariate normal cumulative distribution function.

        Parameters
        ----------
        x : array_like
            Quantiles, with the last axis of `x` denoting the components.
        %(_mvn_doc_default_callparams)s
        maxpts: integer, optional
            The maximum number of points to use for integration
            (default `1000000*dim`)
        abseps: float, optional
            Absolute error tolerance (default 1e-5)
        releps: float, optional
            Relative error tolerance (default 1e-5)

        Returns
        -------
        cdf : ndarray or scalar
            Cumulative distribution function evaluated at `x`

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        .. versionadded:: 1.0.0

        Nr   r   )r   r   r/   r   r   s
             r   cdfzmultivariate_normal_gen.cdfJ  sz    < 11$cBBT3##As++S0000 	#s]Fii4fff==
r   c                     |                      d||          \  }}}|                     |          }|                    |||          }t          |          S )a  
        Draw random samples from a multivariate normal distribution.

        Parameters
        ----------
        %(_mvn_doc_default_callparams)s
        size : integer, optional
            Number of samples to draw (default 1).
        %(_doc_random_state)s

        Returns
        -------
        rvs : ndarray or scalar
            Random variates of size (`size`, `N`), where `N` is the
            dimension of the random variable.

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        N)r   ra   multivariate_normalr   )rA   ru   rv   r   r\   r   r   s          r   rvszmultivariate_normal_gen.rvsq  sY    , 11$cBBT3--l;;..tS$??s###r   c                     |                      d||          \  }}}t          j                            dt          j        z  t          j        z  |z            \  }}d|z  S )aP  
        Compute the differential entropy of the multivariate normal.

        Parameters
        ----------
        %(_mvn_doc_default_callparams)s

        Returns
        -------
        h : scalar
            Entropy of the multivariate normal distribution

        Notes
        -----
        %(_mvn_doc_callparams_note)s

        Nr         ?)r   r   r3   slogdetpie)rA   ru   rv   r   _logdets         r   entropyzmultivariate_normal_gen.entropy  sV    $ 11$cBBT3I%%a"%i"$&6&<==	6V|r   rI   )Nr%   FN)Nr%   F)Nr%   FNr"   r"   )Nr%   r%   N)Nr%   )rN   rO   rP   rQ   rG   rw   r   r   r   r   r   r   r   r   r   r   rc   rd   s   @r   ro   ro      s0       R RhJ J J J J J	5 	5 	5 	5= = =~  $= = =6$ $ $ $4$ $ $ $4$ $ $@ HL#'% % % %N EI $% % % %N$ $ $ $8       r   ro   c                   @    e Zd Z	 	 ddZd Zd Zd Zd	 Zdd
Zd Z	dS )rt   Nr%   Fr"   c                    t          |          | _        | j                            d||          \  | _        | _        | _        t          | j        |          | _        |s
d| j        z  }|| _        || _	        || _
        dS )a  
        Create a frozen multivariate normal distribution.

        Parameters
        ----------
        mean : array_like, optional
            Mean of the distribution (default zero)
        cov : array_like, optional
            Covariance matrix of the distribution (default one)
        allow_singular : bool, optional
            If this flag is True then tolerate a singular
            covariance matrix (default False).
        seed : {None, int, `~np.random.RandomState`, `~np.random.Generator`}, optional
            This parameter defines the object to use for drawing random
            variates.
            If `seed` is `None` the `~np.random.RandomState` singleton is used.
            If `seed` is an int, a new ``RandomState`` instance is used, seeded
            with seed.
            If `seed` is already a ``RandomState`` or ``Generator`` instance,
            then that object is used.
            Default is None.
        maxpts: integer, optional
            The maximum number of points to use for integration of the
            cumulative distribution function (default `1000000*dim`)
        abseps: float, optional
            Absolute error tolerance for the cumulative distribution function
            (default 1e-5)
        releps: float, optional
            Relative error tolerance for the cumulative distribution function
            (default 1e-5)

        Examples
        --------
        When called with the default parameters, this will create a 1D random
        variable with mean 0 and covariance 1:

        >>> from scipy.stats import multivariate_normal
        >>> r = multivariate_normal()
        >>> r.mean
        array([ 0.])
        >>> r.cov
        array([[1.]])

        Nr   r   )ro   rh   r   r   ru   rv   r/   cov_infor   r   r   )rA   ru   rv   rC   rY   r   r   r   s           r   rG   z#multivariate_normal_frozen.__init__  s    \ -T22
(,
(F(F<@$)M )M%$)TXTXnEEE 	(tx'Fr   c                     | j                             || j                  }| j                             || j        | j        j        | j        j        | j        j                  }t          |          S rI   )
rh   r   r   r   ru   r   r<   r?   r;   r   rA   r'   r   s      r   r   z!multivariate_normal_frozen.logpdf  s]    J))!TX66j  DIt}!%!79KM Ms###r   c                 P    t          j        |                     |                    S rI   r   r   r   rA   r'   s     r   r   zmultivariate_normal_frozen.pdf      vdkk!nn%%%r   c                 P    t          j        |                     |                    S rI   )r   r>   r   r   s     r   r   z!multivariate_normal_frozen.logcdf  s    vdhhqkk"""r   c                     | j                             || j                  }| j                             || j        | j        | j        | j        | j                  }t          |          S rI   )
rh   r   r   r   ru   rv   r   r   r   r   r   s      r   r   zmultivariate_normal_frozen.cdf  sU    J))!TX66jooaDHdk4;"k+ +s###r   c                 P    | j                             | j        | j        ||          S rI   )rh   r   ru   rv   rA   r   r\   s      r   r   zmultivariate_normal_frozen.rvs  s     z~~di4FFFr   c                 X    | j         j        }| j         j        }d|t          dz   z  |z   z  S )z
        Computes the differential entropy of the multivariate normal.

        Returns
        -------
        h : scalar
            Entropy of the multivariate normal distribution

        r   r%   )r   r?   r;   r   )rA   r?   r;   s      r   r   z"multivariate_normal_frozen.entropy  s1     =)}!dhl+h677r   )Nr%   FNNr"   r"   r%   N)
rN   rO   rP   rG   r   r   r   r   r   r   r	   r   r   rt   rt     s        DH266 6 6 6p$ $ $& & &# # #$ $ $G G G G8 8 8 8 8r   rt   a  
loc : array_like, optional
    Location of the distribution. (default ``0``)
shape : array_like, optional
    Positive semidefinite matrix of the distribution. (default ``1``)
df : float, optional
    Degrees of freedom of the distribution; must be greater than zero.
    If ``np.inf`` then results are multivariate normal. The default is ``1``.
allow_singular : bool, optional
    Whether to allow a singular matrix. (default ``False``)
a  Setting the parameter `loc` to ``None`` is equivalent to having `loc`
be the zero-vector. The parameter `shape` can be a scalar, in which case
the shape matrix is the identity times that value, a vector of
diagonal entries for the shape matrix, or a two-dimensional array_like.
)_mvt_doc_default_callparams_mvt_doc_callparams_noterm   c                   Z     e Zd ZdZd fd	Z	 	 ddZddZddZd	 Zdd
Z	d Z
d Z xZS )multivariate_t_gena	  
    A multivariate t-distributed random variable.

    The `loc` parameter specifies the location. The `shape` parameter specifies
    the positive semidefinite shape matrix. The `df` parameter specifies the
    degrees of freedom.

    In addition to calling the methods below, the object itself may be called
    as a function to fix the location, shape matrix, and degrees of freedom
    parameters, returning a "frozen" multivariate t-distribution random.

    Methods
    -------
    ``pdf(x, loc=None, shape=1, df=1, allow_singular=False)``
        Probability density function.
    ``logpdf(x, loc=None, shape=1, df=1, allow_singular=False)``
        Log of the probability density function.
    ``rvs(loc=None, shape=1, df=1, size=1, random_state=None)``
        Draw random samples from a multivariate t-distribution.

    Parameters
    ----------
    x : array_like
        Quantiles, with the last axis of `x` denoting the components.
    %(_mvt_doc_default_callparams)s
    %(_doc_random_state)s

    Notes
    -----
    %(_mvt_doc_callparams_note)s
    The matrix `shape` must be a (symmetric) positive semidefinite matrix. The
    determinant and inverse of `shape` are computed as the pseudo-determinant
    and pseudo-inverse, respectively, so that `shape` does not need to have
    full rank.

    The probability density function for `multivariate_t` is

    .. math::

        f(x) = \frac{\Gamma(\nu + p)/2}{\Gamma(\nu/2)\nu^{p/2}\pi^{p/2}|\Sigma|^{1/2}}
               \exp\left[1 + \frac{1}{\nu} (\mathbf{x} - \boldsymbol{\mu})^{\top}
               \boldsymbol{\Sigma}^{-1}
               (\mathbf{x} - \boldsymbol{\mu}) \right]^{-(\nu + p)/2},

    where :math:`p` is the dimension of :math:`\mathbf{x}`,
    :math:`\boldsymbol{\mu}` is the :math:`p`-dimensional location,
    :math:`\boldsymbol{\Sigma}` the :math:`p \times p`-dimensional shape
    matrix, and :math:`\nu` is the degrees of freedom.

    .. versionadded:: 1.6.0

    Examples
    --------
    >>> import matplotlib.pyplot as plt
    >>> from scipy.stats import multivariate_t
    >>> x, y = np.mgrid[-1:3:.01, -2:1.5:.01]
    >>> pos = np.dstack((x, y))
    >>> rv = multivariate_t([1.0, -0.5], [[2.1, 0.3], [0.3, 1.5]], df=2)
    >>> fig, ax = plt.subplots(1, 1)
    >>> ax.set_aspect('equal')
    >>> plt.contourf(x, y, rv.pdf(pos))

    Nc                     t                                          |           t          j        | j        t
                    | _        t          |          | _        dS )z
        Initialize a multivariate t-distributed random variable.

        Parameters
        ----------
        seed : Random state.

        N)rV   rG   r   rq   rQ   mvt_docdict_paramsr   rW   rX   s     r   rG   zmultivariate_t_gen.__init__i  sJ     	'6HII/55r   r%   Fc                 p    |t           j        k    rt          ||||          S t          |||||          S )zs
        Create a frozen multivariate t-distribution. See
        `multivariate_t_frozen` for parameters.

        )ru   rv   rC   rY   )locr   dfrC   rY   )r   r   rt   multivariate_t_frozen)rA   r   r   r   rC   rY   s         r   rw   zmultivariate_t_gen.__call__v  sX     <<-3E=K379 9 9 9 %Eb4BO O O 	Or   c           	         |                      |||          \  }}}}|                     ||          }t          ||          }|                     |||j        |j        |||j                  }t          j        |          S )al  
        Multivariate t-distribution probability density function.

        Parameters
        ----------
        x : array_like
            Points at which to evaluate the probability density function.
        %(_mvt_doc_default_callparams)s

        Returns
        -------
        pdf : Probability density function evaluated at `x`.

        Examples
        --------
        >>> from scipy.stats import multivariate_t
        >>> x = [0.4, 5]
        >>> loc = [0, 1]
        >>> shape = [[1, 0.1], [0.1, 1]]
        >>> df = 7
        >>> multivariate_t.pdf(x, loc, shape, df)
        array([0.00075713])

        r   )	r   r   r/   r   r<   r?   r;   r   r   )	rA   r'   r   r   r   rC   r   
shape_infor   s	            r   r   zmultivariate_t_gen.pdf  s    2 #66sE2FFS%##As++%???
ajlJ4G!:?4 4vf~~r   c           	          |                      |||          \  }}}}|                     ||          }t          |          }|                     |||j        |j        |||j                  S )a  
        Log of the multivariate t-distribution probability density function.

        Parameters
        ----------
        x : array_like
            Points at which to evaluate the log of the probability density
            function.
        %(_mvt_doc_default_callparams)s

        Returns
        -------
        logpdf : Log of the probability density function evaluated at `x`.

        Examples
        --------
        >>> from scipy.stats import multivariate_t
        >>> x = [0.4, 5]
        >>> loc = [0, 1]
        >>> shape = [[1, 0.1], [0.1, 1]]
        >>> df = 7
        >>> multivariate_t.logpdf(x, loc, shape, df)
        array([-7.1859802])

        See Also
        --------
        pdf : Probability density function.

        )r   r   r/   r   r<   r?   r;   )rA   r'   r   r   r   r   r   s          r   r   zmultivariate_t_gen.logpdf  sp    < #66sE2FFS%##As++%[[
||AsJL*2Er3&O- - 	-r   c                     |t           j        k    rt                              |||||          S ||z
  }t          j        t          j        ||                                        d          }	d||z   z  }
t          |
          }t          d|z            }|dz  t          j        |t           j	        z            z  }d|z  }|
 t          j        dd|z  |	z  z             z  }t          ||z
  |z
  |z
  |z             S )aB  Utility method `pdf`, `logpdf` for parameters.

        Parameters
        ----------
        x : ndarray
            Points at which to evaluate the log of the probability density
            function.
        loc : ndarray
            Location of the distribution.
        prec_U : ndarray
            A decomposition such that `np.dot(prec_U, prec_U.T)` is the inverse
            of the shape matrix.
        log_pdet : float
            Logarithm of the determinant of the shape matrix.
        df : float
            Degrees of freedom of the distribution.
        dim : int
            Dimension of the quantiles x.
        rank : int
            Rank of the shape matrix.

        Notes
        -----
        As this function does no argument checking, it should not be called
        directly; use 'logpdf' instead.

        r   r   r   g       @r%   ry   )r   r   r   r   r   rJ   r=   r   r>   r   r   )rA   r'   r   r   r?   r   r   r;   r   r   r   ABCDEs                   r   r   zmultivariate_t_gen._logpdf  s    8 <<&..q#vxNNN#gyV,,--11r1::28AJJC"HFRVBJ'''(NBRUdN*+++q1uqy1}q0111r   c                    |                      |||          \  }}}}|t          |          }n| j        }t          j        |          rt          j        |          }n|                    ||          |z  }|                    t          j        |          ||          }	||	t          j	        |          dddf         z  z   }
t          |
          S )a  
        Draw random samples from a multivariate t-distribution.

        Parameters
        ----------
        %(_mvt_doc_default_callparams)s
        size : integer, optional
            Number of samples to draw (default 1).
        %(_doc_random_state)s

        Returns
        -------
        rvs : ndarray or scalar
            Random variates of size (`size`, `P`), where `P` is the
            dimension of the random variable.

        Examples
        --------
        >>> from scipy.stats import multivariate_t
        >>> x = [0.4, 5]
        >>> loc = [0, 1]
        >>> shape = [[1, 0.1], [0.1, 1]]
        >>> df = 7
        >>> multivariate_t.rvs(loc, shape, df)
        array([[0.93477495, 3.00408716]])

        N)r   )r   r   rW   r   isinfones	chisquarer   r   r:   r   )rA   r   r   r   r   r\   r   rngr'   zsampless              r   r   zmultivariate_t_gen.rvs  s    B #66sE2FFS%#$\22CC$C8B<< 	2AAbt,,r1A##BHSMM5t#DDBGAJJqqq$w///w'''r   c                     t          j        |t                    }|j        dk    r|t           j                 }n>|j        dk    r3|dk    r|ddt           j        f         }n|t           j        ddf         }|S r   r   r   s      r   r   z%multivariate_t_gen._process_quantiles#  ss     Jq&&&6Q;;"*AAVq[[axxaaam$bj!!!m$r   c                    |;|9t          j        dt                    }t          j        dt                    }d}n|Kt          j        |t                    }|j        dk     rd}n|j        d         }t          j        |          }nv|7t          j        |t                    }|j        }t          j        |          }n=t          j        |t                    }t          j        |t                    }|j        }|dk    rd|_        d|_        |j        dk    s|j        d         |k    rt          d|z            |j        dk    r|t          j        |          z  }n|j        dk    rt          j	        |          }n|j        dk    rl|j        ||fk    r_|j        \  }}||k    rd	t          |j                  z  }n(d
}|t          |j                  t          |          fz  }t          |          |j        dk    rt          d|j        z            |d}n8|dk    rt          d          t          j        |          rt          d          ||||fS )z
        Infer dimensionality from location array and shape matrix, handle
        defaults, and ensure compatible dimensions.

        Nr   r)   r%   r   rz   r{   z*Array 'loc' must be a vector of length %d.r|   zSDimension mismatch: array 'cov' is of shape %s, but 'loc' is a vector of length %d.r}   z'df' must be greater than zero.z8'df' is 'nan' but must be greater than zero or 'np.inf'.)r   r~   r+   r   r   r   r   r   r6   r   r   r7   isnan)rA   r   r   r   r   r   r   r   s           r   r   z&multivariate_t_gen._process_parameters3  sh    ;5=*Qe,,,CJq...ECC[JuE222EzA~~k!n(3--CC]*S...C(CF3KKEEJuE222E*S...C(C!88CI EK8q==CIaLC//I ! " " ":??BF3KK'EEZ1__GENNEEZ1__c
!:!:JD$t||.03EK0@0@A>S--s3xx88S//!Z!^^ 249J? @ @ @ :BB1WW>???Xb\\ 	YWXXXC""r   rI   Nr%   r%   FN)Nr%   r%   F)Nr%   r%   )Nr%   r%   r%   N)rN   rO   rP   rQ   rG   rw   r   r   r   r   r   r   rc   rd   s   @r   r   r   (  s        > >@6 6 6 6 6 6 @EO O O O   @"- "- "- "-H)2 )2 )2V.( .( .( .(`   ;# ;# ;# ;# ;# ;# ;#r   r   c                   .    e Zd Z	 	 ddZd Zd Zd	dZdS )
r   Nr%   Fc                     t          |          | _        | j                            |||          \  }}}}||||f\  | _        | _        | _        | _        t          ||          | _        dS )a  
        Create a frozen multivariate t distribution.

        Parameters
        ----------
        %(_mvt_doc_default_callparams)s

        Examples
        --------
        >>> loc = np.zeros(3)
        >>> shape = np.eye(3)
        >>> df = 10
        >>> dist = multivariate_t(loc, shape, df)
        >>> dist.rvs()
        array([[ 0.81412036, -1.53612361,  0.42199647]])
        >>> dist.pdf([1, 1, 1])
        array([0.01237803])

        r   N)	r   rh   r   r   r   r   r   r/   r   )rA   r   r   r   rC   rY   r   s          r   rG   zmultivariate_t_frozen.__init__s  sl    * (--
"j<<S%LLS%25sE22E/$(DJu^DDDr   c           	          | j                             || j                  }| j        j        }| j        j        }| j                             || j        ||| j        | j        | j        j	                  S rI   )
rh   r   r   r   r<   r?   r   r   r   r;   )rA   r'   r<   r?   s       r   r   zmultivariate_t_frozen.logpdf  sc    J))!TX66O?+z!!!TXq(DGTX"&/"68 8 	8r   c                 P    t          j        |                     |                    S rI   r   r   s     r   r   zmultivariate_t_frozen.pdf  r   r   c                 ^    | j                             | j        | j        | j        ||          S )N)r   r   r   r   r\   )rh   r   r   r   r   r   s      r   r   zmultivariate_t_frozen.rvs  s3    z~~$($(J!%#'+7	  9 9 	9r   r   r   )rN   rO   rP   rG   r   r   r   r	   r   r   r   r   q  sd        ?DE E E E48 8 8& & &9 9 9 9 9 9r   r   )r   r   r   )NN)r"   )/numpyr   scipy.linalgr2   
scipy._libr   scipy.specialr   scipy._lib._utilr   scipy.statsr   r>   r   r   _LOG_2_LOG_PIrm   r   r!   r-   r/   rT   rf   rk   rl   _mvn_doc_frozen_callparams_mvn_doc_frozen_callparams_noterr   mvn_docdict_noparamsro   r   rt   r   r   _mvt_doc_frozen_callparams_noter   mvt_docdict_noparamsr   r   multivariate_tname__dict__methodmethod_frozenrq   rQ   r	   r   r   <module>r     sc                 ! ! ! ! ! ! / / / / / /      26!be)	
"&--	 	 	 	       FK K K K(D D D D D D D DN!& !& !& !& !& !& !& !&H< < < < < < < <      I   $? 8*   $> ?*  b b b b b. b b bJ .-// Z8 Z8 Z8 Z8 Z8 Z8 Z8 Z8|
   E   $? 8*   $& ?*  F# F# F# F# F#) F# F# F#R
+9 +9 +9 +9 +9O +9 +9 +9\ $#%%
 % J JD(.F)248M,F,V^-AC CM%V%fn6HIIFNNJ Jr   