
    (ph                       S SK r S SKrS SKrS SKrS SKJr  S SKJ	r	J
r
JrJrJrJrJrJr  S SKJr  S SKJrJr  S SKJrJr  SSKJrJ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%J&r&  / SQr'\RP                  " S\RR                  -  5      r*\RP                  " S5      r+\RP                  " \RR                  5      r,\RZ                  " 5       r.Sr/S r0SS jr1SS jr2 " S S5      r3 " S S5      r4 " S S5      r5Sr6Sr7Sr8Sr9\6\7\/S.r:\8\9\/S.r; " S S \45      r<\<" 5       r= " S! S"\55      r>S# He  r?\<R                  \?   rA\>R                  \?   rB\R                  " \AR                  \;5      \BlD        \R                  " \AR                  \:5      \AlD        Mg     S$rES%rFSrGSrH\E\F\/S&.rI\G\H\/S&.rJ " S' S(\45      rK\K" 5       rL " S) S*\55      rMS+ He  r?\KR                  \?   rA\MR                  \?   rB\R                  " \AR                  \J5      \BlD        \R                  " \AR                  \I5      \AlD        Mg     S,rNSrOSrP\N\/S-.rQ\O\/S-.rRS. rSS/ rTS0 rU " S1 S2\45      rV\V" 5       rW " S3 S4\55      rXS5 He  r?\VR                  \?   rA\XR                  \?   rB\R                  " \AR                  \R5      \BlD        \R                  " \AR                  \Q5      \AlD        Mg     S6rYSrZSr[Sr\\Y\Z\/S7.r]\[\\\/S7.r^ " S8 S9\45      r_\_" 5       r` " S: S;\55      raS< He  r?\_R                  \?   rA\aR                  \?   rB\R                  " \AR                  \^5      \BlD        \R                  " \AR                  \]5      \AlD        Mg      " S= S>\_5      rb\b" 5       rc " S? S@\55      rdSA He  r?\bR                  \?   rA\aR                  \?   rB\R                  " \AR                  \^5      \BlD        \R                  " \AR                  \]5      \AlD        Mg     SBreSCrfSrgSrh\e\f\/S7.ri\g\h\/S7.rj " SD SE\45      rk\k" 5       rl " SF SG\55      rmSH He  r?\kR                  \?   rA\mR                  \?   rB\R                  " \AR                  \j5      \BlD        \R                  " \AR                  \i5      \AlD        Mg      " SI SJ\45      rn\n" 5       ro " SK SL\55      rp " SM SN\45      rq\q" 5       rr " SO SP\55      rs " SQ SR\45      rt\t" 5       ru " SS ST\55      rv " SU SV\45      rw\w" 5       rx " SW SX\55      rySYrzSZr{Sr|\z\{\/S[.r}S\|\/S[.r~ " S\ S]\45      r " S^ S_\55      r\" 5       rS` He  r?\R                  \?   rA\R                  \?   rB\R                  " \AR                  \~5      \BlD        \R                  " \AR                  \}5      \AlD        Mg     SarSbrSrSr\\\/S7.r\\\/S7.r " Sc Sd\45      r\" 5       r " Se Sf\55      rSg He  r?\R                  \?   rA\R                  \?   rB\R                  " \AR                  \5      \BlD        \R                  " \AR                  \5      \AlD        Mg      " Sh Si\45      r\" 5       r " Sj Sk\55      rSlrSmrSnrSo\ 3rSr\/\\\\Sp.r\GR)                  5       r\GR-                  SS\Sq.5        SSr jr\" \\5        Ss H>  r?\R                  \?   rA\R                  \?   rB\" \B\\AR                  5        \" \A\5        M@      " St Su\45      r\" 5       r " Sv Sw\55      rSx rSyrSrSr\\/Sz.r\\/Sz.rSS{ jr " S| S}\45      r\" 5       r " S~ S\55      rS He  r?\R                  \?   rA\R                  \?   rB\R                  " \AR                  \5      \BlD        \R                  " \AR                  \5      \AlD        Mg      " S S\45      r\" 5       r " S S\55      r " S S\45      r\" 5       r " S S\55      rS He  r?\R                  \?   rA\R                  \?   rB\R                  " \AR                  \;5      \BlD        \R                  " \AR                  \:5      \AlD        Mg     g)    N)doccer)gammalnpsimultigammalnxlogyentrbetalniveloggamma)special)check_random_state
_lazywhere)drotget_blas_funcs   )norminvgamma)binom)_mvn_covariance_rcont_qmvt)directional_stats)root_scalar)multivariate_normalmatrix_normal	dirichletdirichlet_multinomialwishart
invwishartmultinomialspecial_ortho_grouportho_grouprandom_correlationunitary_groupmultivariate_tmultivariate_hypergeomrandom_tableuniform_directionvonmises_fishernormal_inverse_gamma   a  seed : {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                 P    U R                  5       n U R                  S:X  a  U S   n U $ )zS
Remove single-dimensional entries from array and convert to scalar,
if necessary.
r    )squeezendimouts    L/var/www/html/venv/lib/python3.13/site-packages/scipy/stats/_multivariate.py_squeeze_outputr5   9   s(    
 ++-C
xx1}"gJ    c                     Ub  UnUS;   aN  U R                   R                  R                  5       nSSS.nXC   [        R                  " U5      R
                  -  nU[        R                  " [        U 5      5      -  nU$ )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     @@g    .A)fd)dtypecharlowernpfinfoepsmaxabs)spectrumcondrcondtfactorrA   s         r4   _eigvalsh_to_epsrI   D   sm    0 zNN%%'%y288A;??*
H&
&CJr6   c                     [         R                  " U  Vs/ s H  n[        U5      U::  a  SOSU-  PM     sn[        S9$ s  snf )aV  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.

r   r   r<   )r?   arrayrC   float)vrA   xs      r4   _pinv_1drP   f   s:      88!<!Q#a&C-QQqS0!<EJJ<s    ?c                   <    \ rS rSrSr  SS jrS r\S 5       rSr	g)	_PSDy   a  
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().

Nc                    [         R                  " U5      U l        [        R                  R                  XUS9u  px[        XrU5      n	[         R                  " U5      U	* :  a  Sn
[        U
5      eXwU	:     n[        U5      [        U5      :  a(  U(       d!  Sn
[         R                  R                  U
5      e[        Xy5      n[         R                  " U[         R                  " U5      5      nSU	-  U l        US S 2Xy:*  4   U l        [        U5      U l        Xl        [         R$                  " [         R&                  " U5      5      U l        S U l        g )Nr>   check_finitez9The input matrix must be symmetric positive semidefinite.zUWhen `allow_singular is False`, the input matrix must be symmetric positive definite.r9   )r?   asarray_MscipylinalgeighrI   min
ValueErrorlenLinAlgErrorrP   multiplysqrtrA   VrankUsumloglog_pdet_pinv)selfMrE   rF   r>   rV   allow_singularsurA   msgr;   s_pinvrd   s                 r4   __init___PSD.__init__   s   **Q-
 ||  l Kq.66!9tMCS/!#gJq6CF?>2C))'',,!!KK2776?+ s71ah; F	rvvay) 
r6   c                 v    [         R                  R                  XR                  -  SS9nX R                  :  nU$ )z:
Check whether x lies in the support of the distribution.
r8   axis)r?   rZ   r   rb   rA   )ri   rO   residual
in_supports       r4   _support_mask_PSD._support_mask   s2     99>>!ff*2>6(
r6   c                     U R                   c:  [        R                  " U R                  U R                  R                  5      U l         U R                   $ N)rh   r?   dotrd   Tri   s    r4   pinv	_PSD.pinv   s4    ::1DJzzr6   )rd   rb   rX   rh   rA   rg   rc   )NNTTT)
__name__
__module____qualname____firstlineno____doc__rp   rw   propertyr~   __static_attributes__r/   r6   r4   rR   rR   y   s/    %N 8<37B  r6   rR   c                   j   ^  \ rS rSrSrSU 4S jjr\S 5       r\R                  S 5       rS r	Sr
U =r$ )	multi_rv_generic   zW
Class which encapsulates common functionality between all multivariate
distributions.
c                 B   > [         TU ]  5         [        U5      U l        g rz   )superrp   r   _random_stateri   seed	__class__s     r4   rp   multi_rv_generic.__init__   s    /5r6   c                     U R                   $ )aF  Get or set the Generator object for generating random variates.

If `seed` is None (or `np.random`), the `numpy.random.RandomState`
singleton is used.
If `seed` is an int, a new ``RandomState`` instance is used,
seeded with `seed`.
If `seed` is already a ``Generator`` or ``RandomState`` instance then
that instance is used.

r   r}   s    r4   random_statemulti_rv_generic.random_state   s     !!!r6   c                 $    [        U5      U l        g rz   r   r   ri   r   s     r4   r   r      s    /5r6   c                 6    Ub  [        U5      $ U R                  $ rz   r   ri   r   s     r4   _get_random_state"multi_rv_generic._get_random_state   s    #%l33%%%r6   r   rz   )r   r   r   r   r   rp   r   r   setterr   r   __classcell__r   s   @r4   r   r      sE    6 " " 6 6& &r6   r   c                   L    \ rS rSrSr\S 5       r\R                  S 5       rSrg)multi_rv_frozen   z^
Class which encapsulates common functionality between all frozen
multivariate distributions.
c                 .    U R                   R                  $ rz   )_distr   r}   s    r4   r   multi_rv_frozen.random_state   s    zz'''r6   c                 8    [        U5      U R                  l        g rz   )r   r   r   r   s     r4   r   r      s    #5d#;

 r6   r/   N)	r   r   r   r   r   r   r   r   r   r/   r6   r4   r   r      s5     ( ( < <r6   r   aV  mean : array_like, default: ``[0]``
    Mean of the distribution.
cov : array_like or `Covariance`, default: ``[1]``
    Symmetric positive (semi)definite covariance matrix of the distribution.
allow_singular : bool, default: ``False``
    Whether to allow a singular covariance matrix. This is ignored if `cov` is
    a `Covariance` object.
a5  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, a two-dimensional array_like,
or a `Covariance` object.
 z>See class definition for a detailed description of parameters.)_mvn_doc_default_callparams_mvn_doc_callparams_note_doc_random_statec                      ^  \ rS rSrSrSU 4S jjrSS jrSS jrS rS r	S	 r
S
 rSS jrSS jrS r  SSS.S jjr  SSS.S jjrSS jrSS jrSS jrSrU =r$ )multivariate_normal_geni%  aG  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, lower_limit=None)
    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(mean=None, cov=1)
    Compute the differential entropy of the multivariate normal.
fit(x, fix_mean=None, fix_cov=None)
    Fit a multivariate normal distribution to data.

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

Notes
-----
%(_mvn_doc_callparams_note)s

The covariance matrix `cov` may be an instance of a subclass of
`Covariance`, e.g. `scipy.stats.CovViaPrecision`. If so, `allow_singular`
is ignored.

Otherwise, `cov` must be a symmetric positive semidefinite
matrix when `allow_singular` is True; it must be (strictly) positive
definite when `allow_singular` is False.
Symmetry is not checked; only the lower triangular portion is used.
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,
:math:`k` the rank of :math:`\Sigma`. In case of singular :math:`\Sigma`,
SciPy extends this definition according to [1]_.

.. versionadded:: 0.14.0

References
----------
.. [1] Multivariate Normal Distribution - Degenerate Case, Wikipedia,
       https://en.wikipedia.org/wiki/Multivariate_normal_distribution#Degenerate_case

Examples
--------
>>> import numpy as np
>>> 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)
>>> plt.show()

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.

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                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   	docformatr   mvn_docdict_paramsr   s     r4   rp    multivariate_normal_gen.__init__  )    ''6HIr6   c                     [        XUUS9$ )zjCreate a frozen multivariate normal distribution.

See `multivariate_normal_frozen` for more information.
)rk   r   )multivariate_normal_frozen)ri   meancovrk   r   s        r4   __call__ multivariate_normal_gen.__call__  s    
 *$9G/35 	5r6   c                     [        U[        R                  5      (       a  U R                  X5      $ U R	                  SX5      u  pAn[        X#S9n[        R                  " U5      nXAU4$ )zt
Infer dimensionality from mean or covariance matrix, ensure that
mean and covariance are full vector resp. matrix.
Nrk   )
isinstancer   
Covariance_process_parameters_Covariance_process_parameters_psdrR   	CovViaPSD)ri   r   r   rk   dimpsd
cov_objects          r4   _process_parameters+multivariate_normal_gen._process_parameters  sg    
 c;112266tAA "99$JNCs s:C$..s3Jj((r6   c                     UR                   S   nUc  [        R                  " S/5      OUnSU SU4 3n [        R                  " X5      nX1U4$ ! [         a  n[	        U5      UeS nAff = f)Nr8           z(`cov` represents a covariance matrix in z9 dimensions,and so `mean` must be broadcastable to shape )shaper?   rL   broadcast_tor]   )ri   r   r   r   messagees         r4   r   6multivariate_normal_gen._process_parameters_Covariance  s    iim!%rxx~4=cU CCDG6(L	-??4-D #~  	-W%1,	-s   A 
A+A&&A+c                 t   Uck  UcB  Uc  SnO[         R                  " U[        S9nUR                  S:  a  SnO\UR                  S   nOL[         R                  " U[        S9nUR
                  nO&[         R                  " U5      (       d  [        S5      eUc  [         R                  " U5      n[         R                  " U[        S9nUc  Sn[         R                  " U[        S9nUS:X  a#  UR                  S5      nUR                  SS5      nUR                  S:w  d  UR                  S   U:w  a  [        SU-  5      eUR                  S:X  a  U[         R                  " U5      -  nOUR                  S:X  a  [         R                  " U5      nOUR                  S:X  an  UR                  X4:w  a]  UR                  u  pEXE:w  a  S[        UR                  5       S	3nO%S
nU[        UR                  5      [        U5      4-  n[        U5      eUR                  S:  a  [        SUR                  -  5      eXU4$ )Nr   rK   r-   r   z.Dimension of random variable must be a scalar.      ?z+Array 'mean' must be a vector of length %d.EArray 'cov' must be square if it is two dimensional, but cov.shape = .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?   rW   rM   r1   r   sizeisscalarr]   zerosreshapeeyediagstrr^   )ri   r   r   r   rowscolsrn   s          r4   r   /multivariate_normal_gen._process_parameters_psd  s   ;|;C**S6Cxx!|!iilzz$e4ii;;s##  "- . .
 <88C=Dzz$e,;CjjE*!8<<?D++a#C99>TZZ]c1J ! " "88q=s#CXX]''#,CXX]syySJ6JD|++.syy>*:!=?S^SY77S/!XX\ 247HH= > > #~r6   c                    [         R                  " U[        S9nUR                  S:X  a  U[         R                     nU$ UR                  S:X  a6  US:X  a  USS2[         R                  4   nU$ U[         R                  SS24   nU$ T
Adjust quantiles array so that last axis labels the components of
each data point.
rK   r   r   Nr?   rW   rM   r1   newaxisri   rO   r   s      r4   _process_quantiles*multivariate_normal_gen._process_quantiles  sy    
 JJq&66Q;"**A  VVq[axam$  bjj!m$r6   c                 @   UR                   UR                  pTX-
  nUR                  S:  a*  US[        R                  4   nUS[        R                  4   n[        R
                  " [        R                  " UR                  U5      5      SS9nSU[        -  U-   U-   -  $ )a  Log of the multivariate normal probability density function.

Parameters
----------
x : ndarray
    Points at which to evaluate the log of the probability
    density function
mean : ndarray
    Mean of the distribution
cov_object : Covariance
    An object representing the Covariance matrix

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

r   .r8   rs         )	rg   rc   r1   r?   r   re   squarewhiten_LOG_2PI)ri   rO   r   r   log_det_covrc   devmahas           r4   _logpdfmultivariate_normal_gen._logpdf  s    & '//Th88a<%c2::o6KRZZ(Dvvbii
 1 1# 67bAth4t;<<r6   c                 *   U R                  X#U5      nUu  pbnU R                  X5      nU R                  XU5      n[        R                  " UR
                  U:  5      (       a'  UR                  X-
  5      ) n	[        R                  * X'   [        U5      $ )aV  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

)	r   r   r   r?   anyrc   rw   infr5   
ri   rO   r   r   rk   paramsr   r   r3   out_of_boundss
             r4   logpdfmultivariate_normal_gen.logpdf  s    & ))$^D &:##A+ll1J/66*//C'(('55af==M"$&&Cs##r6   c                 4   U R                  X#U5      nUu  pbnU R                  X5      n[        R                  " U R	                  XU5      5      n[        R
                  " UR                  U:  5      (       a  UR                  X-
  5      ) n	SX'   [        U5      $ )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

r   )	r   r   r?   expr   r   rc   rw   r5   r   s
             r4   pdfmultivariate_normal_gen.pdf9  s    & ))$^D &:##A+ffT\\!:6766*//C'(('55af==M!$Cs##r6   c                   ^^^^^^ Uc0  [         R                  " TR                  [         R                  * 5      OUn[         R                  " X5      u  pX:  nSUR                  SS9-  nU
R                  5       U	R                  5       pX   X   sX'   X'   UR                  S   m[         R                  " X4SS9nUUUUUU4S jn[         R                  " USU5      U-  n[        U5      $ )a  Multivariate normal cumulative distribution function.

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
lower_limit : array_like, optional
    Lower limit of integration of the cumulative distribution function.
    Default is negative infinity. Must be broadcastable with `x`.

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


.. versionadded:: 1.0.0

r8   rs   c           
         > [            [        R                  " U S T U TS  TTTTT5      S   sS S S 5        $ ! , (       d  f       g = fNr   )MVN_LOCKr   mvnun)limitsabsepsr   maxptsr   nrelepss    r4   func1d,multivariate_normal_gen._cdf.<locals>.func1d  s?    zz&!*fQRj$ &889; s	   %7
A)
r?   fullr   r   broadcast_arraysre   copyconcatenateapply_along_axisr5   )ri   rO   r   r   r   r   r   lower_limitr>   bai_swapsignsr   r  r3   r   s     `````         @r4   _cdfmultivariate_normal_gen._cdfU  s    >  ' bffW--8 	 ""1,vzzrz*+vvx1 y!)	19GGBKR0	; 	;
 !!&"f5=s##r6   r  c          	      $   U R                  X#U5      n	U	u  pnUR                  nU R                  X5      nU(       d  SU
-  nU R                  XX5XgU5      n[        R
                  " US:  5      (       a  US-   OUn[        R                  " U5      nU$ )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)
lower_limit : array_like, optional
    Lower limit of integration of the cumulative distribution function.
    Default is negative infinity. Must be broadcastable with `x`.

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

Notes
-----
%(_mvn_doc_callparams_note)s

.. versionadded:: 1.0.0

@B r                   )r   
covariancer   r  r?   r   rf   )ri   rO   r   r   rk   r   r   r   r  r   r   r   cdfr3   s                 r4   logcdfmultivariate_normal_gen.logcdf  s    @ ))$^D &:####A+s]FiifkJ &&q//cBhsffSk
r6   c          	          U R                  X#U5      n	U	u  pnUR                  nU R                  X5      nU(       d  SU
-  nU R                  XX5XgU5      nU$ )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)
lower_limit : array_like, optional
    Lower limit of integration of the cumulative distribution function.
    Default is negative infinity. Must be broadcastable with `x`.

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

Notes
-----
%(_mvn_doc_callparams_note)s

.. versionadded:: 1.0.0

r  )r   r  r   r  )ri   rO   r   r   rk   r   r   r   r  r   r   r   r3   s                r4   r  multivariate_normal_gen.cdf  sa    @ ))$^D &:####A+s]FiifkJ
r6   c                    U R                  X5      u  pQnU R                  U5      n[        U[        R                  5      (       a+  UR
                  nUR                  XU5      n[        U5      nU$ U=(       d
    [        5       n[        R                  " U5      (       d  U4n[        U5      UR                  S   4-   nUR                  US9n	XR                  U	5      -   nU$ )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

r8   r   )r   r   r   r   r   r  r   r5   tupler?   iterabler   normalcolorize)
ri   r   r   r   r   r   r   r3   r   rO   s
             r4   rvsmultivariate_normal_gen.rvs  s    * !% 8 8 C:--l;j+"7"788''C224dCC!#&C 
 ?57D;;t$$w$K:#3#3B#7"99E###/A,,Q//C
r6   c                 v    U R                  X5      u  p1nSUR                  [        S-   -  UR                  -   -  $ )zCompute 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

      ?r   )r   rc   r   rg   )ri   r   r   r   r   s        r4   entropymultivariate_normal_gen.entropy  s<    " !% 8 8 C:jooA69L9LLMMr6   c                 d   [         R                  " U5      nUR                  S:w  a  [        S5      eUR                  u  pEUb7  [         R
                  " U5      nUR                  U4:w  a  Sn[        U5      eUnOUR                  SS9nUb  [         R                  " U5      nUR                  XU4:w  a  Sn[        U5      e[        R                  R                  USSS9u  p[        U5      n
[         R                  " U5      U
* :  a  S	n[        U5      eUnX{4$ X-
  nUR                  U-  U-  nX{4$ )
a  Fit a multivariate normal distribution to data.

Parameters
----------
x : ndarray (m, n)
    Data the distribution is fitted to. Must have two axes.
    The first axis of length `m` represents the number of vectors
    the distribution is fitted to. The second axis of length `n`
    determines the dimensionality of the fitted distribution.
fix_mean : ndarray(n, )
    Fixed mean vector. Must have length `n`.
fix_cov: ndarray (n, n)
    Fixed covariance matrix. Must have shape ``(n, n)``.

Returns
-------
mean : ndarray (n, )
    Maximum likelihood estimate of the mean vector
cov : ndarray (n, n)
    Maximum likelihood estimate of the covariance matrix

r-   z`x` must be two-dimensional.zd`fix_mean` must be a one-dimensional array the same length as the dimensionality of the vectors `x`.r   rs   zn`fix_cov` must be a two-dimensional square array of same side length as the dimensionality of the vectors `x`.TrU   z2`fix_cov` must be symmetric positive semidefinite.)r?   rW   r1   r]   r   
atleast_1dr   
atleast_2drY   rZ   r[   rI   r\   r|   )ri   rO   fix_meanfix_cov	n_vectorsr   rn   r   rl   rm   rA   r   centered_datas                r4   fitmultivariate_normal_gen.fit  s/   0 JJqM66Q;;<<	 }}X.H~~#(J o%D66q6>DmmG,G}}
*& !o% <<$$WDt$LDA"1%CvvayC4J o%C y HM//M1I=Cyr6   r   rz   )Nr   FN)T)Nr   F)Nr   FNh㈵>r/  Nr   r   NNr   NN)r   r   r   r   r   rp   r   r   r   r   r   r   r   r   r  r  r  r  r#  r,  r   r   r   s   @r4   r   r   %  s    `DJ5)0	7r"=6$8$83$j HL#'+8<+Z EI $'59'R#JN(? ?r6   r   c                   j    \ rS rSr  SS jr\S 5       rS rS rSS.S jr	SS.S	 jr
SS
 jrS rSrg)r   i^  Nc                    [        U5      U l        U R                  R                  XU5      u  U l        U l        U l        U=(       d    U R
                  R                  U l        U(       d  SU R                  -  nXPl        X`l	        Xpl
        g)aH  Create a frozen multivariate normal distribution.

Parameters
----------
mean : array_like, default: ``[0]``
    Mean of the distribution.
cov : array_like, default: ``[1]``
    Symmetric positive (semi)definite covariance matrix of the
    distribution.
allow_singular : bool, default: ``False``
    Whether to allow a singular covariance matrix.
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.
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.]])

r  N)r   r   r   r   r   r   _allow_singularrk   r   r   r   )ri   r   r   rk   r   r   r   r   s           r4   rp   #multivariate_normal_frozen.__init___  sm    V -T2
JJ**4nE 	-$)T_,O0O0Otxx'Fr6   c                 .    U R                   R                  $ rz   )r   r  r}   s    r4   r   multivariate_normal_frozen.cov  s    )))r6   c                    U R                   R                  XR                  5      nU R                   R                  XR                  U R
                  5      n[        R                  " U R
                  R                  U R                  :  5      (       a;  U R
                  R                  XR                  -
  5      ) n[        R                  * X#'   [        U5      $ rz   )r   r   r   r   r   r   r?   r   rc   rw   r   r5   )ri   rO   r3   r   s       r4   r   !multivariate_normal_frozen.logpdf  s    JJ))!XX6jj  IIt?66$//&&122!__::1YY;GGM"$&&Cs##r6   c                 L    [         R                  " U R                  U5      5      $ rz   r?   r   r   ri   rO   s     r4   r   multivariate_normal_frozen.pdf      vvdkk!n%%r6   r  c                    U R                  XS9n[        R                  " US:  5      (       a  US-   OUn[        R                  " U5      nU$ )Nr  r   r  )r  r?   r   rf   )ri   rO   r  r  r3   s        r4   r  !multivariate_normal_frozen.logcdf  sA    hhqh2 &&q//cBhsffSk
r6   c          	         U R                   R                  XR                  5      nU R                   R                  XR                  U R
                  R                  U R                  U R                  U R                  U5      n[        U5      $ rz   )r   r   r   r  r   r   r  r   r   r   r5   )ri   rO   r  r3   s       r4   r  multivariate_normal_frozen.cdf  sa    JJ))!XX6jjooaDOO,F,F"kk4;;)+ s##r6   c                 d    U R                   R                  U R                  U R                  X5      $ rz   )r   r  r   r   ri   r   r   s      r4   r  multivariate_normal_frozen.rvs  s!    zz~~dii$MMr6   c                 ~    U R                   R                  nU R                   R                  nSU[        S-   -  U-   -  $ )zComputes the differential entropy of the multivariate normal.

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

r"  r   )r   rg   rc   r   )ri   rg   rc   s      r4   r#  "multivariate_normal_frozen.entropy  s;     ??++##dhl+h677r6   )r   r   rk   r   r   r   r   r   )Nr   FNNr/  r/  r   N)r   r   r   r   rp   r   r   r   r   r  r  r  r#  r   r/   r6   r4   r   r   ^  sK    DH263j * *$& (,  %) $N8r6   r   )r   r   r  r  r  a  mean : array_like, optional
    Mean of the distribution (default: `None`)
rowcov : array_like, optional
    Among-row covariance matrix of the distribution (default: ``1``)
colcov : array_like, optional
    Among-column covariance matrix of the distribution (default: ``1``)
a  If `mean` is set to `None` then a matrix of zeros is used for the mean.
The dimensions of this matrix are inferred from the shape of `rowcov` and
`colcov`, if these are provided, or set to ``1`` if ambiguous.

`rowcov` and `colcov` can be two-dimensional array_likes specifying the
covariance matrices directly. Alternatively, a one-dimensional array will
be be interpreted as the entries of a diagonal matrix, and a scalar or
zero-dimensional array will be interpreted as this value times the
identity matrix.
)_matnorm_doc_default_callparams_matnorm_doc_callparams_noter   c                   z   ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	SS jr
SS	 jrSS
 jrSS jrS rSrU =r$ )matrix_normal_geni  a  A matrix normal random variable.

The `mean` keyword specifies the mean. The `rowcov` keyword specifies the
among-row covariance matrix. The 'colcov' keyword specifies the
among-column covariance matrix.

Methods
-------
pdf(X, mean=None, rowcov=1, colcov=1)
    Probability density function.
logpdf(X, mean=None, rowcov=1, colcov=1)
    Log of the probability density function.
rvs(mean=None, rowcov=1, colcov=1, size=1, random_state=None)
    Draw random samples.
entropy(rowcol=1, colcov=1)
    Differential entropy.

Parameters
----------
%(_matnorm_doc_default_callparams)s
%(_doc_random_state)s

Notes
-----
%(_matnorm_doc_callparams_note)s

The covariance matrices specified by `rowcov` and `colcov` must be
(symmetric) positive definite. If the samples in `X` are
:math:`m \times n`, then `rowcov` must be :math:`m \times m` and
`colcov` must be :math:`n \times n`. `mean` must be the same shape as `X`.

The probability density function for `matrix_normal` is

.. math::

    f(X) = (2 \pi)^{-\frac{mn}{2}}|U|^{-\frac{n}{2}} |V|^{-\frac{m}{2}}
           \exp\left( -\frac{1}{2} \mathrm{Tr}\left[ U^{-1} (X-M) V^{-1}
           (X-M)^T \right] \right),

where :math:`M` is the mean, :math:`U` the among-row covariance matrix,
:math:`V` the among-column covariance matrix.

The `allow_singular` behaviour of the `multivariate_normal`
distribution is not currently supported. Covariance matrices must be
full rank.

The `matrix_normal` distribution is closely related to the
`multivariate_normal` distribution. Specifically, :math:`\mathrm{Vec}(X)`
(the vector formed by concatenating the columns  of :math:`X`) has a
multivariate normal distribution with mean :math:`\mathrm{Vec}(M)`
and covariance :math:`V \otimes U` (where :math:`\otimes` is the Kronecker
product). Sampling and pdf evaluation are
:math:`\mathcal{O}(m^3 + n^3 + m^2 n + m n^2)` for the matrix normal, but
:math:`\mathcal{O}(m^3 n^3)` for the equivalent multivariate normal,
making this equivalent form algorithmically inefficient.

.. versionadded:: 0.17.0

Examples
--------

>>> import numpy as np
>>> from scipy.stats import matrix_normal

>>> M = np.arange(6).reshape(3,2); M
array([[0, 1],
       [2, 3],
       [4, 5]])
>>> U = np.diag([1,2,3]); U
array([[1, 0, 0],
       [0, 2, 0],
       [0, 0, 3]])
>>> V = 0.3*np.identity(2); V
array([[ 0.3,  0. ],
       [ 0. ,  0.3]])
>>> X = M + 0.1; X
array([[ 0.1,  1.1],
       [ 2.1,  3.1],
       [ 4.1,  5.1]])
>>> matrix_normal.pdf(X, mean=M, rowcov=U, colcov=V)
0.023410202050005054

>>> # Equivalent multivariate normal
>>> from scipy.stats import multivariate_normal
>>> vectorised_X = X.T.flatten()
>>> equiv_mean = M.T.flatten()
>>> equiv_cov = np.kron(V,U)
>>> multivariate_normal.pdf(vectorised_X, mean=equiv_mean, cov=equiv_cov)
0.023410202050005054

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

>>> rv = matrix_normal(mean=None, rowcov=1, colcov=1)
>>> # Frozen object with the same methods but holding the given
>>> # mean and covariance fixed.

c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   r   r   matnorm_docdict_paramsr   s     r4   rp   matrix_normal_gen.__init__X  )    ''6LMr6   c                     [        XX4S9$ )z_Create a frozen matrix normal distribution.

See `matrix_normal_frozen` for more information.

r   )matrix_normal_frozenri   r   rowcovcolcovr   s        r4   r   matrix_normal_gen.__call__\  s     $D&DDr6   c                    Ubh  [         R                  " U[        S9nUR                  n[	        U5      S:w  a  [        S5      e[         R                  " US:H  5      (       a  [        S5      e[         R                  " U[        S9nUR                  S:X  a:  Ub  U[         R                  " WS   5      -  nO@U[         R                  " S5      -  nO&UR                  S:X  a  [         R                  " U5      nUR                  n[	        U5      S:w  a  [        S5      eUS   US   :w  a  [        S5      eUS   S:X  a  [        S	5      eUS   n[         R                  " U[        S9nUR                  S:X  a:  Ub  U[         R                  " WS   5      -  nO@U[         R                  " S5      -  nO&UR                  S:X  a  [         R                  " U5      nUR                  n[	        U5      S:w  a  [        S
5      eUS   US   :w  a  [        S5      eUS   S:X  a  [        S5      eUS   nUb)  WS   U:w  a  [        S5      eUS   U:w  a  [        S5      eO[         R                  " Xh45      nXh4n	XX#4$ )zg
Infer dimensionality from mean or covariance matrices. Handle
defaults. Ensure compatible dimensions.
rK   r-   z%Array `mean` must be two dimensional.r   zArray `mean` has invalid shape.r   z(`rowcov` must be a scalar or a 2D array.zArray `rowcov` must be square.z!Array `rowcov` has invalid shape.z(`colcov` must be a scalar or a 2D array.zArray `colcov` must be square.z!Array `colcov` has invalid shape.z=Arrays `mean` and `rowcov` must have the same number of rows.z@Arrays `mean` and `colcov` must have the same number of columns.)r?   rW   rM   r   r^   r]   r   r1   identityr   r   )
ri   r   rV  rW  	meanshaperowshapenumrowscolshapenumcolsdimss
             r4   r   %matrix_normal_gen._process_parametersd  sQ    ::d%0D

I9~" !HIIvvi1n%% !BCC F%0;;!"++il";;"++a.0[[AWWV_F<<x=AGHHA;(1+%=>>A;!@AA1+ F%0;;!"++il";;"++a.0[[AWWV_F<<x=AGHHA;(1+%=>>A;!@AA1+ |w&  "8 9 9|w&  "; < < ' 88W./D!6))r6   c                     [         R                  " U[        S9nUR                  S:X  a  U[         R                  SS24   nUR
                  SS U:w  a  [        S5      eU$ )zX
Adjust quantiles array so that last two axes labels the components of
each data point.
rK   r-   NzJThe shape of array `X` is not compatible with the distribution parameters.)r?   rW   rM   r1   r   r   r]   )ri   Xr`  s      r4   r   $matrix_normal_gen._process_quantiles  s]    
 JJq&66Q;"**a- A7723<4 A B Br6   c                 X   Uu  p[         R                  " X#-
  SS5      n
[         R                  " UR                  [         R                  " X5      S5      n[         R
                  " [         R
                  " [         R                  " U5      SS9SS9nSX-  [        -  X-  -   X-  -   U-   -  $ )aQ  Log of the matrix normal probability density function.

Parameters
----------
dims : tuple
    Dimensions of the matrix variates
X : ndarray
    Points at which to evaluate the log of the probability
    density function
mean : ndarray
    Mean of the distribution
row_prec_rt : ndarray
    A decomposition such that np.dot(row_prec_rt, row_prec_rt.T)
    is the inverse of the among-row covariance matrix
log_det_rowcov : float
    Logarithm of the determinant of the among-row covariance matrix
col_prec_rt : ndarray
    A decomposition such that np.dot(col_prec_rt, col_prec_rt.T)
    is the inverse of the among-column covariance matrix
log_det_colcov : float
    Logarithm of the determinant of the among-column covariance matrix

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

r8   r   r   rs   r   )r?   moveaxis	tensordotr|   r{   re   r   r   )ri   r`  rd  r   row_prec_rtlog_det_rowcovcol_prec_rtlog_det_colcovr]  r_  roll_dev	scale_devr   s                r4   r   matrix_normal_gen._logpdf  s    <  ;;qvr1-LL!#!>C	vvbffRYYy1;!Dwx/'2HH /0267 8 	8r6   c           	         U R                  X#U5      u  pRp4U R                  X5      n[        USS9n[        USS9nU R                  XQX&R                  UR
                  UR                  UR
                  5      n[        U5      $ )aU  Log of the matrix normal probability density function.

Parameters
----------
X : array_like
    Quantiles, with the last two axes of `X` denoting the components.
%(_matnorm_doc_default_callparams)s

Returns
-------
logpdf : ndarray
    Log of the probability density function evaluated at `X`

Notes
-----
%(_matnorm_doc_callparams_note)s

Fr   )r   r   rR   r   rd   rg   r5   )	ri   rd  r   rV  rW  r`  rowpsdcolpsdr3   s	            r4   r   matrix_normal_gen.logpdf  s{    & &*%=%=d>D&F"F##A,fU3fU3ll4D((FOOVXX!??,s##r6   c                 N    [         R                  " U R                  XX45      5      $ )a<  Matrix normal probability density function.

Parameters
----------
X : array_like
    Quantiles, with the last two axes of `X` denoting the components.
%(_matnorm_doc_default_callparams)s

Returns
-------
pdf : ndarray
    Probability density function evaluated at `X`

Notes
-----
%(_matnorm_doc_callparams_note)s

r<  )ri   rd  r   rV  rW  s        r4   r   matrix_normal_gen.pdf  s    & vvdkk!6:;;r6   c           	         [        U5      nU R                  XU5      u  pap#[        R                  R	                  USS9n[        R                  R	                  USS9nU R                  U5      nUR                  US   XFS   4S9R                  SSS5      n	U[        R                  " SXyUSS9-   n
US:X  a  U
R                  UR                  5      n
U
$ )	a  Draw random samples from a matrix normal distribution.

Parameters
----------
%(_matnorm_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`, `dims`), where `dims` is the
    dimension of the random matrices.

Notes
-----
%(_matnorm_doc_callparams_note)s

Tr>   r   r   r  r-   zjp,ipq,kq->ijk)optimize)intr   rY   rZ   choleskyr   standard_normal	transposer?   einsumr   r   )ri   r   rV  rW  r   r   r`  rowcholcolcholstd_normr3   s              r4   r  matrix_normal_gen.rvs
  s    * 4y%)%=%=d>D&F"F,,''d';,,''d';--l;
  //q'4a) 0 

)Aq!
 	 RYY/&'(,. . 19++djj)C
r6   c                    [         R                  " UR                  S   UR                  S   45      nU R                  UUU5      u  pEp[	        USS9n[	        USS9nU R                  XFR                  UR                  5      $ )a  Log of the matrix normal probability density function.

Parameters
----------
rowcov : array_like, optional
    Among-row covariance matrix of the distribution (default: ``1``)
colcov : array_like, optional
    Among-column covariance matrix of the distribution (default: ``1``)

Returns
-------
entropy : float
    Entropy of the distribution

Notes
-----
%(_matnorm_doc_callparams_note)s

r   Fr   )r?   r   r   r   rR   _entropyrg   )ri   rV  rW  
dummy_meanr`  _rq  rr  s           r4   r#  matrix_normal_gen.entropy3  sx    ( XXv||AQ@A
"&":"::;A;A#C fU3fU3}}T??FOODDr6   c                 R    Uu  pESU-  U-  S[         -   -  SU-  U-  -   SU-  U-  -   $ Nr"  r   )r   )ri   r`  row_cov_logdetcol_cov_logdetr   ps         r4   r  matrix_normal_gen._entropyP  sA    a!q8|,sQw/GGa.() 	*r6   r.  rz   r0  Nr   r   Nr   r   r   Nr   r   )r   r   r   r   r   rp   r   r   r   r   r   r   r  r#  r  r   r   r   s   @r4   rM  rM    sH    bHNE@*D$8L$8<*'RE:* *r6   rM  c                   >    \ rS rSrSrS
S jrS rS rSS jrS r	S	r
g)rT  iY  aR  
Create a frozen matrix normal distribution.

Parameters
----------
%(_matnorm_doc_default_callparams)s
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    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`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import matrix_normal

>>> distn = matrix_normal(mean=np.zeros((3,3)))
>>> X = distn.rvs(); X
array([[-0.02976962,  0.93339138, -0.09663178],
       [ 0.67405524,  0.28250467, -0.93308929],
       [-0.31144782,  0.74535536,  1.30412916]])
>>> distn.pdf(X)
2.5160642368346784e-05
>>> distn.logpdf(X)
-10.590229595124615
Nc                     [        U5      U l        U R                  R                  XU5      u  U l        U l        U l        U l        [        U R
                  SS9U l        [        U R                  SS9U l	        g )NFr   )
rM  r   r   r`  r   rV  rW  rR   rq  rr  rU  s        r4   rp   matrix_normal_frozen.__init__x  s[    &t,
JJ**4@ 	7	49dk4;4;;u=4;;u=r6   c           	      j   U R                   R                  XR                  5      nU R                   R                  U R                  XR                  U R
                  R                  U R
                  R                  U R                  R                  U R                  R                  5      n[        U5      $ rz   )
r   r   r`  r   r   rq  rd   rg   rr  r5   )ri   rd  r3   s      r4   r   matrix_normal_frozen.logpdf  su    JJ))!YY7jj  Ayy$++--!%!5!5t{{}}!%!5!57 s##r6   c                 L    [         R                  " U R                  U5      5      $ rz   r<  )ri   rd  s     r4   r   matrix_normal_frozen.pdf  r?  r6   c                 |    U R                   R                  U R                  U R                  U R                  UU5      $ rz   )r   r  r   rV  rW  rE  s      r4   r  matrix_normal_frozen.rvs  s.    zz~~diidkk4*, 	,r6   c                     U R                   R                  U R                  U R                  R                  U R
                  R                  5      $ rz   )r   r  r`  rq  rg   rr  r}   s    r4   r#  matrix_normal_frozen.entropy  s8    zz""499dkk.B.B#';;#7#79 	9r6   )r   rW  rr  r`  r   rV  rq  r0  rI  )r   r   r   r   r   rp   r   r   r  r#  r   r/   r6   r4   rT  rT  Y  s     <>$&,9r6   rT  )r   r   r  r#  zalpha : array_like
    The concentration parameters. The number of entries determines the
    dimensionality of the distribution.
)!_dirichlet_doc_default_callparamsr   c                     [         R                  " U 5      n [         R                  " U 5      S::  a  [        S5      eU R                  S:w  a  [        SU R
                   S35      eU $ )Nr   z%All parameters must be greater than 0r   z<Parameter vector 'a' must be one dimensional, but a.shape = r   )r?   rW   r\   r]   r1   r   alphas    r4   _dirichlet_check_parametersr    s^    JJuE	vve}@AA	q **/++a9 : 	:Lr6   c                    [         R                  " U5      nUR                  S   S-   U R                  S   :w  aF  UR                  S   U R                  S   :w  a&  [        SU R                   SUR                   S35      eUR                  S   U R                  S   :w  a  [         R                  " S[         R
                  " US5      -
  /5      nUR                  S:X  a  [         R                  " X5      nO3UR                  S:X  a  [         R                  " X45      nO[        S5      e[         R                  " U5      S:  a  [        S5      e[         R                  " U5      S:  a  [        S	5      eUS:H  nU S:  nUR                  U R                  :w  a;  [         R                  " XAR                  S
   S
S9R                  UR                  5      n[         R                  " X45      n[         R
                  " U5      (       a  [        S5      e[         R                  " [         R
                  " US5      S-
  5      S:  R                  5       (       a$  [        S[         R
                  " US5       S35      eU$ )Nr   r   z|Vector 'x' must have either the same number of entries as, or one entry fewer than, parameter vector 'a', but alpha.shape = z and x.shape = r   r-   zUThe input must be one dimensional or a two dimensional matrix containing the entries.z8Each entry in 'x' must be greater than or equal to zero.z/Each entry in 'x' must be smaller or equal one.r8   rs   zJEach entry in 'x' must be greater than zero if its alpha is less than one.r   g&.>zLThe input vector 'x' must lie within the normal simplex. but np.sum(x, 0) = )r?   rW   r   r]   rL   re   r1   appendvstackr\   rB   repeatr   logical_andrC   r   )r  rO   xkxeq0alphalt1chks         r4   _dirichlet_check_inputr    s   


1AwwqzA~Q'AGGAJ%++a.,H DDIKK= Q**+''!5 6 	6
 	wwqzU[[^#XXq266!Q<'()77a<		! AWW\		1'"A J K K 
vvay1} $ % 	% 
vvay1}JKK FD	Hww%++99Xwwr{<DDQWWM
..
(C	vvc{{ 3 4 	4 	rvva|c!"V+0022 88:q!~QH I 	I Hr6   c                     [         R                  " [        U 5      5      [        [         R                  " U 5      5      -
  $ )aJ  Internal helper function to compute the log of the useful quotient.

.. math::

    B(\alpha) = \frac{\prod_{i=1}{K}\Gamma(\alpha_i)}
                     {\Gamma\left(\sum_{i=1}^{K} \alpha_i \right)}

Parameters
----------
%(_dirichlet_doc_default_callparams)s

Returns
-------
B : scalar
    Helper quotient, internal use only

)r?   re   r   r  s    r4   _lnBr    s)    $ 66'%.!GBFF5M$:::r6   c                   n   ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
 rS rSS jrSrU =r$ )dirichlet_geni  a~  A Dirichlet random variable.

The ``alpha`` keyword specifies the concentration parameters of the
distribution.

.. versionadded:: 0.15.0

Methods
-------
pdf(x, alpha)
    Probability density function.
logpdf(x, alpha)
    Log of the probability density function.
rvs(alpha, size=1, random_state=None)
    Draw random samples from a Dirichlet distribution.
mean(alpha)
    The mean of the Dirichlet distribution
var(alpha)
    The variance of the Dirichlet distribution
cov(alpha)
    The covariance of the Dirichlet distribution
entropy(alpha)
    Compute the differential entropy of the Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s
%(_doc_random_state)s

Notes
-----
Each :math:`\alpha` entry must be positive. The distribution has only
support on the simplex defined by

.. math::
    \sum_{i=1}^{K} x_i = 1

where :math:`0 < x_i < 1`.

If the quantiles don't lie within the simplex, a ValueError is raised.

The probability density function for `dirichlet` is

.. math::

    f(x) = \frac{1}{\mathrm{B}(\boldsymbol\alpha)} \prod_{i=1}^K x_i^{\alpha_i - 1}

where

.. math::

    \mathrm{B}(\boldsymbol\alpha) = \frac{\prod_{i=1}^K \Gamma(\alpha_i)}
                                 {\Gamma\bigl(\sum_{i=1}^K \alpha_i\bigr)}

and :math:`\boldsymbol\alpha=(\alpha_1,\ldots,\alpha_K)`, the
concentration parameters and :math:`K` is the dimension of the space
where :math:`x` takes values.

Note that the `dirichlet` interface is somewhat inconsistent.
The array returned by the rvs function is transposed
with respect to the format expected by the pdf and logpdf.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import dirichlet

Generate a dirichlet random variable

>>> quantiles = np.array([0.2, 0.2, 0.6])  # specify quantiles
>>> alpha = np.array([0.4, 5, 15])  # specify concentration parameters
>>> dirichlet.pdf(quantiles, alpha)
0.2843831684937255

The same PDF but following a log scale

>>> dirichlet.logpdf(quantiles, alpha)
-1.2574327653159187

Once we specify the dirichlet distribution
we can then calculate quantities of interest

>>> dirichlet.mean(alpha)  # get the mean of the distribution
array([0.01960784, 0.24509804, 0.73529412])
>>> dirichlet.var(alpha) # get variance
array([0.00089829, 0.00864603, 0.00909517])
>>> dirichlet.entropy(alpha)  # calculate the differential entropy
-4.3280162474082715

We can also return random samples from the distribution

>>> dirichlet.rvs(alpha, size=1, random_state=1)
array([[0.00766178, 0.24670518, 0.74563305]])
>>> dirichlet.rvs(alpha, size=2, random_state=2)
array([[0.01639427, 0.1292273 , 0.85437844],
       [0.00156917, 0.19033695, 0.80809388]])

Alternatively, the object may be called (as a function) to fix
concentration parameters, returning a "frozen" Dirichlet
random variable:

>>> rv = dirichlet(alpha)
>>> # Frozen object with the same methods but holding the given
>>> # concentration parameters fixed.

c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   r   r   dirichlet_docdict_paramsr   s     r4   rp   dirichlet_gen.__init__g  s)    ''6NOr6   c                     [        XS9$ NrS  )dirichlet_frozenri   r  r   s      r4   r   dirichlet_gen.__call__k  s    11r6   c                     [        U5      nU* [        R                  " [        US-
  UR                  5      R                  S5      -   $ )a>  Log of the Dirichlet probability density function.

Parameters
----------
x : ndarray
    Points at which to evaluate the log of the probability
    density function
%(_dirichlet_doc_default_callparams)s

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

r   r   )r  r?   re   r   r|   )ri   rO   r  lnBs       r4   r   dirichlet_gen._logpdfn  s:      5kurvvuUQY477;;;r6   c                 f    [        U5      n[        X!5      nU R                  X5      n[        U5      $ )a)  Log of the Dirichlet probability density function.

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

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

)r  r  r   r5   ri   rO   r  r3   s       r4   r   dirichlet_gen.logpdf  s1     ,E2"5,ll1$s##r6   c                     [        U5      n[        X!5      n[        R                  " U R	                  X5      5      n[        U5      $ )a  The Dirichlet probability density function.

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

Returns
-------
pdf : ndarray or scalar
    The probability density function evaluated at `x`.

)r  r  r?   r   r   r5   r  s       r4   r   dirichlet_gen.pdf  s:     ,E2"5,ffT\\!+,s##r6   c                 `    [        U5      nU[        R                  " U5      -  n[        U5      $ )zMean of the Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s

Returns
-------
mu : ndarray or scalar
    Mean of the Dirichlet distribution.

r  r?   re   r5   )ri   r  r3   s      r4   r   dirichlet_gen.mean  s+     ,E2rvve}%s##r6   c                 ~    [        U5      n[        R                  " U5      nXU-
  -  X"-  US-   -  -  n[        U5      $ )zVariance of the Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s

Returns
-------
v : ndarray or scalar
    Variance of the Dirichlet distribution.

r   r  )ri   r  alpha0r3   s       r4   vardirichlet_gen.var  sB     ,E2'V_!,LMs##r6   c                     [        U5      n[        R                  " U5      nX-  n[        R                  " U5      [        R                  " X35      -
  US-   -  n[        U5      $ )zCovariance matrix of the Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s

Returns
-------
cov : ndarray
    The covariance matrix of the distribution.
r   )r  r?   re   r   outerr5   )ri   r  r  r
  r   s        r4   r   dirichlet_gen.cov  sP     ,E2NwwqzBHHQN*vz:s##r6   c                 P   [        U5      n[        R                  " U5      n[        U5      nUR                  S   nX2U-
  [
        R                  R                  U5      -  -   [        R                  " US-
  [
        R                  R                  U5      -  5      -
  n[        U5      $ )z
Differential entropy of the Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s

Returns
-------
h : scalar
    Entropy of the Dirichlet distribution

r   r   )	r  r?   re   r  r   rY   r   r   r5   )ri   r  r  r  Kr3   s         r4   r#  dirichlet_gen.entropy  s     ,E25kKKNaZ5==#4#4V#<<<rvvQY%--++E22@4 4s##r6   c                 X    [        U5      nU R                  U5      nUR                  XS9$ )aS  
Draw random samples from a Dirichlet distribution.

Parameters
----------
%(_dirichlet_doc_default_callparams)s
size : int, 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.

r  )r  r   r   )ri   r  r   r   s       r4   r  dirichlet_gen.rvs  s2    $ ,E2--l;%%e%77r6   r.  rz   rI  )r   r   r   r   r   rp   r   r   r   r   r   r  r   r#  r  r   r   r   s   @r4   r  r    sB    iVP2<&$*$*$$$($($28 8r6   r  c                   L    \ rS rSrSS jrS rS rS rS rS r	S	 r
SS
 jrSrg)r  i  Nc                 D    [        U5      U l        [        U5      U l        g rz   )r  r  r  r   r  s      r4   rp   dirichlet_frozen.__init__  s    07
"4(
r6   c                 L    U R                   R                  XR                  5      $ rz   )r   r   r  r=  s     r4   r   dirichlet_frozen.logpdf  s    zz  JJ//r6   c                 L    U R                   R                  XR                  5      $ rz   )r   r   r  r=  s     r4   r   dirichlet_frozen.pdf   s    zz~~a,,r6   c                 L    U R                   R                  U R                  5      $ rz   )r   r   r  r}   s    r4   r   dirichlet_frozen.mean#  s    zztzz**r6   c                 L    U R                   R                  U R                  5      $ rz   )r   r  r  r}   s    r4   r  dirichlet_frozen.var&      zz~~djj))r6   c                 L    U R                   R                  U R                  5      $ rz   )r   r   r  r}   s    r4   r   dirichlet_frozen.cov)  r  r6   c                 L    U R                   R                  U R                  5      $ rz   )r   r#  r  r}   s    r4   r#  dirichlet_frozen.entropy,  s    zz!!$**--r6   c                 N    U R                   R                  U R                  X5      $ rz   )r   r  r  rE  s      r4   r  dirichlet_frozen.rvs/  s    zz~~djj$==r6   )r   r  rz   rI  )r   r   r   r   rp   r   r   r   r  r   r#  r  r   r/   r6   r4   r  r    s*    )0-+**.>r6   r  )r   r   r  r   r  r   r#  zdf : int
    Degrees of freedom, must be greater than or equal to dimension of the
    scale matrix
scale : array_like
    Symmetric positive definite scale matrix of the distribution
)_doc_default_callparams_doc_callparams_noter   c                      ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rS rSS jrS rS rS rSrU =r$ )wishart_geniY  a!  A Wishart random variable.

The `df` keyword specifies the degrees of freedom. The `scale` keyword
specifies the scale matrix, which must be symmetric and positive definite.
In this context, the scale matrix is often interpreted in terms of a
multivariate normal precision matrix (the inverse of the covariance
matrix). These arguments must satisfy the relationship
``df > scale.ndim - 1``, but see notes on using the `rvs` method with
``df < scale.ndim``.

Methods
-------
pdf(x, df, scale)
    Probability density function.
logpdf(x, df, scale)
    Log of the probability density function.
rvs(df, scale, size=1, random_state=None)
    Draw random samples from a Wishart distribution.
entropy()
    Compute the differential entropy of the Wishart distribution.

Parameters
----------
%(_doc_default_callparams)s
%(_doc_random_state)s

Raises
------
scipy.linalg.LinAlgError
    If the scale matrix `scale` is not positive definite.

See Also
--------
invwishart, chi2

Notes
-----
%(_doc_callparams_note)s

The scale matrix `scale` must be a symmetric positive definite
matrix. Singular matrices, including the symmetric positive semi-definite
case, are not supported. Symmetry is not checked; only the lower triangular
portion is used.

The Wishart distribution is often denoted

.. math::

    W_p(\nu, \Sigma)

where :math:`\nu` is the degrees of freedom and :math:`\Sigma` is the
:math:`p \times p` scale matrix.

The probability density function for `wishart` has support over positive
definite matrices :math:`S`; if :math:`S \sim W_p(\nu, \Sigma)`, then
its PDF is given by:

.. math::

    f(S) = \frac{|S|^{\frac{\nu - p - 1}{2}}}{2^{ \frac{\nu p}{2} }
           |\Sigma|^\frac{\nu}{2} \Gamma_p \left ( \frac{\nu}{2} \right )}
           \exp\left( -tr(\Sigma^{-1} S) / 2 \right)

If :math:`S \sim W_p(\nu, \Sigma)` (Wishart) then
:math:`S^{-1} \sim W_p^{-1}(\nu, \Sigma^{-1})` (inverse Wishart).

If the scale matrix is 1-dimensional and equal to one, then the Wishart
distribution :math:`W_1(\nu, 1)` collapses to the :math:`\chi^2(\nu)`
distribution.

The algorithm [2]_ implemented by the `rvs` method may
produce numerically singular matrices with :math:`p - 1 < \nu < p`; the
user may wish to check for this condition and generate replacement samples
as necessary.


.. versionadded:: 0.16.0

References
----------
.. [1] M.L. Eaton, "Multivariate Statistics: A Vector Space Approach",
       Wiley, 1983.
.. [2] W.B. Smith and R.R. Hocking, "Algorithm AS 53: Wishart Variate
       Generator", Applied Statistics, vol. 21, pp. 341-345, 1972.

Examples
--------
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import wishart, chi2
>>> x = np.linspace(1e-5, 8, 100)
>>> w = wishart.pdf(x, df=3, scale=1); w[:5]
array([ 0.00126156,  0.10892176,  0.14793434,  0.17400548,  0.1929669 ])
>>> c = chi2.pdf(x, 3); c[:5]
array([ 0.00126156,  0.10892176,  0.14793434,  0.17400548,  0.1929669 ])
>>> plt.plot(x, w)
>>> plt.show()

The input quantiles can be any shape of array, as long as the last
axis labels the components.

Alternatively, the object may be called (as a function) to fix the degrees
of freedom and scale parameters, returning a "frozen" Wishart random
variable:

>>> rv = wishart(df=1, scale=1)
>>> # Frozen object with the same methods but holding the given
>>> # degrees of freedom and scale fixed.

c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   r   rp   r   r   r   wishart_docdict_paramsr   s     r4   rp   wishart_gen.__init__  rQ  r6   c                     [        XU5      $ )zRCreate a frozen Wishart distribution.

See `wishart_frozen` for more information.
)wishart_frozenri   dfscaler   s       r4   r   wishart_gen.__call__  s    
 b..r6   c                    Uc  Sn[         R                  " U[        S9nUR                  S:X  a$  U[         R                  [         R                  4   nOUR                  S:X  a  [         R
                  " U5      nOzUR                  S:X  aB  UR                  S   UR                  S   :X  d"  [        S[        UR                  5       S35      eUR                  S:  a  [        SUR                  -  5      eUR                  S   nUc  UnO9[         R                  " U5      (       d  [        S	5      eXS-
  ::  a  [        S
5      eX1U4$ )Nr   rK   r   r   r-   zIArray 'scale' must be square if it is two dimensional, but scale.scale = r   zBArray 'scale' must be at most two-dimensional, but scale.ndim = %dz$Degrees of freedom must be a scalar.zNDegrees of freedom must be greater than the dimension of scale matrix minus 1.)
r?   rW   rM   r1   r   r   r   r]   r   r   )ri   r  r  r   s       r4   r   wishart_gen._process_parameters  s+   =E

5.::?"**bjj01EZZ1_GGENEZZ1_U[[^u{{1~%E 336u{{3C2DAG H HZZ!^ 46;jjA B B kk!n:BRCDD7] B C C ~r6   c                    [         R                  " U[        S9nUR                  S:X  a1  U[         R                  " U5      SS2SS2[         R
                  4   -  nUR                  S:X  a]  US:X  a(  U[         R
                  [         R
                  SS24   nGO[         R                  " U5      SS2SS2[         R
                  4   nOUR                  S:X  a]  UR                  S   UR                  S   :X  d"  [        S[        UR                  5       S35      eUSS2SS2[         R
                  4   nO{UR                  S:X  aC  UR                  S   UR                  S   :X  d"  [        S	[        UR                  5       S35      eO(UR                  S:  a  [        S
UR                  -  5      eUR                  SS X"4:X  d   [        SX"4 SUR                  SS  S35      eU$ )r   rK   r   Nr   r-   zDQuantiles must be square if they are two dimensional, but x.shape = r      zbQuantiles must be square in the first two dimensions if they are three dimensional, but x.shape = znQuantiles must be at most two-dimensional with an additional dimension for multiplecomponents, but x.ndim = %dz2Quantiles have incompatible dimensions: should be z, got )
r?   rW   rM   r1   r   r   r   r   r]   r   r   s      r4   r   wishart_gen._process_quantiles  s   
 JJq&66Q;BFF3K1bjj 011A66Q;axbjj"**a/0GGAJq!RZZ/0VVq[771:+ &&)!''l^167 7 !Q

"#AVVq[771:+ DDGL>QRTU U , VVaZ ;=>VVD E E
 wwq|z) $%(J<vaggal^1F G G r6   c                    [         R                  " U5      nUR                  S:X  a  U[         R                     nO0UR                  S:  a   [	        S[        [        U5      5       35      eUR                  5       n[        U5      nX#4$ )Nr   r   z]Size must be an integer or tuple of integers; thus must have dimension <= 1. Got size.ndim = )r?   rW   r1   r   r]   r   r  prod)ri   r   r   r   s       r4   _process_sizewishart_gen._process_size  sw    zz$99>

#DYY] %%(t%5$68 9 9 IIKdxr6   c                 l   [         R                  " UR                  S   5      n[         R                  " UR                  5      n[         R                  " UR                  S   5      n	[        UR                  S   5       Hu  n
U R	                  USS2SS2U
4   5      u  oU
'   [
        R                  R                  US4USS2SS2U
4   5      USS2SS2U
4'   USS2SS2U
4   R                  5       X'   Mw     SX2-
  S-
  -  U-  SU	-  -
  SU-  U-  [        -  SU-  U-  -   [        SU-  U5      -   -
  nU$ )a  Log of the Wishart probability density function.

Parameters
----------
x : ndarray
    Points at which to evaluate the log of the probability
    density function
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
scale : ndarray
    Scale matrix
log_det_scale : float
    Logarithm of the determinant of the scale matrix
C : ndarray
    Cholesky factorization of the scale matrix, lower triangular.

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

r8   NTr"  r   )r?   emptyr   range_cholesky_logdetrY   rZ   	cho_solvetrace_LOG_2r   )ri   rO   r   r  r  log_det_scaleC	log_det_xscale_inv_xtr_scale_inv_xir  r3   s                r4   r   wishart_gen._logpdf#  s"   > HHQWWR[)	hhqww'!''"+.qwwr{#A"33AaAgJ?OA|#(<<#9#91d)Qq!QwZ#PK1a  +Aq!G 4 : : <N $ rx!|$y033GGb3'#(]*BBSVS)*+ 
r6   c                     U R                  X#5      u  pBnU R                  X5      nU R                  U5      u  pVU R                  XX#Xe5      n[	        U5      $ )ax  Log of the Wishart probability density function.

Parameters
----------
x : array_like
    Quantiles, with the last axis of `x` denoting the components.
    Each quantile must be a symmetric positive definite matrix.
%(_doc_default_callparams)s

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

Notes
-----
%(_doc_callparams_note)s

r   r   r  r   r5   ri   rO   r  r  r   r  r  r3   s           r4   r   wishart_gen.logpdfQ  sZ    ( 11"<##A+  007ll12m?s##r6   c                 N    [         R                  " U R                  XU5      5      $ )ab  Wishart probability density function.

Parameters
----------
x : array_like
    Quantiles, with the last axis of `x` denoting the components.
    Each quantile must be a symmetric positive definite matrix.
%(_doc_default_callparams)s

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

Notes
-----
%(_doc_callparams_note)s

r<  ri   rO   r  r  s       r4   r   wishart_gen.pdfn      ( vvdkk!/00r6   c                 
    X#-  $ )zMean of the Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r/   ri   r   r  r  s       r4   _meanwishart_gen._mean  s     zr6   c                 d    U R                  X5      u  p1nU R                  X1U5      n[        U5      $ )zMean of the Wishart distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mean : float
    The mean of the distribution
r   r  r5   ri   r  r  r   r3   s        r4   r   wishart_gen.mean  s3     11"<jj%(s##r6   c                 2    X!S-   :  a  X!-
  S-
  U-  nU$ SnU$ )zMode of the Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r   Nr/   ri   r   r  r  r3   s        r4   _modewishart_gen._mode  s0     q=6!8u$C 
 C
r6   c                 n    U R                  X5      u  p1nU R                  X1U5      nUb  [        U5      $ U$ )zMode of the Wishart distribution

Only valid if the degrees of freedom are greater than the dimension of
the scale matrix.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mode : float or None
    The Mode of the distribution
r   r  r5   r  s        r4   modewishart_gen.mode  s<     11"<jj%('*s#?C?r6   c                 j    US-  nUR                  5       nU[        R                  " XU5      -  nXB-  nU$ )zVariance of the Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r-   diagonalr?   r  ri   r   r  r  r  r   s         r4   _varwishart_gen._var  s8     Qh~~rxx##	
r6   c                 d    U R                  X5      u  p1nU R                  X1U5      n[        U5      $ )zVariance of the Wishart distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
var : float
    The variance of the distribution
r   r   r5   r  s        r4   r  wishart_gen.var  s3     11"<ii's##r6   c           	      $   X3S-
  -  S-  nUR                  X-  S9R                  X&4-   5      n[        R                  [	        U5       Vs/ s H  nUR                  XHS-   -
  S-   US9S-  PM      sn   R                  U4USSS2   -   5      R                  n	[        R                  " X#U4-   5      n
[        [        SSS5      /[        U5      -  5      n[        R                  " USS9nXzX-   '   [        R                  " U5      nXX-   '   U
$ s  snf )a  
Parameters
----------
n : integer
    Number of variates to generate
shape : iterable
    Shape of the variates to generate
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional

    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

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

r   r-   r  r"  Nr8   k)r  r   r?   r_r  	chisquarer|   r   r  slicer^   tril_indicesdiag_indices)ri   r   r   r   r  r   n_trilcovariancesr  	variancesAsize_idxtril_idxdiag_idxs                 r4   _standard_rvswishart_gen._standard_rvs  s-   : A!#")) * "75?3 	 UU%*3Z1%/ )222s8A:A2FK%/1 229'3&:?"+;F 3GGHq 	
 HHU3Z'( %dD123u:=>??3"-!,(
 ??3'!*(
!1s   
%Dc                     U R                  U5      nU R                  XX4U5      n[        R                  " U5       H>  n[        R                  " XWU   5      n	[        R                  " XR
                  5      Xx'   M@     U$ )a  Draw random samples from a Wishart distribution.

Parameters
----------
n : integer
    Number of variates to generate
shape : iterable
    Shape of the variates to generate
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
C : ndarray
    Cholesky factorization of the scale matrix, lower triangular.
%(_doc_random_state)s

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

)r   r4  r?   ndindexr{   r|   )
ri   r   r   r   r  r  r   r0  indexCAs
             r4   _rvswishart_gen._rvs&	  sl    . --l; q,? ZZ&EU8$Bvvb$$'AH ' r6   c                     U R                  U5      u  pVU R                  X5      u  pqn[        R                  R	                  USS9nU R                  XVXqX5      n	[        U	5      $ )a  Draw random samples from a Wishart distribution.

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

Returns
-------
rvs : ndarray
    Random variates of shape (`size`) + (``dim``, ``dim``), where
    ``dim`` is the dimension of the scale matrix.

Notes
-----
%(_doc_callparams_note)s

Trw  r  r   rY   rZ   rz  r:  r5   
ri   r  r  r   r   r   r   r   r  r3   s
             r4   r  wishart_gen.rvsS	  b    * %%d+11"< LL!!%t!4ii#1;s##r6   c                    SUS-   -  U-  SU-  US-   -  [         -  -   [        SU-  U5      -   SX!-
  S-
  -  [        R                  " [	        U5       Vs/ s H  n[        SUS-   US-   -
  -  5      PM     sn5      -  -
  SU-  U-  -   $ s  snf )aR  Compute the differential entropy of the Wishart.

Parameters
----------
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
log_det_scale : float
    Logarithm of the determinant of the scale matrix

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

r"  r   )r  r   r?   re   r  r   )ri   r   r  r  r  s        r4   r  wishart_gen._entropyr	  s    & 3q5MM)#IQ&()R%& 28a< 26649#J?JqS"q&AaC.)*J?$  "HsN	

 @s   !B	c                 t    U R                  X5      u  p1nU R                  U5      u  pEU R                  X1U5      $ )zCompute the differential entropy of the Wishart.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
h : scalar
    Entropy of the Wishart distribution

Notes
-----
%(_doc_callparams_note)s

r   r  r  ri   r  r  r   r  r  s         r4   r#  wishart_gen.entropy	  s<    " 11"<007}}Sm44r6   c                     [         R                  R                  USS9nS[        R                  " [        R
                  " UR                  5       5      5      -  nX#4$ )ax  Compute Cholesky decomposition and determine (log(det(scale)).

Parameters
----------
scale : ndarray
    Scale matrix.

Returns
-------
c_decomp : ndarray
    The Cholesky decomposition of `scale`.
logdet : scalar
    The log of the determinant of `scale`.

Notes
-----
This computation of ``logdet`` is equivalent to
``np.linalg.slogdet(scale)``.  It is ~2x faster though.

Trw  r-   )rY   rZ   rz  r?   re   rf   r  )ri   r  c_decomplogdets       r4   r  wishart_gen._cholesky_logdet	  sK    * <<((d(;RVVBFF8#4#4#6788r6   r.  rz   NNNrI  )r   r   r   r   r   rp   r   r   r   r  r   r   r   r  r   r  r  r   r  r4  r:  r  r  r#  r  r   r   r   s   @r4   r  r  Y  sy    m^N/8#J,\$:1,"$ *@&*$ 2h+Z$>
85*   r6   r  c                   P    \ rS rSrSrSS jrS rS rS rS r	S	 r
SS
 jrS rSrg)r  i	  a   Create a frozen Wishart distribution.

Parameters
----------
df : array_like
    Degrees of freedom of the distribution
scale : array_like
    Scale matrix of the distribution
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance then
    that instance is used.

Nc                     [        U5      U l        U R                  R                  X5      u  U l        U l        U l        U R                  R                  U R
                  5      u  U l        U l        g rz   )	r  r   r   r   r  r  r  r  r  r  s       r4   rp   wishart_frozen.__init__	  sT     &
(,

(F(F)%$'4:%)ZZ%@%@%L""r6   c                    U R                   R                  XR                  5      nU R                   R                  XR                  U R                  U R
                  U R                  U R                  5      n[        U5      $ rz   )	r   r   r   r   r  r  r  r  r5   ri   rO   r3   s      r4   r   wishart_frozen.logpdf	  sZ    JJ))!XX6jj  HHdggtzz!%!3!3TVV=s##r6   c                 L    [         R                  " U R                  U5      5      $ rz   r<  r=  s     r4   r   wishart_frozen.pdf	  r?  r6   c                     U R                   R                  U R                  U R                  U R                  5      n[        U5      $ rz   r   r  r   r  r  r5   ri   r3   s     r4   r   wishart_frozen.mean	  1    jjtxx$**=s##r6   c                     U R                   R                  U R                  U R                  U R                  5      nUb  [        U5      $ U$ rz   r   r  r   r  r  r5   rV  s     r4   r  wishart_frozen.mode	  :    jjtxx$**='*s#?C?r6   c                     U R                   R                  U R                  U R                  U R                  5      n[        U5      $ rz   r   r   r   r  r  r5   rV  s     r4   r  wishart_frozen.var	  s/    jjoodhh<s##r6   c                     U R                   R                  U5      u  p4U R                   R                  X4U R                  U R                  U R
                  U5      n[        U5      $ rz   r   r  r:  r   r  r  r5   ri   r   r   r   r   r3   s         r4   r  wishart_frozen.rvs	  sL    ::++D1jjooa$''"ffl4s##r6   c                 x    U R                   R                  U R                  U R                  U R                  5      $ rz   r   r  r   r  r  r}   s    r4   r#  wishart_frozen.entropy	  )    zz""488TWWd6H6HIIr6   r  r   r  r   r  r  rz   rI  )r   r   r   r   r   rp   r   r   r   r  r  r  r#  r   r/   r6   r4   r  r  	  s2    "M$&$@$$Jr6   r  )r   r   r   r  r  r  r#  c                      ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
 rS rS rS rS rS rSS jrS rS rSrU =r$ )invwishart_geni
  a  An inverse Wishart random variable.

The `df` keyword specifies the degrees of freedom. The `scale` keyword
specifies the scale matrix, which must be symmetric and positive definite.
In this context, the scale matrix is often interpreted in terms of a
multivariate normal covariance matrix.

Methods
-------
pdf(x, df, scale)
    Probability density function.
logpdf(x, df, scale)
    Log of the probability density function.
rvs(df, scale, size=1, random_state=None)
    Draw random samples from an inverse Wishart distribution.
entropy(df, scale)
    Differential entropy of the distribution.

Parameters
----------
%(_doc_default_callparams)s
%(_doc_random_state)s

Raises
------
scipy.linalg.LinAlgError
    If the scale matrix `scale` is not positive definite.

See Also
--------
wishart

Notes
-----
%(_doc_callparams_note)s

The scale matrix `scale` must be a symmetric positive definite
matrix. Singular matrices, including the symmetric positive semi-definite
case, are not supported. Symmetry is not checked; only the lower triangular
portion is used.

The inverse Wishart distribution is often denoted

.. math::

    W_p^{-1}(\nu, \Psi)

where :math:`\nu` is the degrees of freedom and :math:`\Psi` is the
:math:`p \times p` scale matrix.

The probability density function for `invwishart` has support over positive
definite matrices :math:`S`; if :math:`S \sim W^{-1}_p(\nu, \Sigma)`,
then its PDF is given by:

.. math::

    f(S) = \frac{|\Sigma|^\frac{\nu}{2}}{2^{ \frac{\nu p}{2} }
           |S|^{\frac{\nu + p + 1}{2}} \Gamma_p \left(\frac{\nu}{2} \right)}
           \exp\left( -tr(\Sigma S^{-1}) / 2 \right)

If :math:`S \sim W_p^{-1}(\nu, \Psi)` (inverse Wishart) then
:math:`S^{-1} \sim W_p(\nu, \Psi^{-1})` (Wishart).

If the scale matrix is 1-dimensional and equal to one, then the inverse
Wishart distribution :math:`W_1(\nu, 1)` collapses to the
inverse Gamma distribution with parameters shape = :math:`\frac{\nu}{2}`
and scale = :math:`\frac{1}{2}`.

Instead of inverting a randomly generated Wishart matrix as described in [2],
here the algorithm in [4] is used to directly generate a random inverse-Wishart
matrix without inversion.

.. versionadded:: 0.16.0

References
----------
.. [1] M.L. Eaton, "Multivariate Statistics: A Vector Space Approach",
       Wiley, 1983.
.. [2] M.C. Jones, "Generating Inverse Wishart Matrices", Communications
       in Statistics - Simulation and Computation, vol. 14.2, pp.511-514,
       1985.
.. [3] Gupta, M. and Srivastava, S. "Parametric Bayesian Estimation of
       Differential Entropy and Relative Entropy". Entropy 12, 818 - 843.
       2010.
.. [4] S.D. Axen, "Efficiently generating inverse-Wishart matrices and
       their Cholesky factors", :arXiv:`2310.15884v1`. 2023.

Examples
--------
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import invwishart, invgamma
>>> x = np.linspace(0.01, 1, 100)
>>> iw = invwishart.pdf(x, df=6, scale=1)
>>> iw[:3]
array([  1.20546865e-15,   5.42497807e-06,   4.45813929e-03])
>>> ig = invgamma.pdf(x, 6/2., scale=1./2)
>>> ig[:3]
array([  1.20546865e-15,   5.42497807e-06,   4.45813929e-03])
>>> plt.plot(x, iw)
>>> plt.show()

The input quantiles can be any shape of array, as long as the last
axis labels the components.

Alternatively, the object may be called (as a function) to fix the degrees
of freedom and scale parameters, returning a "frozen" inverse Wishart
random variable:

>>> rv = invwishart(df=1, scale=1)
>>> # Frozen object with the same methods but holding the given
>>> # degrees of freedom and scale fixed.

c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   r  r   s     r4   rp   invwishart_gen.__init__v
  rQ  r6   c                     [        XU5      $ )z^Create a frozen inverse Wishart distribution.

See `invwishart_frozen` for more information.

)invwishart_frozenr  s       r4   r   invwishart_gen.__call__z
  s     !D11r6   c           	      d   [         R                  " UR                  S   5      n[         R                  " UR                  S   5      n[        SU45      nUS:  am  [	        UR                  S   5       HP  n	U R                  USS2SS2U	4   5      u  oU	'   U" SXSSS9n[         R                  R                  U5      S	-  Xy'   MR     O-[         R                  " US
   5      USS& US
   S	-  US
   -  USS& SU-  U-  SU-  -
  SU-  U-  [        -  SX2-   S-   -  U-  -   -
  [        SU-  U5      -
  nU$ )a  Log of the inverse Wishart probability density function.

Parameters
----------
x : ndarray
    Points at which to evaluate the log of the probability
    density function.
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
log_det_scale : float
    Logarithm of the determinant of the scale matrix
C : ndarray
    Cholesky factorization of the scale matrix, lower triangular.

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

r8   trsmr   Nr   r   Tsider>   r-   r   r   r"  )r?   r  r   r   r  r  rZ   r   rf   r  r   )ri   rO   r   r  r  r  r  tr_scale_x_invrq  r  Cxr0  r3   s                r4   r   invwishart_gen._logpdf
  s8   0 HHQWWR[)	!''"+.v-71772;'#'#8#81a7#D aLR$7$&IINN1$5q$8! (
 66!D'?IaL !$
QtW 4N1 b=(3+??b3'#A*>*JJLCFC() 
r6   c                     U R                  X#5      u  pBnU R                  X5      nU R                  U5      u  pVU R                  XX&U5      n[	        U5      $ )a  Log of the inverse Wishart probability density function.

Parameters
----------
x : array_like
    Quantiles, with the last axis of `x` denoting the components.
    Each quantile must be a symmetric positive definite matrix.
%(_doc_default_callparams)s

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

Notes
-----
%(_doc_callparams_note)s

r  r  s           r4   r   invwishart_gen.logpdf
  sX    ( 11"<##A+007ll12a8s##r6   c                 N    [         R                  " U R                  XU5      5      $ )aj  Inverse Wishart probability density function.

Parameters
----------
x : array_like
    Quantiles, with the last axis of `x` denoting the components.
    Each quantile must be a symmetric positive definite matrix.
%(_doc_default_callparams)s

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

Notes
-----
%(_doc_callparams_note)s

r<  r	  s       r4   r   invwishart_gen.pdf
  r  r6   c                 2    X!S-   :  a  X2U-
  S-
  -  nU$ SnU$ )zMean of the inverse Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r   Nr/   r  s        r4   r  invwishart_gen._mean
  s0     a<8a<(C 
 C
r6   c                 n    U R                  X5      u  p1nU R                  X1U5      nUb  [        U5      $ U$ )a  Mean of the inverse Wishart distribution.

Only valid if the degrees of freedom are greater than the dimension of
the scale matrix plus one.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mean : float or None
    The mean of the distribution

r  r  s        r4   r   invwishart_gen.mean
  s<      11"<jj%('*s#?C?r6   c                     X2U-   S-   -  $ )zMode of the inverse Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r   r/   r  s       r4   r  invwishart_gen._mode  s     S1%%r6   c                 d    U R                  X5      u  p1nU R                  X1U5      n[        U5      $ )zMode of the inverse Wishart distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mode : float
    The Mode of the distribution

r  r  s        r4   r  invwishart_gen.mode  s3     11"<jj%(s##r6   c                     X!S-   :  aZ  X!-
  S-   US-  -  nUR                  5       nXBU-
  S-
  [        R                  " XU5      -  -  nXBU-
  X!-
  S-
  S-  -  X!-
  S-
  -  -  nU$ SnU$ )zVariance of the inverse Wishart distribution.

Parameters
----------
dim : int
    Dimension of the scale matrix
%(_doc_default_callparams)s

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

r  r   r-   Nr  r  s         r4   r   invwishart_gen._var(  s     a<8a<5!8+C>>#DHqLBHHT$888CHA 11RX\BBC 
 C
r6   c                 n    U R                  X5      u  p1nU R                  X1U5      nUb  [        U5      $ U$ )a  Variance of the inverse Wishart distribution.

Only valid if the degrees of freedom are greater than the dimension of
the scale matrix plus three.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
var : float
    The variance of the distribution
r#  r  s        r4   r  invwishart_gen.var@  s<     11"<ii''*s#?C?r6   c                 (   [         R                  " X#U4-   5      n[         R                  " USS9u  pxX3S-
  -  S-  n	UR                  / UQU	P7S9USXx4'   [         R                  " U5      n
XC-
  S-   U
-   nUR                  U/ UQUP7S9S-  USX4'   U$ )	a  
Parameters
----------
n : integer
    Number of variates to generate
shape : iterable
    Shape of the variates to generate
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional

    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

Returns
-------
A : ndarray
    Random variates of shape (`shape`) + (``dim``, ``dim``).
    Each slice `A[..., :, :]` is lower-triangular, and its
    inverse is the lower Cholesky factor of a draw from
    `invwishart(df, np.eye(dim))`.

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

r8   r&  r   r-   r  .)r  r   r"  )r?   r   r+  r  aranger)  )ri   r   r   r   r  r   r0  tri_rowstri_colsr-  r   chi_dfss               r4   _inv_standard_rvs invwishart_gen._inv_standard_rvsS  s    H HHU3Z'(  __SB7A!#%1%8%8!5!&! &9 &
#x
!"
 yy~8a<4')33]u]c] 4 
#t/ r6   c           
      @   U R                  U5      nU R                  XX4U5      n[        SU45      n[        SU45      n	[        R                  " UR
                  SS 5       H8  n
US:  a  U" SXz   USSS9nU	" SXSSSS	9Xz'   M#  US
   Xz   S
   -  S-  Xz   S
'   M:     U$ )a  Draw random samples from an inverse Wishart distribution.

Parameters
----------
n : integer
    Number of variates to generate
shape : iterable
    Shape of the variates to generate
dim : int
    Dimension of the scale matrix
df : int
    Degrees of freedom
C : ndarray
    Cholesky factorization of the scale matrix, lower triangular.
%(_doc_random_state)s

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

rq  trmmNrc  r   r   Trr  )rs  r>   trans_art  r-   )r   r  r   r?   r7  r   )ri   r   r   r   r  r  r   r0  rq  r  r8  r9  s               r4   r:  invwishart_gen._rvs  s    . --l;""1SlC v-v-ZZ-EQw "ah>B$M"#D'AHTN":Q!> . r6   c                     U R                  U5      u  pVU R                  X5      u  pqn[        R                  R	                  USS9nU R                  XVXqX5      n	[        U	5      $ )a  Draw random samples from an inverse Wishart distribution.

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

Returns
-------
rvs : ndarray
    Random variates of shape (`size`) + (``dim``, ``dim``), where
    ``dim`` is the dimension of the scale matrix.

Notes
-----
%(_doc_callparams_note)s

Trw  r=  r>  s
             r4   r  invwishart_gen.rvs  r@  r6   c                 "   [        SUS-   5       Vs/ s H  nSX!-
  U-   -  PM     nn[        R                  " U5      n[        SU-  U5      SU-  U-  -   SUS-   -  U[        -
  -  -   SX!-   S-   -  [        XUS9R                  5       -  -
  $ s  snf )Nr   r"  r2   )r  r?   rW   r   r  r   re   )ri   r   r  r  r  psi_eval_pointss         r4   r  invwishart_gen._entropy  s    9>q#'9JK9JA3"(Q,/9JK**_5C"Hc*S3Y^;37O}v56728a< 599;<< 	< Ls   Bc                 t    U R                  X5      u  p1nU R                  U5      u  pEU R                  X1U5      $ rz   rD  rE  s         r4   r#  invwishart_gen.entropy  s:    11"<007}}Sm44r6   r.  rz   rK  rI  )r   r   r   r   r   rp   r   r   r   r   r  r   r  r  r   r  r  r:  r  r  r#  r   r   r   s   @r4   rj  rj  
  se    qfN2)V$41,*@(&"$"0@&4l)V$><5 5r6   rj  c                   L    \ rS rSrSS jrS rS rS rS rS r	SS	 jr
S
 rSrg)rn  i  Nc                 n   [        U5      U l        U R                  R                  X5      u  U l        U l        U l        [        R                  R                  U R
                  SS9U l	        S[        R                  " [        R                  " U R                  R                  5       5      5      -  U l        g)a  Create a frozen inverse Wishart distribution.

Parameters
----------
df : array_like
    Degrees of freedom of the distribution
scale : array_like
    Scale matrix of the distribution
seed : {None, int, `numpy.random.Generator`}, optional
    If `seed` is None the `numpy.random.Generator` singleton is used.
    If `seed` is an int, a new ``Generator`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` instance then that instance is
    used.

Trw  r-   N)rj  r   r   r   r  r  rY   rZ   rz  r  r?   re   rf   r  r  r  s       r4   rp   invwishart_frozen.__init__  s    " $D)
(,

(F(F)
%$'4:
 &&tzz&>tvv/@(A!BBr6   c                     U R                   R                  XR                  5      nU R                   R                  XR                  U R                  U R
                  U R                  5      n[        U5      $ rz   )r   r   r   r   r  r  r  r5   rP  s      r4   r   invwishart_frozen.logpdf   sT    JJ))!XX6jj  HHdgg!%!3!3TVV=s##r6   c                 L    [         R                  " U R                  U5      5      $ rz   r<  r=  s     r4   r   invwishart_frozen.pdf  r?  r6   c                     U R                   R                  U R                  U R                  U R                  5      nUb  [        U5      $ U$ rz   rU  rV  s     r4   r   invwishart_frozen.mean	  r\  r6   c                     U R                   R                  U R                  U R                  U R                  5      n[        U5      $ rz   rZ  rV  s     r4   r  invwishart_frozen.mode  rX  r6   c                     U R                   R                  U R                  U R                  U R                  5      nUb  [        U5      $ U$ rz   r^  rV  s     r4   r  invwishart_frozen.var  s8    jjoodhh<'*s#?C?r6   c                     U R                   R                  U5      u  p4U R                   R                  X4U R                  U R                  U R
                  U5      n[        U5      $ rz   ra  rb  s         r4   r  invwishart_frozen.rvs  sN    ::++D1jjooa$''"ffl4 s##r6   c                 x    U R                   R                  U R                  U R                  U R                  5      $ rz   re  r}   s    r4   r#  invwishart_frozen.entropy  rg  r6   rh  rz   rI  )r   r   r   r   rp   r   r   r   r  r  r  r#  r   r/   r6   r4   rn  rn    s.    C4$&@$@$Jr6   rn  )r   r   r   r  r  r  zsn : int
    Number of trials
p : array_like
    Probability of a trial falling into each category; should sum to 1
a  `n` should be a nonnegative integer. Each element of `p` should be in the
interval :math:`[0,1]` and the elements should sum to 1. If they do not sum to
1, the last element of the `p` array is not used and is replaced with the
remaining probability left over from the earlier elements.
c                   ~   ^  \ rS rSrSrSU 4S jjrSS jrSS jrS rS r	S r
S	 rS
 rS rS rS rSS jrSrU =r$ )multinomial_geniJ  a  A multinomial random variable.

Methods
-------
pmf(x, n, p)
    Probability mass function.
logpmf(x, n, p)
    Log of the probability mass function.
rvs(n, p, size=1, random_state=None)
    Draw random samples from a multinomial distribution.
entropy(n, p)
    Compute the entropy of the multinomial distribution.
cov(n, p)
    Compute the covariance matrix of the multinomial distribution.

Parameters
----------
%(_doc_default_callparams)s
%(_doc_random_state)s

Notes
-----
%(_doc_callparams_note)s

The probability mass function for `multinomial` is

.. math::

    f(x) = \frac{n!}{x_1! \cdots x_k!} p_1^{x_1} \cdots p_k^{x_k},

supported on :math:`x=(x_1, \ldots, x_k)` where each :math:`x_i` is a
nonnegative integer and their sum is :math:`n`.

.. versionadded:: 0.19.0

Examples
--------

>>> from scipy.stats import multinomial
>>> rv = multinomial(8, [0.3, 0.2, 0.5])
>>> rv.pmf([1, 3, 4])
0.042000000000000072

The multinomial distribution for :math:`k=2` is identical to the
corresponding binomial distribution (tiny numerical differences
notwithstanding):

>>> from scipy.stats import binom
>>> multinomial.pmf([3, 4], n=7, p=[0.4, 0.6])
0.29030399999999973
>>> binom.pmf(3, 7, 0.4)
0.29030400000000012

The functions ``pmf``, ``logpmf``, ``entropy``, and ``cov`` support
broadcasting, under the convention that the vector parameters (``x`` and
``p``) are interpreted as if each row along the last axis is a single
object. For instance:

>>> multinomial.pmf([[3, 4], [3, 5]], n=[7, 8], p=[.3, .7])
array([0.2268945,  0.25412184])

Here, ``x.shape == (2, 2)``, ``n.shape == (2,)``, and ``p.shape == (2,)``,
but following the rules mentioned above they behave as if the rows
``[3, 4]`` and ``[3, 5]`` in ``x`` and ``[.3, .7]`` in ``p`` were a single
object, and as if we had ``x.shape = (2,)``, ``n.shape = (2,)``, and
``p.shape = ()``. To obtain the individual elements without broadcasting,
we would do this:

>>> multinomial.pmf([3, 4], n=7, p=[.3, .7])
0.2268945
>>> multinomial.pmf([3, 5], 8, p=[.3, .7])
0.25412184

This broadcasting also works for ``cov``, where the output objects are
square matrices of size ``p.shape[-1]``. For example:

>>> multinomial.cov([4, 5], [[.3, .7], [.4, .6]])
array([[[ 0.84, -0.84],
        [-0.84,  0.84]],
       [[ 1.2 , -1.2 ],
        [-1.2 ,  1.2 ]]])

In this example, ``n.shape == (2,)`` and ``p.shape == (2, 2)``, and
following the rules above, these broadcast as if ``p.shape == (2,)``.
Thus the result should also be of shape ``(2,)``, but since each output is
a :math:`2 \times 2` matrix, the result in fact has shape ``(2, 2, 2)``,
where ``result[0]`` is equal to ``multinomial.cov(n=4, p=[.3, .7])`` and
``result[1]`` is equal to ``multinomial.cov(n=5, p=[.4, .6])``.

Alternatively, the object may be called (as a function) to fix the `n` and
`p` parameters, returning a "frozen" multinomial random variable:

>>> rv = multinomial(n=7, p=[.3, .7])
>>> # Frozen object with the same methods but holding the given
>>> # degrees of freedom and scale fixed.

See also
--------
scipy.stats.binom : The binomial distribution.
numpy.random.Generator.multinomial : Sampling from the multinomial distribution.
scipy.stats.multivariate_hypergeom :
    The multivariate hypergeometric distribution.
c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   r   r   multinomial_docdict_paramsr   s     r4   rp   multinomial_gen.__init__  s,    T\\+EF 	r6   c                     [        XU5      $ )zZCreate a frozen multinomial distribution.

See `multinomial_frozen` for more information.
)multinomial_frozen)ri   r   r  r   s       r4   r   multinomial_gen.__call__  s    
 "!--r6   c                 n   [         R                  " U[         R                  SS9nSUSSS24   R                  SS9-
  n[         R                  " U5      U:  nXE   X%S4'   [         R
                  " US:  SS9nU[         R
                  " US	:  SS9-  n[         R                  " U[        SS9nUS:  nXXv-  4$ )
zReturns: n_, p_, npcond.

n_ and p_ are arrays of the correct shape; npcond is a boolean array
flagging values out of the domain.
Tr<   r  r   .Nr8   rs   r   r   )r?   rL   float64re   rC   r   ry  )ri   r   r  rA   
p_adjusted
i_adjustedpcondnconds           r4   r   #multinomial_gen._process_parameters  s     HHQbjjt4!C"H+//r/22
VVJ'#-
&2b. q1u2&AB''HHQc- AU]""r6   c                    [         R                  " U[        S9nUR                  S:X  a  [	        S5      eUR
                  S:w  aJ  UR                  S   UR                  S   :X  d*  [	        SUR                  S   UR                  S   4-  5      e[         R                  " XA:g  SS9nU[         R                  " US:  SS9-  nU[         R                  " USS9U:g  -  nXE4$ )zeReturns: x_, xcond.

x_ is an int array; xcond is a boolean array flagging values out of the
domain.
rK   r   zx must be an array.r8   zHSize of each quantile should be size of p: received %d, but expected %d.rs   )	r?   rW   ry  r1   r]   r   r   r   re   )ri   rO   r   r  xxrE   s         r4   r   "multinomial_gen._process_quantiles  s     ZZ%77a<23377a< ; = hhrlAGGBK89 : :
 vvbgB'rAvB''rvvbr*a/0xr6   c                     [         R                  " U5      nUR                  S:w  a  X1U'   U$ U(       a  UR                  S:X  a  U$ X1S'   U$ )Nr   .r?   rW   r1   ri   resultrE   	bad_values       r4   _checkresultmultinomial_gen._checkresult  sL    F#99>$4L
 	 {{a  #3Kr6   c                 z    [        US-   5      [        R                  " [        X5      [        US-   5      -
  SS9-   $ )Nr   r8   rs   )r   r?   re   r   ri   rO   r   r  s       r4   _logpmfmultinomial_gen._logpmf  s1    qs|bffU1[71Q3<%?bIIIr6   c                    U R                  X#5      u  p#nU R                  XU5      u  pU R                  XU5      nU[        R                  " UR
                  [        R                  S9-  nU R                  Xg[        R                  * 5      nU[        R                  " UR
                  [        R                  S9-  nU R                  Xh[        R                  5      $ )aB  Log of the Multinomial probability mass function.

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

Returns
-------
logpmf : ndarray or scalar
    Log of the probability mass function evaluated at `x`

Notes
-----
%(_doc_callparams_note)s
rK   )
r   r   r  r?   r   r   bool_r  r   nan)	ri   rO   r   r  npcondxcondr  xcond_npcond_s	            r4   logpmfmultinomial_gen.logpmf  s    $ //5f**13aA& &,,bhh??""6BFF7; 288EKKrxx@@  "&&99r6   c                 N    [         R                  " U R                  XU5      5      $ )a,  Multinomial probability mass function.

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

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

Notes
-----
%(_doc_callparams_note)s
r?   r   r  r  s       r4   pmfmultinomial_gen.pmf  s    $ vvdkk!*++r6   c                     U R                  X5      u  pnUS[        R                  4   U-  nU R                  XC[        R                  5      $ )zMean of the Multinomial distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mean : float
    The mean of the distribution
.)r   r?   r   r  r  )ri   r   r  r  r  s        r4   r   multinomial_gen.mean.  sF     //5f3

?#A%  88r6   c                 T   U R                  X5      u  pnUS[        R                  [        R                  4   nU[        R                  " SU* U5      -  n[	        UR
                  S   5       H  nUSXf4==   XSU4   -  -  ss'   M     U R                  XS[        R                  5      $ )zCovariance matrix of the multinomial distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
cov : ndarray
    The covariance matrix of the distribution
.z...j,...k->...jkr8   )r   r?   r   r}  r  r   r  r  )ri   r   r  r  nnr  r  s          r4   r   multinomial_gen.cov>  s     //5fsBJJ

*+bii 2QB:: qwwr{#A39S!V9, $   88r6   c                 ^   U R                  X5      u  pn[        R                  S[        R                  " U5      S-    nU[        R                  " [        U5      SS9-  nU[        US-   5      -  nUS[        R                  4   n[        UR                  UR                  5      UR                  -
  S-   nU=R                  SU-  -  sl	        [        R                  " [        R                  " XAU5      [        US-   5      -  SSU-
  4S9nU R                  XW-   U[        R                  5      $ )a  Compute the entropy of the multinomial distribution.

The entropy is computed using this expression:

.. math::

    f(x) = - \log n! - n\sum_{i=1}^k p_i \log p_i +
    \sum_{i=1}^k \sum_{x=0}^n \binom n x p_i^x(1-p_i)^{n-x} \log x!

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
h : scalar
    Entropy of the Multinomial distribution

Notes
-----
%(_doc_callparams_note)s
r   r8   rs   .)r   )r   r?   r(  rB   re   r   r   r   r1   r   r   r  r  r  )ri   r   r  r  rO   term1new_axes_neededterm2s           r4   r#  multinomial_gen.entropyU  s    . //5fEE!BFF1IaK "&&ar**1c2::oaffaff-6:	4''uyyq)'!A#,6O!346   ??r6   c                 p    U R                  X5      u  pnU R                  U5      nUR                  XU5      $ )aY  Draw random samples from a Multinomial distribution.

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

Returns
-------
rvs : ndarray or scalar
    Random variates of shape (`size`, `len(p)`)

Notes
-----
%(_doc_callparams_note)s
)r   r   r"   )ri   r   r  r   r   r  s         r4   r  multinomial_gen.rvs|  s;    & //5f--l;''d33r6   r.  rz   )gV瞯<r2  )r   r   r   r   r   rp   r   r   r   r  r  r  r  r   r   r#  r  r   r   r   s   @r4   r  r  J  sP    fPG
.#,.	J:@,(9 9.%@N4 4r6   r  c                   J    \ rS rSrSrSS jrS rS rS rS r	S	 r
SS
 jrSrg)r  i  a"  Create a frozen Multinomial distribution.

Parameters
----------
n : int
    number of trials
p: array_like
    probability of a trial falling into each category; should sum to 1
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance then
    that instance is used.
Nc                    ^  [        U5      T l        T R                  R                  X5      u  T l        T l        T l        U 4S jnUT R                  l        g )Nc                 J   > TR                   TR                  TR                  4$ rz   )r   r  r  )r   r  ri   s     r4   r   8multinomial_frozen.__init__.<locals>._process_parameters  s    664664;;..r6   )r  r   r   r   r  r  )ri   r   r  r   r   s   `    r4   rp   multinomial_frozen.__init__  sC    $T*
&*jj&D&DQ&J#	/ *=

&r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r   r  r=  s     r4   r  multinomial_frozen.logpmf  !    zz  FFDFF33r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r   r  r=  s     r4   r  multinomial_frozen.pmf      zz~~a00r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r   r  r}   s    r4   r   multinomial_frozen.mean      zztvvtvv..r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r   r  r}   s    r4   r   multinomial_frozen.cov      zz~~dffdff--r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r#  r   r  r}   s    r4   r#  multinomial_frozen.entropy  s!    zz!!$&&$&&11r6   c                 d    U R                   R                  U R                  U R                  X5      $ rz   )r   r  r   r  rE  s      r4   r  multinomial_frozen.rvs  s!    zz~~dffdffdAAr6   )r   r   r  r  rz   rI  )r   r   r   r   r   rp   r  r  r   r   r#  r  r   r/   r6   r4   r  r    s+     =41/.2Br6   r  )r  r  r   r   r  c                   J   ^  \ rS rSrSrSU 4S jjrS	S jrS rS
S jrSr	U =r
$ )special_ortho_group_geni  a  A Special Orthogonal matrix (SO(N)) random variable.

Return a random rotation matrix, drawn from the Haar distribution
(the only uniform distribution on SO(N)) with a determinant of +1.

The `dim` keyword specifies the dimension N.

Methods
-------
rvs(dim=None, size=1, random_state=None)
    Draw random samples from SO(N).

Parameters
----------
dim : scalar
    Dimension of matrices
seed : {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`.

Notes
-----
This class is wrapping the random_rot code from the MDP Toolkit,
https://github.com/mdp-toolkit/mdp-toolkit

Return a random rotation matrix, drawn from the Haar distribution
(the only uniform distribution on SO(N)).
The algorithm is described in the paper
Stewart, G.W., "The efficient generation of random orthogonal
matrices with an application to condition estimators", SIAM Journal
on Numerical Analysis, 17(3), pp. 403-409, 1980.
For more information see
https://en.wikipedia.org/wiki/Orthogonal_matrix#Randomization

See also the similar `ortho_group`. For a random rotation in three
dimensions, see `scipy.spatial.transform.Rotation.random`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import special_ortho_group
>>> x = special_ortho_group.rvs(3)

>>> np.dot(x, x.T)
array([[  1.00000000e+00,   1.13231364e-17,  -2.86852790e-16],
       [  1.13231364e-17,   1.00000000e+00,  -1.46845020e-16],
       [ -2.86852790e-16,  -1.46845020e-16,   1.00000000e+00]])

>>> import scipy.linalg
>>> scipy.linalg.det(x)
1.0

This generates one random matrix from SO(3). It is orthogonal and
has a determinant of 1.

Alternatively, the object may be called (as a function) to fix the `dim`
parameter, returning a "frozen" special_ortho_group random variable:

>>> rv = special_ortho_group(5)
>>> # Frozen object with the same methods but holding the
>>> # dimension parameter fixed.

See Also
--------
ortho_group, scipy.spatial.transform.Rotation.random

c                 n   > [         TU ]  U5        [        R                  " U R                  5      U l        g rz   r   rp   r   r   r   r   s     r4   rp    special_ortho_group_gen.__init__  &    ''5r6   c                     [        XS9$ )z\Create a frozen SO(N) distribution.

See `special_ortho_group_frozen` for more information.
rS  )special_ortho_group_frozenri   r   r   s      r4   r    special_ortho_group_gen.__call__  s    
 *#99r6   c                     Ub0  [         R                  " U5      (       a  US::  d  U[        U5      :w  a  [        S5      eU$ )5Dimension N must be specified; it cannot be inferred.r   zmDimension of rotation must be specified,
                                and must be a scalar greater than 1.r?   r   ry  r]   ri   r   s     r4   r   +special_ortho_group_gen._process_parameters%  sA    ;bkk#..#(cSXo H I I 
r6   c                    U R                  U5      n[        U5      nUS:  a  U4OSnU R                  U5      n[        R                  " X!U4-   5      n[        R
                  " U5      USSS2SS24'   [        R                  " X!4-   5      n[        US-
  5       GH%  nUR                  X!U-
  4-   S9nUSSSS24   nUSSS2S4   n	[        R                  " X5      R                  S5      n
US   R                  5       n[        R                  " US:g  [        R                  " U5      S5      USU4'   US==   USU4   [        R                  " U
5      -  -  ss'   U[        R                  " XS	-  -
  US   S	-  -   S
-  5      S   -  nUSSS2US24==   [        R                  " USSS2US24   U	5      U-  -  ss'   GM(     SUS-
  -  USSS24   R                  SS9-  US'   XESSS2S4   -  nU$ )a  Draw random samples from SO(N).

Parameters
----------
dim : integer
    Dimension of rotation space (N).
size : integer, optional
    Number of samples to draw (default 1).

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim)

r   r/   .Nr  )rc  r8   .r   r   r-          @.Nr8   rs   ).r8   )r   ry  r   r?   r  r   r  r  matmulr0   r  wheresignra   r  )ri   r   r   r   HDr   rO   xrowxcolnorm2x0s               r4   r  special_ortho_group_gen.rvs-  s     --l;4y(w&&s+ HHT#J&'vvc{#q!)HHTF]#s1uA ##Q#9AS$\?DS!T\?D
 IId)11(;E6!Bq"''"+q9Ac1fIfI362775>11I %a%-!F)Q,6"<=iHHA c1abjMRYYqa}d;dBBM3 6 CE]1S#2#X;#3#3#3#<<'
 	
sAt|_r6   r.  rz   r2  rI  r   r   r   r   r   rp   r   r   r  r   r   r   s   @r4   r  r    s%    GR6:A Ar6   r  c                   (    \ rS rSrSS jrSS jrSrg)r  it  Nc                 d    [        U5      U l        U R                  R                  U5      U l        g)aD  Create a frozen SO(N) distribution.

Parameters
----------
dim : scalar
    Dimension of matrices
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

Examples
--------
>>> from scipy.stats import special_ortho_group
>>> g = special_ortho_group(5)
>>> x = g.rvs()

N)r  r   r   r   r  s      r4   rp   #special_ortho_group_frozen.__init__u  s&    , -T2
::11#6r6   c                 N    U R                   R                  U R                  X5      $ rz   r   r  r   rE  s      r4   r  special_ortho_group_frozen.rvs      zz~~dhh;;r6   r   r   r2  rI  r   r   r   r   rp   r  r   r/   r6   r4   r  r  t      72<r6   r  c                   J   ^  \ rS rSrSrSU 4S jjrS	S jrS rS
S jrSr	U =r
$ )ortho_group_geni  a  An Orthogonal matrix (O(N)) random variable.

Return a random orthogonal matrix, drawn from the O(N) Haar
distribution (the only uniform distribution on O(N)).

The `dim` keyword specifies the dimension N.

Methods
-------
rvs(dim=None, size=1, random_state=None)
    Draw random samples from O(N).

Parameters
----------
dim : scalar
    Dimension of matrices
seed : {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`.

Notes
-----
This class is closely related to `special_ortho_group`.

Some care is taken to avoid numerical error, as per the paper by Mezzadri.

References
----------
.. [1] F. Mezzadri, "How to generate random matrices from the classical
       compact groups", :arXiv:`math-ph/0609050v2`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import ortho_group
>>> x = ortho_group.rvs(3)

>>> np.dot(x, x.T)
array([[  1.00000000e+00,   1.13231364e-17,  -2.86852790e-16],
       [  1.13231364e-17,   1.00000000e+00,  -1.46845020e-16],
       [ -2.86852790e-16,  -1.46845020e-16,   1.00000000e+00]])

>>> import scipy.linalg
>>> np.fabs(scipy.linalg.det(x))
1.0

This generates one random matrix from O(3). It is orthogonal and
has a determinant of +1 or -1.

Alternatively, the object may be called (as a function) to fix the `dim`
parameter, returning a "frozen" ortho_group random variable:

>>> rv = ortho_group(5)
>>> # Frozen object with the same methods but holding the
>>> # dimension parameter fixed.

See Also
--------
special_ortho_group
c                 n   > [         TU ]  U5        [        R                  " U R                  5      U l        g rz   r  r   s     r4   rp   ortho_group_gen.__init__  r  r6   c                     [        XS9$ )zSCreate a frozen O(N) distribution.

See `ortho_group_frozen` for more information.
rS  )ortho_group_frozenr  s      r4   r   ortho_group_gen.__call__  s    
 "#11r6   c                     Ub0  [         R                  " U5      (       a  US::  d  U[        U5      :w  a  [        S5      eU$ r  r   zLDimension of rotation must be specified,and must be a scalar greater than 1.r  r  s     r4   r   #ortho_group_gen._process_parameters  A    ;bkk#..#(cSXo D E E 
r6   c                 L   U R                  U5      n[        U5      nU R                  U5      nUS:  a  U4OSnUR                  X!U4-   S9n[        R
                  R                  U5      u  pVUR                  SSSS9nXW[        U5      -  S[        R                  S	S	24   -  nU$ )
a  Draw random samples from O(N).

Parameters
----------
dim : integer
    Dimension of rotation space (N).
size : integer, optional
    Number of samples to draw (default 1).

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim)

r   r/   r  r   rc  r8   offsetaxis1axis2.N)
r   ry  r   r  r?   rZ   qrr  rC   r   ri   r   r   r   zqrr;   s           r4   r  ortho_group_gen.rvs  s      --l;4y&&s+(wT#J%67yy||A JJarJ4 	
AhRZZ*++r6   r.  rz   r2  rI  r  r   s   @r4   r   r     s#    @D62 r6   r   c                   (    \ rS rSrSS jrSS jrSrg)r$  i  Nc                 d    [        U5      U l        U R                  R                  U5      U l        g)a3  Create a frozen O(N) distribution.

Parameters
----------
dim : scalar
    Dimension of matrices
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

Examples
--------
>>> from scipy.stats import ortho_group
>>> g = ortho_group(5)
>>> x = g.rvs()

N)r   r   r   r   r  s      r4   rp   ortho_group_frozen.__init__  s&    , %T*
::11#6r6   c                 N    U R                   R                  U R                  X5      $ rz   r  rE  s      r4   r  ortho_group_frozen.rvs'  r  r6   r  r2  rI  r  r/   r6   r4   r$  r$    r  r6   r$  c                   V   ^  \ rS rSrSrS
U 4S jjrSS jrS rS rS r	SS jr
S	rU =r$ )random_correlation_geni+  a  A random correlation matrix.

Return a random correlation matrix, given a vector of eigenvalues.

The `eigs` keyword specifies the eigenvalues of the correlation matrix,
and implies the dimension.

Methods
-------
rvs(eigs=None, random_state=None)
    Draw random correlation matrices, all with eigenvalues eigs.

Parameters
----------
eigs : 1d ndarray
    Eigenvalues of correlation matrix
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.
tol : float, optional
    Tolerance for input parameter checks
diag_tol : float, optional
    Tolerance for deviation of the diagonal of the resulting
    matrix. Default: 1e-7

Raises
------
RuntimeError
    Floating point error prevented generating a valid correlation
    matrix.

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim),
    each having eigenvalues eigs.

Notes
-----

Generates a random correlation matrix following a numerically stable
algorithm spelled out by Davies & Higham. This algorithm uses a single O(N)
similarity transformation to construct a symmetric positive semi-definite
matrix, and applies a series of Givens rotations to scale it to have ones
on the diagonal.

References
----------

.. [1] Davies, Philip I; Higham, Nicholas J; "Numerically stable generation
       of correlation matrices and their factors", BIT 2000, Vol. 40,
       No. 4, pp. 640 651

Examples
--------
>>> import numpy as np
>>> from scipy.stats import random_correlation
>>> rng = np.random.default_rng()
>>> x = random_correlation.rvs((.5, .8, 1.2, 1.5), random_state=rng)
>>> x
array([[ 1.        , -0.02423399,  0.03130519,  0.4946965 ],
       [-0.02423399,  1.        ,  0.20334736,  0.04039817],
       [ 0.03130519,  0.20334736,  1.        ,  0.02694275],
       [ 0.4946965 ,  0.04039817,  0.02694275,  1.        ]])
>>> import scipy.linalg
>>> e, v = scipy.linalg.eigh(x)
>>> e
array([ 0.5,  0.8,  1.2,  1.5])

c                 n   > [         TU ]  U5        [        R                  " U R                  5      U l        g rz   r  r   s     r4   rp   random_correlation_gen.__init__w  r  r6   c                     [        XUUS9$ )zbCreate a frozen random correlation matrix.

See `random_correlation_frozen` for more information.
)r   toldiag_tol)random_correlation_frozen)ri   eigsr   r?  r@  s        r4   r   random_correlation_gen.__call__{  s    
 )c2:< 	<r6   c                 f   [         R                  " U[        S9nUR                  nUR                  S:w  d  UR
                  S   U:w  d  US::  a  [        S5      e[         R                  " [         R                  " U5      U-
  5      U:  a  [        S5      eU H  nXB* :  d  M  [        S5      e   X14$ )NrK   r   r   z7Array 'eigs' must be a vector of length greater than 1.z-Sum of eigenvalues must equal dimensionality.z%All eigenvalues must be non-negative.)	r?   rW   rM   r   r1   r   r]   fabsre   )ri   rB  r?  r   rO   s        r4   r   *random_correlation_gen._process_parameters  s    zz$e,ii99>TZZ]c1SAX / 0 0 77266$<#%&,LMMA4x !HII  yr6   c                    US-
  nUS-
  nUS:X  a  g[         R                  " [        US-  XE-  -
  S5      5      nU[         R                  " Xc5      -   U-  nS[         R                  " SXw-  -   5      -  nUS:X  a  Sn	X4$ X-  n	X4$ )a  Computes a 2x2 Givens matrix to put 1's on the diagonal.

The input matrix is a 2x2 symmetric matrix M = [ aii aij ; aij ajj ].

The output matrix g is a 2x2 anti-symmetric matrix of the form
[ c s ; -s c ];  the elements c and s are returned.

Applying the output matrix to the input matrix (as b=g.T M g)
results in a matrix with bii=1, provided tr(M) - det(M) >= 1
and floating point issues do not occur. Otherwise, some other
valid rotation is returned. When tr(M)==2, also bjj=1.

r   r   )r   r   r-   )mathra   rB   copysign)
ri   aiiajjaijaiidajjdddrG   crl   s
             r4   _givens_to_1#random_correlation_gen._givens_to_1  s     RxRx19YYs36DI-q12 4==))T128$$6A t Atr6   c                 z   UR                   R                  (       a>  UR                  [        R                  :X  a   UR
                  S   UR
                  S   :X  d
  [        5       eUR
                  S   n[        US-
  5       H  nXU4   S:X  a  M  XU4   S:  a#  [        US-   U5       H  nXU4   S:  d  M    O%   O"[        US-   U5       H  nXU4   S:  d  M    O   U R                  XU4   UWU4   XU4   5      u  pVUR                  5       n[        XwXV* UX2-  SXB-  SSSS9  [        XwXV* UX2XBSSS9  M     U$ )z
Given a psd matrix m, rotate to put one's on the diagonal, turning it
into a correlation matrix.  This also requires the trace equal the
dimensionality. Note: modifies input matrix
r   r   T)r   offxincxoffyincyoverwrite_xoverwrite_y)flagsc_contiguousr<   r?   r  r   r]   r  rQ  ravelr   )ri   mr;   r  jrP  rl   mvs           r4   _to_corrrandom_correlation_gen._to_corr  sD    $$BJJ)>
aggaj(,GGAJqsAAw!|a41qsAAAw{ ' qsAAAw{ ' $$Q!tWa1gqAw?DA BB!c!!t5 B!a!t5/ 6 r6   c                    U R                  XS9u  pQU R                  U5      n[        R                  XRS9n[        R
                  " [        R
                  " U[        R                  " U5      5      UR                  5      nU R                  U5      n[        UR                  5       S-
  5      R                  5       U:  a  [        S5      eU$ )a  Draw random correlation matrices.

Parameters
----------
eigs : 1d ndarray
    Eigenvalues of correlation matrix
tol : float, optional
    Tolerance for input parameter checks
diag_tol : float, optional
    Tolerance for deviation of the diagonal of the resulting
    matrix. Default: 1e-7

Raises
------
RuntimeError
    Floating point error prevented generating a valid correlation
    matrix.

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim),
    each having eigenvalues eigs.

r?  )r   r   z-Failed to generate a valid correlation matrix)r   r   r$   r  r?   r{   r   r|   r`  rC   r  rB   RuntimeError)ri   rB  r   r?  r@  r   r]  s          r4   r  random_correlation_gen.rvs  s    4 ,,T,;	--l;OOCO;FF266!RWWT]+QSS1MM! qzz|a $$&1NOOr6   r.  rz   NgvIh%<=gHz>)r   r   r   r   r   rp   r   r   rQ  r`  r  r   r   r   s   @r4   r;  r;  +  s/    IV6<"B'R& &r6   r;  c                   (    \ rS rSrSS jrSS jrSrg)rA  i
  Nc                     [        U5      U l        X0l        X@l        U R                  R	                  XR                  S9u  oPl        g)a  Create a frozen random correlation matrix distribution.

Parameters
----------
eigs : 1d ndarray
    Eigenvalues of correlation matrix
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.
tol : float, optional
    Tolerance for input parameter checks
diag_tol : float, optional
    Tolerance for deviation of the diagonal of the resulting
    matrix. Default: 1e-7

Raises
------
RuntimeError
    Floating point error prevented generating a valid correlation
    matrix.

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim),
    each having eigenvalues eigs.
rc  N)r;  r   r?  r@  r   rB  )ri   rB  r   r?  r@  r  s         r4   rp   "random_correlation_frozen.__init__  s:    B ,D1
 zz55d5I9r6   c                 v    U R                   R                  U R                  UU R                  U R                  S9$ )N)r   r?  r@  )r   r  rB  r?  r@  r   s     r4   r  random_correlation_frozen.rvs1  s3    zz~~diil"&((T]]  D 	Dr6   )r   r@  rB  r?  rf  rz   r  r/   r6   r4   rA  rA  
  s    $JLDr6   rA  c                   J   ^  \ rS rSrSrSU 4S jjrS	S jrS rS
S jrSr	U =r
$ )unitary_group_geni6  a  A matrix-valued U(N) random variable.

Return a random unitary matrix.

The `dim` keyword specifies the dimension N.

Methods
-------
rvs(dim=None, size=1, random_state=None)
    Draw random samples from U(N).

Parameters
----------
dim : scalar
    Dimension of matrices, must be greater than 1.
seed : {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`.

Notes
-----
This class is similar to `ortho_group`.

References
----------
.. [1] F. Mezzadri, "How to generate random matrices from the classical
       compact groups", :arXiv:`math-ph/0609050v2`.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import unitary_group
>>> x = unitary_group.rvs(3)

>>> np.dot(x, x.conj().T)
array([[  1.00000000e+00,   1.13231364e-17,  -2.86852790e-16],
       [  1.13231364e-17,   1.00000000e+00,  -1.46845020e-16],
       [ -2.86852790e-16,  -1.46845020e-16,   1.00000000e+00]])  # may vary

This generates one random matrix from U(3). The dot product confirms that
it is unitary up to machine precision.

Alternatively, the object may be called (as a function) to fix the `dim`
parameter, return a "frozen" unitary_group random variable:

>>> rv = unitary_group(5)

See Also
--------
ortho_group

c                 n   > [         TU ]  U5        [        R                  " U R                  5      U l        g rz   r  r   s     r4   rp   unitary_group_gen.__init__q  r  r6   c                     [        XS9$ )ztCreate a frozen (U(N)) n-dimensional unitary matrix distribution.

See `unitary_group_frozen` for more information.
rS  )unitary_group_frozenr  s      r4   r   unitary_group_gen.__call__u  s    
 $C33r6   c                     Ub0  [         R                  " U5      (       a  US::  d  U[        U5      :w  a  [        S5      eU$ r'  r  r  s     r4   r   %unitary_group_gen._process_parameters|  r)  r6   c                    U R                  U5      n[        U5      nU R                  U5      nUS:  a  U4OSnS[        R                  " S5      -  UR                  X!U4-   S9SUR                  X!U4-   S9-  -   -  n[        R                  R                  U5      u  pVUR                  SSSS	9nXW[        U5      -  S
[        R                  SS24   -  nU$ )a  Draw random samples from U(N).

Parameters
----------
dim : integer
    Dimension of space (N).
size : integer, optional
    Number of samples to draw (default 1).

Returns
-------
rvs : ndarray or scalar
    Random size N-dimensional matrices, dimension (size, dim, dim)

r   r/   r-   r  y              ?r   rc  r8   r+  .N)r   ry  r   rH  ra   r  r?   rZ   r/  r  rC   r   r0  s           r4   r  unitary_group_gen.rvs  s      --l;4y&&s+(wdiilNL//T#J5F/G|22Sz8I2JJK Lyy||A JJarJ4 	
AhRZZ*++r6   r.  rz   r2  rI  r  r   s   @r4   rm  rm  6  s"    8t64   r6   rm  c                   (    \ rS rSrSS jrSS jrSrg)rq  i  Nc                 d    [        U5      U l        U R                  R                  U5      U l        g)aR  Create a frozen (U(N)) n-dimensional unitary matrix distribution.

Parameters
----------
dim : scalar
    Dimension of matrices
seed : {None, int, `numpy.random.Generator`, `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

Examples
--------
>>> from scipy.stats import unitary_group
>>> x = unitary_group(3)
>>> x.rvs()

N)rm  r   r   r   r  s      r4   rp   unitary_group_frozen.__init__  s&    , 't,
::11#6r6   c                 N    U R                   R                  U R                  X5      $ rz   r  rE  s      r4   r  unitary_group_frozen.rvs  r  r6   r  r2  rI  r  r/   r6   r4   rq  rq    r  r6   rq  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_noter   c                      ^  \ rS rSrSrSU 4S jjr  SS jrSS jrSS jrS r	  SS	 jr
SSSSS
.S jjrSS jrSS jrSS jrS rS rSrU =r$ )multivariate_t_geni  a	  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.
cdf(x, loc=None, shape=1, df=1, allow_singular=False, *,
    maxpts=None, lower_limit=None, random_state=None)
    Cumulative distribution function.
rvs(loc=None, shape=1, df=1, size=1, random_state=None)
    Draw random samples from a multivariate t-distribution.
entropy(loc=None, shape=1, df=1)
    Differential entropy of a multivariate t-distribution.

Parameters
----------
%(_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}}
           \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

References
----------
.. [1] Arellano-Valle et al. "Shannon Entropy and Mutual Information for
       Multivariate Skew-Elliptical Distributions". Scandinavian Journal
       of Statistics. Vol. 40, issue 1.

Examples
--------
The object may be called (as a function) to fix the `loc`, `shape`,
`df`, and `allow_singular` parameters, returning a "frozen"
multivariate_t random variable:

>>> import numpy as np
>>> from scipy.stats import multivariate_t
>>> rv = multivariate_t([1.0, -0.5], [[2.1, 0.3], [0.3, 1.5]], df=2)
>>> # Frozen object with the same methods but holding the given location,
>>> # scale, and degrees of freedom fixed.

Create a contour plot of the PDF.

>>> import matplotlib.pyplot as plt
>>> x, y = np.mgrid[-1:3:.01, -2:1.5:.01]
>>> pos = np.dstack((x, y))
>>> fig, ax = plt.subplots(1, 1)
>>> ax.set_aspect('equal')
>>> plt.contourf(x, y, rv.pdf(pos))

Nc                    > [         TU ]  U5        [        R                  " U R                  [
        5      U l        [        U5      U l        g)zfInitialize a multivariate t-distributed random variable.

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

N)r   rp   r   r   r   mvt_docdict_paramsr   r   r   s     r4   rp   multivariate_t_gen.__init__>  s8     	''6HI/5r6   c                 V    U[         R                  :X  a  [        XUUS9$ [        XUXES9$ )zZCreate a frozen multivariate t-distribution.

See `multivariate_t_frozen` for parameters.
)r   r   rk   r   )locr   r  rk   r   )r?   r   r   multivariate_t_frozen)ri   r  r   r  rk   r   s         r4   r   multivariate_t_gen.__call__J  s<     <-3=K379 9 %b4BO 	Or6   c           	          U R                  X#U5      u  pbp4U R                  X5      n[        X5S9nU R                  XUR                  UR
                  UXgR                  5      n[        R                  " U5      $ )a  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)
0.00075713

r   )	r   r   rR   r   rd   rg   rc   r?   r   )	ri   rO   r  r   r  rk   r   
shape_infor   s	            r4   r   multivariate_t_gen.pdfW  sj    0 #66s2F%##A+%?
ajllJ4G4G!??4vvf~r6   c           	          U R                  X#U5      u  pRp4U R                  X5      n[        U5      nU R                  XUR                  UR
                  XEUR                  5      $ )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)
-7.1859802

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

)r   r   rR   r   rd   rg   rc   )ri   rO   r  r   r  r   r  s          r4   r   multivariate_t_gen.logpdfv  s^    : #66s2F%##A+%[
||AJLL*2E2Er&OO- 	-r6   c                    U[         R                  :X  a  [        R                  XX4U5      $ X-
  n[         R                  " [         R
                  " X5      5      R                  SS9n	SXV-   -  n
[        U
5      n[        SU-  5      nUS-  [         R                  " U[         R                  -  5      -  nSU-  nU
* [         R                  " SSU-  U	-  -   5      -  n[        X-
  U-
  U-
  U-   5      $ )a  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.

r8   rs   r"  r  r   r   )r?   r   r   r   r   r{   re   r   rf   pir5   )ri   rO   r  prec_Urg   r  r   rc   r   r   rG   r0  Br  r  Es                   r4   r   multivariate_t_gen._logpdf  s    8 <&..qvNNgyy,-11r1:28AJC"HFRVVBJ''(NBRUdN*++quqy1}q011r6   c	                 R  ^^^^^ Ub  [        U5      mOU R                  mT(       d  SU-  mU R                  X5      nUc0  [        R                  " UR
                  [        R                  * 5      OUnX-
  Xr-
  pq[        R                  " X5      u  pX:  nSUR                  SS9-  nU
R                  5       U	R                  5       pX   X   sX'   X'   UR
                  S   m[        R                  " X4SS9nUUUUU4S jn[        R                  " USU5      U-  n[        U5      $ )Ni  r8   rs   c                 :   > U S T U TS  p![        TTTXT5      S   $ r   r   )r   r
  r	  r  r   r   rngr   s      r4   r  'multivariate_t_gen._cdf.<locals>.func1d  s.    "1:vabzqUA#6q99r6   )r   r   r   r?   r  r   r   r  re   r  r  r  r5   )ri   rO   r  r   r  r   r   r  r   r	  r
  r  r  r   r  resr   r  s      `` `         @@r4   r  multivariate_t_gen._cdf  s    #$\2C$$CCZF##A+%- wwsyy266'23> 	 +"3;""12vzzrz*+vvx1 y!)	19GGBKR0	: 	: !!&"f5= s##r6   r   r  r   c          
      z    U R                  X#U5      u  pp4[        X5S9R                  nU R                  XX4XXx5      $ )a3  Multivariate t-distribution cumulative distribution function.

Parameters
----------
x : array_like
    Points at which to evaluate the cumulative distribution function.
%(_mvt_doc_default_callparams)s
maxpts : int, optional
    Maximum number of points to use for integration. The default is
    1000 times the number of dimensions.
lower_limit : array_like, optional
    Lower limit of integration of the cumulative distribution function.
    Default is negative infinity. Must be broadcastable with `x`.
%(_doc_random_state)s

Returns
-------
cdf : ndarray or scalar
    Cumulative distribution 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.cdf(x, loc, shape, df)
0.64798491

r   )r   rR   rX   r  )
ri   rO   r  r   r  rk   r   r  r   r   s
             r4   r  multivariate_t_gen.cdf  sF    B #66s2F%U:==yyC$4 	4r6   c                   ^ U[         R                  :X  a  [        S US9R                  5       $ [	        U5      nSUR
                  -  mU4S jnU4S jnUS-  S-  [         R                  " U5      S-   -  n[        X':  X4XeS9$ )	N)r   r"  c                    > SX-   -  nSU-  n[        U5      * [        U5      -   SU -  [        R                  " U[        R                  -  5      -  -   U[	        U5      [	        U5      -
  -  -   T-   $ )Nr"  )r   r?   rf   r  r   )r   r  halfsumhalf_df
shape_terms       r4   regular,multivariate_t_gen._entropy.<locals>.regular  s{    SX&GBhG!!GG$44)bffR"%%Z0013:w<#g,.400 r6   c                    > U [         R                  " 5       -  X-  -   X S-
  -  US-  -  S-  -
  U S-  U S-
  -  US-  -  S-  -   U SU S-  -  SU S-  -  -   S-
  -  US	-  -  S
-  -   U S-  SU S-  -  SU S-  -  -
  S-   -  US-  -  S-  -   T-   S   $ )Nr-   g                   r     g         
      g         r/   )r   r  )r   r  r  s     r4   
asymptotic/multivariate_t_gen._entropy.<locals>.asymptotic#  s    
 dmmo%0q/BH,q01q&C!G$r4x/!34 c1fq36z1A56TABFG q&AQJc1f4r9:RXEJ	K
   r6   d   r  r   )r:   f2)r?   r   r   r#  rR   rg   rf   r   )	ri   r   r  r   r  r  r  	thresholdr  s	           @r4   r  multivariate_t_gen._entropy  sz    <&t7??AA%[
:...
		 #IMRVVC[1_5	"/C9
OOr6   c                 P    U R                  SX#5      u  pAp#U R                  XCU5      $ )zCalculate the differential entropy of a multivariate
t-distribution.

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

Returns
-------
h : float
    Differential entropy

Nr   r  )ri   r  r   r  r   s        r4   r#  multivariate_t_gen.entropy4  s,     #66tUG%}}Se,,r6   c                    U R                  XU5      u  pap#Ub  [        U5      nOU R                  n[        R                  " U5      (       a  [        R
                  " U5      nOUR                  X4S9U-  nUR                  [        R                  " U5      X$S9n	X[        R                  " U5      S   -  -   n
[        U
5      $ )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]])

r  r	  )r   r   r   r?   isinfonesr)  r   r   ra   r5   )ri   r  r   r  r   r   r   r  rO   r1  sampless              r4   r  multivariate_t_gen.rvsE  s    @ #66s2F%#$\2C$$C88B<<Ab,r1A##BHHSM5#DBGGAJy111w''r6   c                    [         R                  " U[        S9nUR                  S:X  a  U[         R                     nU$ UR                  S:X  a6  US:X  a  USS2[         R                  4   nU$ U[         R                  SS24   nU$ r   r   r   s      r4   r   %multivariate_t_gen._process_quantilest  sy    
 JJq&66Q;"**A  VVq[axam$  bjj!m$r6   c                 @   Uc8  Uc5  [         R                  " S[        S9n[         R                  " S[        S9nSnOUcR  [         R                  " U[        S9nUR                  S:  a  SnOUR                  S   n[         R
                  " U5      nO}Uc<  [         R                  " U[        S9nUR                  n[         R                  " U5      nO>[         R                  " U[        S9n[         R                  " U[        S9nUR                  nUS:X  a#  UR                  S5      nUR                  SS5      nUR                  S:w  d  UR                  S   U:w  a  [        SU-  5      eUR                  S:X  a  U[         R                  " U5      -  nOUR                  S:X  a  [         R                  " U5      nOUR                  S:X  an  UR                  XD4:w  a]  UR                  u  pVXV:w  a  S[        UR                  5       S3nO%SnU[        UR                  5      [        U5      4-  n[        U5      eUR                  S:  a  [        S	UR                  -  5      eUc  SnO7US::  a  [        S
5      e[         R                  " U5      (       a  [        S5      eXAX#4$ )zo
Infer dimensionality from location array and shape matrix, handle
defaults, and ensure compatible dimensions.
r   rK   r   r-   z*Array 'loc' must be a vector of length %d.r   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?   rW   rM   r1   r   r   r   r   r   r]   r   r   r^   isnan)ri   r  r   r  r   r   r   rn   s           r4   r   &multivariate_t_gen._process_parameters  s0   
 ;5=**Qe,CJJq.EC[JJuE2EzzA~kk!n((3-C]**S.C((CFF3KEJJuE2E**S.C((C!8++a.CMM!Q'E88q=CIIaLC/I ! " "::?BFF3K'EZZ1_GGENEZZ1_
!:JD|++.u{{+;*<A?>S-s3x88S/!ZZ!^ 249JJ? @ @ :B1W>??XXb\\WXX""r6   )r   r   rz   Nr   r   FN)Nr   r   Fr  rK  r  r  )r   r   r   r   r   rp   r   r   r   r   r  r  r  r#  r  r   r   r   r   r   s   @r4   r  r    ss    Pd
6 @EO>!-F)2V EI%$N%4T%4N PD-"-(^:# :#r6   r  c                   P    \ rS rSr  SS jrS rSSSS.S jrS rSS jrS	 r	S
r
g)r  i  Nc                     [        U5      U l        U R                  R                  XU5      u  pap#XaX#4u  U l        U l        U l        U l        [        X$S9U l        g)a  Create a frozen multivariate t distribution.

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

Examples
--------
>>> import numpy as np
>>> from scipy.stats import multivariate_t
>>> 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  r   r   r   r  r   r  rR   r  )ri   r  r   r  rk   r   r   s          r4   rp   multivariate_t_frozen.__init__  sR    , (-
"jj<<SL%25E2E/$(DJuDr6   c           	      F   U R                   R                  XR                  5      nU R                  R                  nU R                  R
                  nU R                   R                  XR                  X#U R                  U R                  U R                  R                  5      $ rz   )
r   r   r   r  rd   rg   r   r  r  rc   )ri   rO   rd   rg   s       r4   r   multivariate_t_frozen.logpdf  sp    JJ))!XX6OO??++zz!!!XXqDGGTXX"&//"6"68 	8r6   r  c          
          U R                   R                  XR                  5      nU R                   R                  XR                  U R
                  U R                  U R                  X#U5      $ rz   )r   r   r   r  r  r   r  )ri   rO   r   r  r   s        r4   r  multivariate_t_frozen.cdf  sN    JJ))!XX6zzq((DJJ%LB 	Br6   c                 L    [         R                  " U R                  U5      5      $ rz   r<  r=  s     r4   r   multivariate_t_frozen.pdf  r?  r6   c                 x    U R                   R                  U R                  U R                  U R                  UUS9$ )N)r  r   r  r   r   )r   r  r  r   r  rE  s      r4   r  multivariate_t_frozen.rvs  s6    zz~~$(($(JJ!%#'+7	  9 	9r6   c                 x    U R                   R                  U R                  U R                  U R                  5      $ rz   )r   r  r   r  r   r}   s    r4   r#  multivariate_t_frozen.entropy  s'    zz""488TWWdjjAAr6   )r   r  r   r  r   r  r  rI  )r   r   r   r   rp   r   r  r   r  r#  r   r/   r6   r4   r  r    s2    ?DE68  $D B
&9Br6   r  )r   r   r  r  r#  zm : array_like
    The number of each type of object in the population.
    That is, :math:`m[i]` is the number of objects of
    type :math:`i`.
n : array_like
    The number of samples taken from the population.
a  `m` must be an array of positive integers. If the quantile
:math:`i` contains values out of the range :math:`[0, m_i]`
where :math:`m_i` is the number of objects of type :math:`i`
in the population or if the parameters are inconsistent with one
another (e.g. ``x.sum() != n``), methods return the appropriate
value (e.g. ``0`` for ``pmf``). If `m` or `n` contain negative
values, the result will contain ``nan`` there.
c                   z   ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
 rS rS rS rSS jrSrU =r$ )multivariate_hypergeom_geni)  a  A multivariate hypergeometric random variable.

Methods
-------
pmf(x, m, n)
    Probability mass function.
logpmf(x, m, n)
    Log of the probability mass function.
rvs(m, n, size=1, random_state=None)
    Draw random samples from a multivariate hypergeometric
    distribution.
mean(m, n)
    Mean of the multivariate hypergeometric distribution.
var(m, n)
    Variance of the multivariate hypergeometric distribution.
cov(m, n)
    Compute the covariance matrix of the multivariate
    hypergeometric distribution.

Parameters
----------
%(_doc_default_callparams)s
%(_doc_random_state)s

Notes
-----
%(_doc_callparams_note)s

The probability mass function for `multivariate_hypergeom` is

.. math::

    P(X_1 = x_1, X_2 = x_2, \ldots, X_k = x_k) = \frac{\binom{m_1}{x_1}
    \binom{m_2}{x_2} \cdots \binom{m_k}{x_k}}{\binom{M}{n}}, \\ \quad
    (x_1, x_2, \ldots, x_k) \in \mathbb{N}^k \text{ with }
    \sum_{i=1}^k x_i = n

where :math:`m_i` are the number of objects of type :math:`i`, :math:`M`
is the total number of objects in the population (sum of all the
:math:`m_i`), and :math:`n` is the size of the sample to be taken
from the population.

.. versionadded:: 1.6.0

Examples
--------
To evaluate the probability mass function of the multivariate
hypergeometric distribution, with a dichotomous population of size
:math:`10` and :math:`20`, at a sample of size :math:`12` with
:math:`8` objects of the first type and :math:`4` objects of the
second type, use:

>>> from scipy.stats import multivariate_hypergeom
>>> multivariate_hypergeom.pmf(x=[8, 4], m=[10, 20], n=12)
0.0025207176631464523

The `multivariate_hypergeom` distribution is identical to the
corresponding `hypergeom` distribution (tiny numerical differences
notwithstanding) when only two types (good and bad) of objects
are present in the population as in the example above. Consider
another example for a comparison with the hypergeometric distribution:

>>> from scipy.stats import hypergeom
>>> multivariate_hypergeom.pmf(x=[3, 1], m=[10, 5], n=4)
0.4395604395604395
>>> hypergeom.pmf(k=3, M=15, n=4, N=10)
0.43956043956044005

The functions ``pmf``, ``logpmf``, ``mean``, ``var``, ``cov``, and ``rvs``
support broadcasting, under the convention that the vector parameters
(``x``, ``m``, and ``n``) are interpreted as if each row along the last
axis is a single object. For instance, we can combine the previous two
calls to `multivariate_hypergeom` as

>>> multivariate_hypergeom.pmf(x=[[8, 4], [3, 1]], m=[[10, 20], [10, 5]],
...                            n=[12, 4])
array([0.00252072, 0.43956044])

This broadcasting also works for ``cov``, where the output objects are
square matrices of size ``m.shape[-1]``. For example:

>>> multivariate_hypergeom.cov(m=[[7, 9], [10, 15]], n=[8, 12])
array([[[ 1.05, -1.05],
        [-1.05,  1.05]],
       [[ 1.56, -1.56],
        [-1.56,  1.56]]])

That is, ``result[0]`` is equal to
``multivariate_hypergeom.cov(m=[7, 9], n=8)`` and ``result[1]`` is equal
to ``multivariate_hypergeom.cov(m=[10, 15], n=12)``.

Alternatively, the object may be called (as a function) to fix the `m`
and `n` parameters, returning a "frozen" multivariate hypergeometric
random variable.

>>> rv = multivariate_hypergeom(m=[10, 20], n=12)
>>> rv.pmf(x=[8, 4])
0.0025207176631464523

See Also
--------
scipy.stats.hypergeom : The hypergeometric distribution.
scipy.stats.multinomial : The multinomial distribution.

References
----------
.. [1] The Multivariate Hypergeometric Distribution,
       http://www.randomservices.org/random/urn/MultiHypergeometric.html
.. [2] Thomas J. Sargent and John Stachurski, 2020,
       Multivariate Hypergeometric Distribution
       https://python.quantecon.org/multi_hyper.html
c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   r   r   mhg_docdict_paramsr   s     r4   rp   #multivariate_hypergeom_gen.__init__  r   r6   c                     [        XUS9$ )zpCreate a frozen multivariate_hypergeom distribution.

See `multivariate_hypergeom_frozen` for more information.
rS  )multivariate_hypergeom_frozen)ri   r]  r   r   s       r4   r   #multivariate_hypergeom_gen.__call__  s    
 -Q==r6   c           
      8   [         R                  " U5      n[         R                  " U5      nUR                  S:X  a  UR                  [        5      nUR                  S:X  a  UR                  [        5      n[         R
                  " UR                  [         R                  5      (       d  [        S5      e[         R
                  " UR                  [         R                  5      (       d  [        S5      eUR                  S:X  a  [        S5      eUR                  S:w  a  US[         R                  4   n[         R                  " X5      u  pUR                  S:w  a  US   nUS:  nUR                  SS9nUS:  X$:  -  nXAX#U[         R                  " USS9U-  4$ )	Nr   z'm' must an array of integers.z'n' must an array of integers.z1'm' must be an array with at least one dimension..r  r8   rs   )r?   rW   r   astypery  
issubdtyper<   integer	TypeErrorr1   r]   r   r  re   r   )ri   r]  r   mcondrj   r  s         r4   r   .multivariate_hypergeom_gen._process_parameters  sA   JJqMJJqM66Q;A66Q;A}}QWWbjj11<==}}QWWbjj11<==66Q; 8 9 9 66Q;#rzz/"A""1( 66Q;&	AAEErENQ15!QubffU&<u&DDDr6   c           
         [         R                  " U5      n[         R                  " UR                  [         R                  5      (       d  [        S5      eUR                  S:X  a  [        S5      eUR                  S   UR                  S   :X  d,  [        SUR                  S    SUR                  S    S35      eUR                  S:w  a*  US[         R                  4   nUS[         R                  4   n[         R                  " XXB5      u  ppBUR                  S:w  a	  US	   US	   p$US:  X:  -  nXX4U[         R                  " USS
9UR                  SS
9U:g  -  4$ )Nz'x' must an array of integers.r   z1'x' must be an array with at least one dimension.r8   z4Size of each quantile must be size of 'm': received z, but expected r   .r  rs   )r?   rW   r  r<   r  r  r1   r]   r   r   r   r  r   re   )ri   rO   rj   r]  r   r  s         r4   r   -multivariate_hypergeom_gen._process_quantiles  sI   JJqM}}QWWbjj11<==66Q; 8 9 9wwr{aggbk)  ))* 6--.WWR[M< = =
 66Q;#rzz/"A#rzz/"A((q4
a 66Q;V9aiqQ15!aEu2&!%%R%.A*=>@ 	@r6   c                     [         R                  " U5      nUR                  S:w  a  X1U'   O	U(       a  U$ UR                  S:X  a  US   $ U$ )Nr   r/   r  r  s       r4   r  'multivariate_hypergeom_gen._checkresult  sF    F#99>$4L;;!":r6   c                    [         R                  " U[         R                  S9n[         R                  " U[         R                  S9nX5)    X)    pX&)    XF)    pB[        US-   S5      [        US-   X1-
  S-   5      -
  Xu) '   [        US-   S5      [        US-   X$-
  S-   5      -
  X) '   [         R                  Xu'   [         R                  X'   UR                  SS9nXx-
  $ )NrK   r   r8   rs   )r?   
zeros_liker  r	   r  re   )	ri   rO   rj   r]  r   mxcondr  numdens	            r4   r  "multivariate_hypergeom_gen._logpmf  s     mmARZZ0mmARZZ0z1W:1y!F)1qsA!QSU);;Gac1~qsACE(::FffVV
gg2gyr6   c                 *   U R                  X#5      u  pBp5pgU R                  XX#5      u  pp#nn	XX-  n
U[        R                  " UR                  [        R
                  S9-  nU R                  XX#X5      nU	[        R                  " UR                  [        R
                  S9-  nU R                  X[        R                  * 5      nU[        R                  " U	R                  [        R
                  S9-  nU R                  X[        R                  5      $ )aR  Log of the multivariate hypergeometric probability mass function.

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

Returns
-------
logpmf : ndarray or scalar
    Log of the probability mass function evaluated at `x`

Notes
-----
%(_doc_callparams_note)s
rK   )
r   r   r?   r   r   r  r  r  r   r  )ri   rO   r]  r   rj   r  r  mncondr  xcond_reducedr  r  r  mncond_s                 r4   r  !multivariate_hypergeom_gen.logpmf  s    $ )-(@(@(F%a11!=	qU	99aA&8 &,,bhh!GG""6BFF7; 288M$7$7rxxHH  "&&99r6   c                 R    [         R                  " U R                  XU5      5      nU$ )a<  Multivariate hypergeometric probability mass function.

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

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

Notes
-----
%(_doc_callparams_note)s
r  )ri   rO   r]  r   r3   s        r4   r  multivariate_hypergeom_gen.pmf  s"    $ ffT[[q)*
r6   c                    U R                  X5      u  p1n  pEUR                  S:w  a)  US[        R                  4   US[        R                  4   p#US:H  n[        R                  R                  X6S9nX!U-  -  nUR                  S:w  aC  US[        R                  4   [        R                  " UR                  [        R                  S9-  nU R                  Xu[        R                  5      $ )zMean of the multivariate hypergeometric distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
mean : array_like or scalar
    The mean of the distribution
r   .maskrK   r   r   r?   r   mamasked_arrayr   r   r  r  r  )ri   r]  r   rj   r  r  rE   mus           r4   r   multivariate_hypergeom_gen.mean1  s     !% 8 8 >aA66Q;S"**_%qbjj'9qQEEq,!W66Q;S"**_-hhrxxrxx89F  RVV44r6   c                    U R                  X5      u  p1n  pEUR                  S:w  a)  US[        R                  4   US[        R                  4   p#US:H  US-
  S:H  -  n[        R                  R                  X6S9nX!-  U-  X1-
  -  U-  X2-
  -  US-
  -  nUR                  S:w  aC  US[        R                  4   [        R                  " UR                  [        R                  S9-  nU R                  Xu[        R                  5      $ )a	  Variance of the multivariate hypergeometric distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
array_like
    The variances of the components of the distribution.  This is
    the diagonal of the covariance matrix of the distribution
r   .r   r  rK   r  )ri   r]  r   rj   r  r  rE   outputs           r4   r  multivariate_hypergeom_gen.varI  s     !% 8 8 >aA66Q;S"**_%qbjj'9qQ1Q3!8$EEq,qAC"ac*AaC066Q;S"**_-hhv||288<=F  88r6   c                    U R                  X5      u  p1n  pEUR                  S:w  aH  US[        R                  [        R                  4   nUS[        R                  [        R                  4   nUS:H  US-
  S:H  -  n[        R                  R                  X6S9nU* X2-
  -  US-
  -  [        R                  " SX5      -  US-  -  nUR                  S:w  a  US   US   p#US   nUR                  S   n[        U5       HE  n	X#U-
  -  USU	4   -  X1SU	4   -
  -  USX4'   USX4   US-
  -  USX4'   USX4   US-  -  USX4'   MG     UR                  S:w  aR  US[        R                  [        R                  4   [        R                  " UR                  [        R                  S	9-  nU R                  Xu[        R                  5      $ )
zCovariance matrix of the multivariate hypergeometric distribution.

Parameters
----------
%(_doc_default_callparams)s

Returns
-------
cov : array_like
    The covariance matrix of the distribution
r   .r   r  z...i,...j->...ijr-   ).r   r   r8   rK   )r   r   r?   r   r  r  r}  r   r  r   r  r  r  )
ri   r]  r   rj   r  r  rE   r  r   r  s
             r4   r   multivariate_hypergeom_gen.covb  s    !% 8 8 >aA66Q;#rzz2::-.A#rzz2::-.AQ1Q3!8$EEq,"*ac")).569:A? 66Q;Y<9q	?DggbksA!"cQsAvY!6CF)!DF39 &sAy 1QqS 9F39 &sAy 1QT :F39  66Q;S"**bjj89hhv||288<=F  88r6   c           	      .   U R                  X5      u  pQn    nU R                  U5      nUb  [        U[        5      (       a  U4nUc*  [        R
                  " UR                  UR                  S9nO/[        R
                  " X1R                  S   4-   UR                  S9nUn[        UR                  S   S-
  5       H>  n	XSU	4   -
  nUS:H  n
U
) UR                  USU	4   X-   X*-   US9-  USU	4'   X'SU	4   -
  nM@     X'SUR                  S   S-
  4'   U$ )aI  Draw random samples from a multivariate hypergeometric distribution.

Parameters
----------
%(_doc_default_callparams)s
size : integer or iterable of integers, optional
    Number of samples to draw. Default is ``None``, in which case a
    single variate is returned as an array with shape ``m.shape``.
%(_doc_random_state)s

Returns
-------
rvs : array_like
    Random variates of shape ``size`` or ``m.shape``
    (if ``size=None``).

Notes
-----
%(_doc_callparams_note)s

Also note that NumPy's `multivariate_hypergeometric` sampler is not
used as it doesn't support broadcasting.
rK   r8   r   .r   r  )
r   r   r   ry  r?   r  r   r<   r  hypergeometric)ri   r]  r   r   r   rj   r  r  remrP  n0masks              r4   r  multivariate_hypergeom_gen.rvs  s1   0  33A9aAq--l;
4 5 58D<((177!''2C((4772;/1AC qwwr{Q'A#q&	/C!VF"7'66qay7:|78z<@ 7 BBCQK
 QKA ( %&Cq !
r6   r.  rz   r2  )r   r   r   r   r   rp   r   r   r   r  r  r  r  r   r  r   r  r   r   r   s   @r4   r  r  )  sQ    o`J>E@@6":H*5092$9L2 2r6   r  c                   F    \ rS rSrSS jrS rS rS rS rS r	SS	 jr
S
rg)r  i  Nc                    ^  [        U5      T l        T R                  R                  X5      u  T l        T l        T l        T l        T l        T l        U 4S jnUT R                  l        g )Nc                    > TR                   TR                  TR                  TR                  TR                  TR
                  4$ rz   )rj   r]  r   r  r  r  )r]  r   ri   s     r4   r   Cmultivariate_hypergeom_frozen.__init__.<locals>._process_parameters  s4    FFDFFDFFJJ

KK! !r6   )	r  r   r   rj   r]  r   r  r  r  )ri   r]  r   r   r   s   `    r4   rp   &multivariate_hypergeom_frozen.__init__  sU    /5
 

66q<		TZ		! *=

&r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r]  r   r=  s     r4   r  $multivariate_hypergeom_frozen.logpmf  r  r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r]  r   r=  s     r4   r  !multivariate_hypergeom_frozen.pmf  r  r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r]  r   r}   s    r4   r   "multivariate_hypergeom_frozen.mean  r  r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r  r]  r   r}   s    r4   r  !multivariate_hypergeom_frozen.var  r  r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r]  r   r}   s    r4   r   !multivariate_hypergeom_frozen.cov  r  r6   c                 b    U R                   R                  U R                  U R                  UUS9$ Nr   r   )r   r  r]  r   rE  s      r4   r  !multivariate_hypergeom_frozen.rvs  s.    zz~~dffdff#'+7  9 	9r6   )rj   r   r]  r  r  r   r  rz   rI  )r   r   r   r   rp   r  r  r   r  r   r  r   r/   r6   r4   r  r    s%    =41/..9r6   r  )r  r  r   r  r   r  c                      ^  \ rS rSrSrSU 4S jjrSS.S jrS rS rS	 r	SSSS
.S jr
\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrU =r$ )random_table_geni  a*  Contingency tables from independent samples with fixed marginal sums.

This is the distribution of random tables with given row and column vector
sums. This distribution represents the set of random tables under the null
hypothesis that rows and columns are independent. It is used in hypothesis
tests of independence.

Because of assumed independence, the expected frequency of each table
element can be computed from the row and column sums, so that the
distribution is completely determined by these two vectors.

Methods
-------
logpmf(x)
    Log-probability of table `x` to occur in the distribution.
pmf(x)
    Probability of table `x` to occur in the distribution.
mean(row, col)
    Mean table.
rvs(row, col, size=None, method=None, random_state=None)
    Draw random tables with given row and column vector sums.

Parameters
----------
%(_doc_row_col)s
%(_doc_random_state)s

Notes
-----
%(_doc_row_col_note)s

Random elements from the distribution are generated either with Boyett's
[1]_ or Patefield's algorithm [2]_. Boyett's algorithm has
O(N) time and space complexity, where N is the total sum of entries in the
table. Patefield's algorithm has O(K x log(N)) time complexity, where K is
the number of cells in the table and requires only a small constant work
space. By default, the `rvs` method selects the fastest algorithm based on
the input, but you can specify the algorithm with the keyword `method`.
Allowed values are "boyett" and "patefield".

.. versionadded:: 1.10.0

Examples
--------
>>> from scipy.stats import random_table

>>> row = [1, 5]
>>> col = [2, 3, 1]
>>> random_table.mean(row, col)
array([[0.33333333, 0.5       , 0.16666667],
       [1.66666667, 2.5       , 0.83333333]])

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> dist = random_table(row, col)
>>> dist.rvs(random_state=123)
array([[1, 0, 0],
       [1, 3, 1]])

References
----------
.. [1] J. Boyett, AS 144 Appl. Statist. 28 (1979) 329-332
.. [2] W.M. Patefield, AS 159 Appl. Statist. 30 (1981) 91-97
Nc                 $   > [         TU ]  U5        g rz   r   rp   r   s     r4   rp   random_table_gen.__init__1      r6   rS  c                    [        XUS9$ )znCreate a frozen distribution of tables with given marginals.

See `random_table_frozen` for more information.
rS  )random_table_frozen)ri   rowcolr   s       r4   r   random_table_gen.__call__4  s    
 #3$77r6   c                    U R                  X#5      u  pEn[        R                  " U5      nUR                  S:  a  [	        S5      e[        R
                  " UR                  [        R                  5      n[        R                  " SS9   U(       d<  [        R                  " UR                  [        5      U:H  5      (       d  [	        S5      eSSS5        [        R                  " US:  5      (       a  [	        S5      e[        R                  " US	S
9n[        R                  " USS
9n	UR                  S	   [        U5      :w  a  [	        S5      eU	R                  S	   [        U5      :w  a  [	        S5      e[        R                   " UR                  SS 5      n
[        R                  " X:H  S	S
9[        R                  " X:H  S	S
9-  nS n[        R                  " U" U5      S	S
9[        R                  " U" U5      S	S
9-   U" U5      -
  [        R                  " U" X   5      SS
9-
  X'   [        R"                  * X) '   U
S   $ ! , (       d  f       GN~= f)a   Log-probability of table to occur in the distribution.

Parameters
----------
%(_doc_x)s
%(_doc_row_col)s

Returns
-------
logpmf : ndarray or scalar
    Log of the probability mass function evaluated at `x`.

Notes
-----
%(_doc_row_col_note)s

If row and column marginals of `x` do not match `row` and `col`,
negative infinity is returned.

Examples
--------
>>> from scipy.stats import random_table
>>> import numpy as np

>>> x = [[1, 5, 1], [2, 3, 1]]
>>> row = np.sum(x, axis=1)
>>> col = np.sum(x, axis=0)
>>> random_table.logpmf(x, row, col)
-1.6306401200847027

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> d = random_table(row, col)
>>> d.logpmf(x)
-1.6306401200847027
r-   z$`x` must be at least two-dimensionalignore)invalidz%`x` must contain only integral valuesNr   z)`x` must contain only non-negative valuesr8   rs   rc  z"shape of `x` must agree with `row`z"shape of `x` must agree with `col`c                     [        U S-   5      $ r1  )r   )rO   s    r4   lnfac&random_table_gen.logpmf.<locals>.lnfac}  s    1q5>!r6   )r8   rc  r/   )r   r?   rW   r1   r]   r  r<   r  errstateallr  ry  r   re   r   r^   r  r   )ri   rO   r  r  r3  rP  r   dtype_is_intr2c2r  r  r!  s                r4   r  random_table_gen.logpmf;  s   L **34aJJqM66A:CDD}}QWWbjj9[[*qxx}/A(B(B !HII +
 66!a%==HIIVVABVVAB88B<3q6!ABB88B<3q6!ABBhhqwws|$vvbgB'"&&r*BB	" VVE!H2.ar1JJQx "$&&qwh"GH	ffWE
2w9 +*s   	AI
Ic                 N    [         R                  " U R                  XU5      5      $ )a  Probability of table to occur in the distribution.

Parameters
----------
%(_doc_x)s
%(_doc_row_col)s

Returns
-------
pmf : ndarray or scalar
    Probability mass function evaluated at `x`.

Notes
-----
%(_doc_row_col_note)s

If row and column marginals of `x` do not match `row` and `col`,
zero is returned.

Examples
--------
>>> from scipy.stats import random_table
>>> import numpy as np

>>> x = [[1, 5, 1], [2, 3, 1]]
>>> row = np.sum(x, axis=1)
>>> col = np.sum(x, axis=0)
>>> random_table.pmf(x, row, col)
0.19580419580419592

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> d = random_table(row, col)
>>> d.pmf(x)
0.19580419580419592
r  )ri   rO   r  r  s       r4   r  random_table_gen.pmf  s    L vvdkk!#.//r6   c                 \    U R                  X5      u  p4n[        R                  " X45      U-  $ )a  Mean of distribution of conditional tables.
%(_doc_mean_params)s

Returns
-------
mean: ndarray
    Mean of the distribution.

Notes
-----
%(_doc_row_col_note)s

Examples
--------
>>> from scipy.stats import random_table

>>> row = [1, 5]
>>> col = [2, 3, 1]
>>> random_table.mean(row, col)
array([[0.33333333, 0.5       , 0.16666667],
       [1.66666667, 2.5       , 0.83333333]])

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> d = random_table(row, col)
>>> d.mean()
array([[0.33333333, 0.5       , 0.16666667],
       [1.66666667, 2.5       , 0.83333333]])
)r   r?   r  )ri   r  r  r3  rP  r   s         r4   r   random_table_gen.mean  s+    > **34axx~!!r6   r   methodr   c                    U R                  X5      u  pgnU R                  X6U5      u  p9U R                  U5      nU R                  XFXx5      n
U
" XgXU5      R	                  U	5      $ )ao  Draw random tables with fixed column and row marginals.

Parameters
----------
%(_doc_row_col)s
size : integer, optional
    Number of samples to draw (default 1).
method : str, optional
    Which method to use, "boyett" or "patefield". If None (default),
    selects the fastest method for this input.
%(_doc_random_state)s

Returns
-------
rvs : ndarray
    Random 2D tables of shape (`size`, `len(row)`, `len(col)`).

Notes
-----
%(_doc_row_col_note)s

Examples
--------
>>> from scipy.stats import random_table

>>> row = [1, 5]
>>> col = [2, 3, 1]
>>> random_table.rvs(row, col, random_state=123)
array([[1., 0., 0.],
       [1., 3., 1.]])

Alternatively, the object may be called (as a function) to fix the row
and column vector sums, returning a "frozen" distribution.

>>> d = random_table(row, col)
>>> d.rvs(random_state=123)
array([[1., 0., 0.],
       [1., 3., 1.]])
)r   _process_size_shaper   _process_rvs_methodr   )ri   r  r  r   r.  r   r3  rP  r   r   meths              r4   r  random_table_gen.rvs  si    P **34a..t:--l;''18A!<088??r6   c                 <   [         R                  " U [         R                  SS9n[         R                  " U[         R                  SS9n[         R                  " U5      S:w  a  [	        S5      e[         R                  " U5      S:w  a  [	        S5      e[         R
                  " US:  5      (       a  [	        S5      e[         R
                  " US:  5      (       a  [	        S5      e[         R                  " U5      nU[         R                  " U5      :w  a  [	        S	5      e[         R                  " U[         R                  " U 5      :H  5      (       d  [	        S
5      e[         R                  " U[         R                  " U5      :H  5      (       d  [	        S5      eX#U4$ )z
Check that row and column vectors are one-dimensional, that they do
not contain negative or non-integer entries, and that the sums over
both vectors are equal.
Tr  r   z`row` must be one-dimensionalz`col` must be one-dimensionalr   z*each element of `row` must be non-negativez*each element of `col` must be non-negativez'sums over `row` and `col` must be equalz(each element of `row` must be an integerz(each element of `col` must be an integer)	r?   rL   int64r1   r]   r   re   r$  rW   )r  r  r3  rP  r   s        r4   r   $random_table_gen._process_parameters   s!    HHSt4HHSt4771:?<==771:?<==66!a%==IJJ66!a%==IJJFF1Iq	>FGGvva2::c?*++GHHvva2::c?*++GHHQwr6   c                 j   [        U5      [        U5      4nU c  SU4$ [        R                  " U 5      n [        R                  " U R                  [        R
                  5      (       a  [        R                  " U S:  5      (       a  [        S5      e[        R                  " U 5      [        U 5      U-   4$ )zG
Compute the number of samples to be drawn and the shape of the output
r   r   z/`size` must be a non-negative integer or `None`)
r^   r?   r&  r  r<   r  r   r]   r  r  )r   r3  rP  r   s       r4   r0  $random_table_gen._process_size_shape  s    
 QQ <e8O}}T"}}TZZ44tax8H8HNOOwwt}eDkE111r6   c           	          U R                  X#U5      U R                  U R                  S.n XQ   $ ! [         a    [	        SU S[        U5       35      ef = f)N)Nboyett	patefield'z!' not recognized, must be one of )_rvs_select_rvs_boyett_rvs_patefieldKeyErrorr]   set)clsr.  r3  rP  r   known_methodss         r4   r1  $random_table_gen._process_rvs_method/  st     //!*oo++

	E (( 	Eq )//2=/A.BD E E	Es	   0 %Ac                     Sn[        U5      [        U5      -  nX4[        R                  " US-   5      -  U-  :  a  U R                  $ U R                  $ )Nr   r   )r^   r?   rf   r?  r>  )rB  r3  rP  r   facr'  s         r4   r=  random_table_gen._rvs_select<  sJ    FSVORVVAE]"Q&&%%%r6   c                 2    [         R                  " XX#U5      $ rz   )r   
rvs_rcont1r  r  ntotr   r   s        r4   r>  random_table_gen._rvs_boyettE        4|DDr6   c                 2    [         R                  " XX#U5      $ rz   )r   
rvs_rcont2rJ  s        r4   r?  random_table_gen._rvs_patefieldI  rM  r6   r/   rz   )r   r   r   r   r   rp   r   r  r  r   r  staticmethodr   r0  classmethodr1  r=  r>  r?  r   r   r   s   @r4   r  r    s    @D *. 8IV&0P "D %)D .@`  < 2 2 
E 
E   E E E Er6   r  c                   >    \ rS rSrSS.S jrS rS rS rS
S jrS	r	g)r  iQ  NrS  c                   ^  [        U5      T l        T R                  R                  X5      T l        U 4S jnUT R                  l        g )Nc                    > TR                   $ rz   )_params)r3  rP  ri   s     r4   r   9random_table_frozen.__init__.<locals>._process_parametersW  s    <<r6   )r  r   r   rV  )ri   r  r  r   r   s   `    r4   rp   random_table_frozen.__init__R  s6    %d+
zz55c?	 )<

&r6   c                 <    U R                   R                  US S 5      $ rz   )r   r  r=  s     r4   r  random_table_frozen.logpmf[  s    zz  D$//r6   c                 <    U R                   R                  US S 5      $ rz   )r   r  r=  s     r4   r  random_table_frozen.pmf^  s    zz~~at,,r6   c                 :    U R                   R                  S S 5      $ rz   )r   r   r}   s    r4   r   random_table_frozen.meana  s    zztT**r6   c                 :    U R                   R                  S S XUS9$ )Nr-  )r   r  )ri   r   r.  r   s       r4   r  random_table_frozen.rvsd  s%    zz~~dDt+7  9 	9r6   )r   rV  rK  )
r   r   r   r   rp   r  r  r   r  r   r/   r6   r4   r  r  Q  s    )- =0-+9r6   r  zprow : array_like
    Sum of table entries in each row.
col : array_like
    Sum of table entries in each column.zx : array-like
   Two-dimensional table of non-negative integers, or a
   multi-dimensional array with the last two dimensions
   corresponding with the tables.zThe row and column vectors must be one-dimensional, not empty,
and each sum up to the same value. They cannot contain negative
or noninteger entries.z
Parameters
----------
)r   _doc_row_col_doc_x_doc_mean_params_doc_row_col_note)ra  rc  rd  c                 b    [         R                  " U=(       d    U R                  U5      U l        g rz   )r   r   r   )objdocdicttemplates      r4   _docfillri    s    ""8#:s{{GDCKr6   )r  r  r   r  c                   J   ^  \ rS rSrSrSU 4S jjrS	S jrS rS	S jrSr	U =r
$ )
uniform_direction_geni  a  A vector-valued uniform direction.

Return a random direction (unit vector). The `dim` keyword specifies
the dimensionality of the space.

Methods
-------
rvs(dim=None, size=1, random_state=None)
    Draw random directions.

Parameters
----------
dim : scalar
    Dimension of directions.
seed : {None, int, `numpy.random.Generator`,
        `numpy.random.RandomState`}, 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`.

Notes
-----
This distribution generates unit vectors uniformly distributed on
the surface of a hypersphere. These can be interpreted as random
directions.
For example, if `dim` is 3, 3D vectors from the surface of :math:`S^2`
will be sampled.

References
----------
.. [1] Marsaglia, G. (1972). "Choosing a Point from the Surface of a
       Sphere". Annals of Mathematical Statistics. 43 (2): 645-646.

Examples
--------
>>> import numpy as np
>>> from scipy.stats import uniform_direction
>>> x = uniform_direction.rvs(3)
>>> np.linalg.norm(x)
1.

This generates one random direction, a vector on the surface of
:math:`S^2`.

Alternatively, the object may be called (as a function) to return a frozen
distribution with fixed `dim` parameter. Here,
we create a `uniform_direction` with ``dim=3`` and draw 5 observations.
The samples are then arranged in an array of shape 5x3.

>>> rng = np.random.default_rng()
>>> uniform_sphere_dist = uniform_direction(3)
>>> unit_vectors = uniform_sphere_dist.rvs(5, random_state=rng)
>>> unit_vectors
array([[ 0.56688642, -0.1332634 , -0.81294566],
       [-0.427126  , -0.74779278,  0.50830044],
       [ 0.3793989 ,  0.92346629,  0.05715323],
       [ 0.36428383, -0.92449076, -0.11231259],
       [-0.27733285,  0.94410968, -0.17816678]])
c                 n   > [         TU ]  U5        [        R                  " U R                  5      U l        g rz   r  r   s     r4   rp   uniform_direction_gen.__init__  r  r6   c                     [        XS9$ )zmCreate a frozen n-dimensional uniform direction distribution.

See `uniform_direction` for more information.
rS  )uniform_direction_frozenr  s      r4   r   uniform_direction_gen.__call__  s    
 (77r6   c                     Ub0  [         R                  " U5      (       a  US:  d  U[        U5      :w  a  [        S5      e[        U5      $ )r  r   zMDimension of vector must be specified, and must be an integer greater than 0.r  r  s     r4   r   )uniform_direction_gen._process_parameters  sE    ;bkk#..#'SCH_ F G G 3xr6   c                     U R                  U5      nUc  [        R                  " / [        S9n[        R                  " U5      nU R                  U5      n[        XU5      nU$ )a  Draw random samples from S(N-1).

Parameters
----------
dim : integer
    Dimension of space (N).
size : int or tuple of ints, optional
    Given a shape of, for example, (m,n,k), m*n*k samples are
    generated, and packed in an m-by-n-by-k arrangement.
    Because each sample is N-dimensional, the output shape
    is (m,n,k,N). If no shape is specified, a single (N-D)
    sample is returned.
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional

    Pseudorandom number generator state used to generate resamples.

    If `random_state` is ``None`` (or `np.random`), the
    `numpy.random.RandomState` singleton is used.
    If `random_state` is an int, a new ``RandomState`` instance is
    used, seeded with `random_state`.
    If `random_state` is already a ``Generator`` or ``RandomState``
    instance then that instance is used.

Returns
-------
rvs : ndarray
    Random direction vectors

rK   )r   r?   rL   ry  r&  r   _sample_uniform_direction)ri   r   r   r   r  s        r4   r  uniform_direction_gen.rvs  sX    > --l;<88Bc*D}}T"&&s++C|Dr6   r.  rz   r2  r  r   s   @r4   rk  rk    s"    ?B68' 'r6   rk  c                   (    \ rS rSrSS jrSS jrSrg)ro  i#  Nc                 d    [        U5      U l        U R                  R                  U5      U l        g)a\  Create a frozen n-dimensional uniform direction distribution.

Parameters
----------
dim : int
    Dimension of matrices
seed : {None, int, `numpy.random.Generator`,
        `numpy.random.RandomState`}, optional

    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

Examples
--------
>>> from scipy.stats import uniform_direction
>>> x = uniform_direction(3)
>>> x.rvs()

N)rk  r   r   r   r  s      r4   rp   !uniform_direction_frozen.__init__$  s&    0 +40
::11#6r6   c                 N    U R                   R                  U R                  X5      $ rz   r  rE  s      r4   r  uniform_direction_frozen.rvs?  r  r6   r  r2  r  r/   r6   r4   ro  ro  #  s    76<r6   ro  c                     [         R                  " X5      nUR                  U5      nU[         R                  R	                  USSS9-  nU$ )z
Private method to generate uniform directions
Reference: Marsaglia, G. (1972). "Choosing a Point from the Surface of a
           Sphere". Annals of Mathematical Statistics. 43 (2): 645-646.
r8   T)rt   keepdims)r?   r  r{  rZ   r   )r   r   r   samples_shaper  s        r4   rt  rt  C  sD     IId(M**=9Gryy~~gB~>>GNr6   a"  alpha : array_like
    The concentration parameters. The number of entries along the last axis
    determines the dimensionality of the distribution. Each entry must be
    strictly positive.
n : int or array_like
    The number of trials. Each element must be a strictly positive integer.
)$_dirichlet_mn_doc_default_callparamsr   c                    [         R                  " U 5      n [         R                  " U5      nUbw   [         R                  " X 5      u  p [         R                  " U5      n[         R
                  " US:  5      (       d  [         R
                  " X%:g  5      (       a  [        S5      eUn[         R
                  " U S:*  5      (       a  [        S5      e[         R                  " U5      n[         R
                  " US:*  5      (       d  [         R
                  " X:g  5      (       a  [        S5      eUn[         R                  " U SS9n[         R                  " Xq5      u  pqUc  XU4$ XX4$ ! [         a  nSn[        U5      UeS nAff = f)Nz&`x` and `alpha` must be broadcastable.r   z,`x` must contain only non-negative integers.z*`alpha` must contain only positive values.z`n` must be a positive integer.r8   rs   )r?   rW   r  r]   floorr   re   )r  r   rO   r   rn   x_intn_int	sum_alphas           r4   '_dirichlet_multinomial_check_parametersr  h  s6   JJuE


1A}	)**14HA
 66!a%==BFF1:..KLL	vveqjEFFHHQKE	vva1f~~
++:;;Au2&I&&y4LI$%IEa KEa3KK)  	):CS/q(	)s   E& &
F0E>>Fc                   X   ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
S	 rS
rU =r$ )dirichlet_multinomial_geni  a@  A Dirichlet multinomial random variable.

The Dirichlet multinomial distribution is a compound probability
distribution: it is the multinomial distribution with number of trials
`n` and class probabilities ``p`` randomly sampled from a Dirichlet
distribution with concentration parameters ``alpha``.

Methods
-------
logpmf(x, alpha, n):
    Log of the probability mass function.
pmf(x, alpha, n):
    Probability mass function.
mean(alpha, n):
    Mean of the Dirichlet multinomial distribution.
var(alpha, n):
    Variance of the Dirichlet multinomial distribution.
cov(alpha, n):
    The covariance of the Dirichlet multinomial distribution.

Parameters
----------
%(_dirichlet_mn_doc_default_callparams)s
%(_doc_random_state)s

See Also
--------
scipy.stats.dirichlet : The dirichlet distribution.
scipy.stats.multinomial : The multinomial distribution.

References
----------
.. [1] Dirichlet-multinomial distribution, Wikipedia,
       https://www.wikipedia.org/wiki/Dirichlet-multinomial_distribution

Examples
--------
>>> from scipy.stats import dirichlet_multinomial

Get the PMF

>>> n = 6  # number of trials
>>> alpha = [3, 4, 5]  # concentration parameters
>>> x = [1, 2, 3]  # counts
>>> dirichlet_multinomial.pmf(x, alpha, n)
0.08484162895927604

If the sum of category counts does not equal the number of trials,
the probability mass is zero.

>>> dirichlet_multinomial.pmf(x, alpha, n=7)
0.0

Get the log of the PMF

>>> dirichlet_multinomial.logpmf(x, alpha, n)
-2.4669689491013327

Get the mean

>>> dirichlet_multinomial.mean(alpha, n)
array([1.5, 2. , 2.5])

Get the variance

>>> dirichlet_multinomial.var(alpha, n)
array([1.55769231, 1.84615385, 2.01923077])

Get the covariance

>>> dirichlet_multinomial.cov(alpha, n)
array([[ 1.55769231, -0.69230769, -0.86538462],
       [-0.69230769,  1.84615385, -1.15384615],
       [-0.86538462, -1.15384615,  2.01923077]])

Alternatively, the object may be called (as a function) to fix the
`alpha` and `n` parameters, returning a "frozen" Dirichlet multinomial
random variable.

>>> dm = dirichlet_multinomial(alpha, n)
>>> dm.pmf(x)
0.08484162895927579

All methods are fully vectorized. Each element of `x` and `alpha` is
a vector (along the last axis), each element of `n` is an
integer (scalar), and the result is computed element-wise.

>>> x = [[1, 2, 3], [4, 5, 6]]
>>> alpha = [[1, 2, 3], [4, 5, 6]]
>>> n = [6, 15]
>>> dirichlet_multinomial.pmf(x, alpha, n)
array([0.06493506, 0.02626937])

>>> dirichlet_multinomial.cov(alpha, n).shape  # both covariance matrices
(2, 3, 3)

Broadcasting according to standard NumPy conventions is supported. Here,
we have four sets of concentration parameters (each a two element vector)
for each of three numbers of trials (each a scalar).

>>> alpha = [[3, 4], [4, 5], [5, 6], [6, 7]]
>>> n = [[6], [7], [8]]
>>> dirichlet_multinomial.mean(alpha, n).shape
(3, 4, 2)

c                 x   > [         TU ]  U5        [        R                  " U R                  [
        5      U l        g rz   )r   rp   r   r   r   dirichlet_mn_docdict_paramsr   s     r4   rp   "dirichlet_multinomial_gen.__init__  s,    ''(CEr6   c                     [        XUS9$ r  )dirichlet_multinomial_frozen)ri   r  r   r   s       r4   r   "dirichlet_multinomial_gen.__call__  s    +E4@@r6   c                 ~   [        X#U5      u  pEp1[        R                  " [        U5      [        US-   5      -   [        X5-   5      -
  5      nU[        X-   5      [        U5      [        US-   5      -   -
  R	                  SS9-  n[        R
                  " XcUR	                  SS9:g  [        R                  * 5        US   $ )a{  The log of the probability mass function.

Parameters
----------
x: ndarray
    Category counts (non-negative integers). Must be broadcastable
    with shape parameter ``alpha``. If multidimensional, the last axis
    must correspond with the categories.
%(_dirichlet_mn_doc_default_callparams)s

Returns
-------
out: ndarray or scalar
    Log of the probability mass function.

r   r8   rs   r/   )r  r?   rW   r   re   placer   )ri   rO   r  r   r
  Sar3   s          r4   r   dirichlet_multinomial_gen.logpmf  s    $ >eJqjj"Q7(16:JJK8A;!a%#@AFFBFOO
155b5>)BFF732wr6   c                 N    [         R                  " U R                  XU5      5      $ )a  Probability mass function for a Dirichlet multinomial distribution.

Parameters
----------
x: ndarray
    Category counts (non-negative integers). Must be broadcastable
    with shape parameter ``alpha``. If multidimensional, the last axis
    must correspond with the categories.
%(_dirichlet_mn_doc_default_callparams)s

Returns
-------
out: ndarray or scalar
    Probability mass function.

r  )ri   rO   r  r   s       r4   r  dirichlet_multinomial_gen.pmf  s    " vvdkk!A.//r6   c                 ~    [        X5      u  p4nUS[        R                  4   US[        R                  4   pBX#-  U-  $ )zMean of a Dirichlet multinomial distribution.

Parameters
----------
%(_dirichlet_mn_doc_default_callparams)s

Returns
-------
out: ndarray
    Mean of a Dirichlet multinomial distribution.

.r  r?   r   ri   r  r   r
  r  s        r4   r   dirichlet_multinomial_gen.mean(  s?     ;5Dq#rzz/"BsBJJ$72urzr6   c                     [        X5      u  p4nUS[        R                  4   US[        R                  4   pBX#-  U-  SX4-  -
  -  X$-   -  SU-   -  $ )a  The variance of the Dirichlet multinomial distribution.

Parameters
----------
%(_dirichlet_mn_doc_default_callparams)s

Returns
-------
out: array_like
    The variances of the components of the distribution. This is
    the diagonal of the covariance matrix of the distribution.

.r   r  r  s        r4   r  dirichlet_multinomial_gen.var9  sZ     ;5Dq#rzz/"BsBJJ$72urzQX&!&1QV<<r6   c                    [        X5      u  p4n[        R                  X25      nUS[        R                  [        R                  4   US[        R                  [        R                  4   pBUSSS2[        R                  4   US[        R                  SS24   -  nU* U-  US-  -  X$-   -  SU-   -  n[        R
                  " UR                  S   5      nXWSX4'   U$ )zCovariance matrix of a Dirichlet multinomial distribution.

Parameters
----------
%(_dirichlet_mn_doc_default_callparams)s

Returns
-------
out : array_like
    The covariance matrix of the distribution.

.Nr-   r   r8   )r  r   r  r?   r   r  r   )	ri   r  r   r
  r  r  aiajr   iis	            r4   r   dirichlet_multinomial_gen.covK  s     ;5Dq#''-#rzz2::-.3

BJJ3N0O2a#$qbjj!);'<<b4i"'!QV,B7YYsyy}%CK
r6   r.  rz   )r   r   r   r   r   rp   r   r  r  r   r  r   r   r   r   s   @r4   r  r    s4    iTE
A20&"=$ r6   r  c                   <    \ rS rSrS
S jrS rS rS rS rS r	S	r
g)r  ig  Nc                 X    [        X5      u  pnXl        X l        [        U5      U l        g rz   )r  r  r   r  r   )ri   r  r   r   r  s        r4   rp   %dirichlet_multinomial_frozen.__init__h  s&    >uH1
.t4
r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r  r   r=  s     r4   r  #dirichlet_multinomial_frozen.logpmfn  s!    zz  JJ77r6   c                 b    U R                   R                  XR                  U R                  5      $ rz   )r   r  r  r   r=  s     r4   r   dirichlet_multinomial_frozen.pmfq  s    zz~~aTVV44r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r  r   r}   s    r4   r   !dirichlet_multinomial_frozen.meant  s    zztzz46622r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r  r  r   r}   s    r4   r   dirichlet_multinomial_frozen.varw      zz~~djj$&&11r6   c                 b    U R                   R                  U R                  U R                  5      $ rz   )r   r   r  r   r}   s    r4   r    dirichlet_multinomial_frozen.covz  r  r6   )r   r  r   rz   )r   r   r   r   rp   r  r  r   r  r   r   r/   r6   r4   r  r  g  s     585322r6   r  )r  r  r   r  r   c                      ^  \ rS rSrSrSU 4S jjrSS jrS rS rS r	S r
SS	 jrSS
 jrS rS rS rS rS rSS jrS rSS jrS rSrU =r$ )vonmises_fisher_geni  a0!  A von Mises-Fisher variable.

The `mu` keyword specifies the mean direction vector. The `kappa` keyword
specifies the concentration parameter.

Methods
-------
pdf(x, mu=None, kappa=1)
    Probability density function.
logpdf(x, mu=None, kappa=1)
    Log of the probability density function.
rvs(mu=None, kappa=1, size=1, random_state=None)
    Draw random samples from a von Mises-Fisher distribution.
entropy(mu=None, kappa=1)
    Compute the differential entropy of the von Mises-Fisher distribution.
fit(data)
    Fit a von Mises-Fisher distribution to data.

Parameters
----------
mu : array_like
    Mean direction of the distribution. Must be a one-dimensional unit
    vector of norm 1.
kappa : float
    Concentration parameter. Must be positive.
seed : {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`.

See Also
--------
scipy.stats.vonmises : Von-Mises Fisher distribution in 2D on a circle
uniform_direction : uniform distribution on the surface of a hypersphere

Notes
-----
The von Mises-Fisher distribution is a directional distribution on the
surface of the unit hypersphere. The probability density
function of a unit vector :math:`\mathbf{x}` is

.. math::

    f(\mathbf{x}) = \frac{\kappa^{d/2-1}}{(2\pi)^{d/2}I_{d/2-1}(\kappa)}
           \exp\left(\kappa \mathbf{\mu}^T\mathbf{x}\right),

where :math:`\mathbf{\mu}` is the mean direction, :math:`\kappa` the
concentration parameter, :math:`d` the dimension and :math:`I` the
modified Bessel function of the first kind. As :math:`\mu` represents
a direction, it must be a unit vector or in other words, a point
on the hypersphere: :math:`\mathbf{\mu}\in S^{d-1}`. :math:`\kappa` is a
concentration parameter, which means that it must be positive
(:math:`\kappa>0`) and that the distribution becomes more narrow with
increasing :math:`\kappa`. In that sense, the reciprocal value
:math:`1/\kappa` resembles the variance parameter of the normal
distribution.

The von Mises-Fisher distribution often serves as an analogue of the
normal distribution on the sphere. Intuitively, for unit vectors, a
useful distance measure is given by the angle :math:`\alpha` between
them. This is exactly what the scalar product
:math:`\mathbf{\mu}^T\mathbf{x}=\cos(\alpha)` in the
von Mises-Fisher probability density function describes: the angle
between the mean direction :math:`\mathbf{\mu}` and the vector
:math:`\mathbf{x}`. The larger the angle between them, the smaller the
probability to observe :math:`\mathbf{x}` for this particular mean
direction :math:`\mathbf{\mu}`.

In dimensions 2 and 3, specialized algorithms are used for fast sampling
[2]_, [3]_. For dimensions of 4 or higher the rejection sampling algorithm
described in [4]_ is utilized. This implementation is partially based on
the geomstats package [5]_, [6]_.

.. versionadded:: 1.11

References
----------
.. [1] Von Mises-Fisher distribution, Wikipedia,
       https://en.wikipedia.org/wiki/Von_Mises%E2%80%93Fisher_distribution
.. [2] Mardia, K., and Jupp, P. Directional statistics. Wiley, 2000.
.. [3] J. Wenzel. Numerically stable sampling of the von Mises Fisher
       distribution on S2.
       https://www.mitsuba-renderer.org/~wenzel/files/vmf.pdf
.. [4] Wood, A. Simulation of the von mises fisher distribution.
       Communications in statistics-simulation and computation 23,
       1 (1994), 157-164. https://doi.org/10.1080/03610919408813161
.. [5] geomstats, Github. MIT License. Accessed: 06.01.2023.
       https://github.com/geomstats/geomstats
.. [6] Miolane, N. et al. Geomstats:  A Python Package for Riemannian
       Geometry in Machine Learning. Journal of Machine Learning Research
       21 (2020). http://jmlr.org/papers/v21/19-027.html

Examples
--------
**Visualization of the probability density**

Plot the probability density in three dimensions for increasing
concentration parameter. The density is calculated by the ``pdf``
method.

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.stats import vonmises_fisher
>>> from matplotlib.colors import Normalize
>>> n_grid = 100
>>> u = np.linspace(0, np.pi, n_grid)
>>> v = np.linspace(0, 2 * np.pi, n_grid)
>>> u_grid, v_grid = np.meshgrid(u, v)
>>> vertices = np.stack([np.cos(v_grid) * np.sin(u_grid),
...                      np.sin(v_grid) * np.sin(u_grid),
...                      np.cos(u_grid)],
...                     axis=2)
>>> x = np.outer(np.cos(v), np.sin(u))
>>> y = np.outer(np.sin(v), np.sin(u))
>>> z = np.outer(np.ones_like(u), np.cos(u))
>>> def plot_vmf_density(ax, x, y, z, vertices, mu, kappa):
...     vmf = vonmises_fisher(mu, kappa)
...     pdf_values = vmf.pdf(vertices)
...     pdfnorm = Normalize(vmin=pdf_values.min(), vmax=pdf_values.max())
...     ax.plot_surface(x, y, z, rstride=1, cstride=1,
...                     facecolors=plt.cm.viridis(pdfnorm(pdf_values)),
...                     linewidth=0)
...     ax.set_aspect('equal')
...     ax.view_init(azim=-130, elev=0)
...     ax.axis('off')
...     ax.set_title(rf"$\kappa={kappa}$")
>>> fig, axes = plt.subplots(nrows=1, ncols=3, figsize=(9, 4),
...                          subplot_kw={"projection": "3d"})
>>> left, middle, right = axes
>>> mu = np.array([-np.sqrt(0.5), -np.sqrt(0.5), 0])
>>> plot_vmf_density(left, x, y, z, vertices, mu, 5)
>>> plot_vmf_density(middle, x, y, z, vertices, mu, 20)
>>> plot_vmf_density(right, x, y, z, vertices, mu, 100)
>>> plt.subplots_adjust(top=1, bottom=0.0, left=0.0, right=1.0, wspace=0.)
>>> plt.show()

As we increase the concentration parameter, the points are getting more
clustered together around the mean direction.

**Sampling**

Draw 5 samples from the distribution using the ``rvs`` method resulting
in a 5x3 array.

>>> rng = np.random.default_rng()
>>> mu = np.array([0, 0, 1])
>>> samples = vonmises_fisher(mu, 20).rvs(5, random_state=rng)
>>> samples
array([[ 0.3884594 , -0.32482588,  0.86231516],
       [ 0.00611366, -0.09878289,  0.99509023],
       [-0.04154772, -0.01637135,  0.99900239],
       [-0.14613735,  0.12553507,  0.98126695],
       [-0.04429884, -0.23474054,  0.97104814]])

These samples are unit vectors on the sphere :math:`S^2`. To verify,
let us calculate their euclidean norms:

>>> np.linalg.norm(samples, axis=1)
array([1., 1., 1., 1., 1.])

Plot 20 observations drawn from the von Mises-Fisher distribution for
increasing concentration parameter :math:`\kappa`. The red dot highlights
the mean direction :math:`\mu`.

>>> def plot_vmf_samples(ax, x, y, z, mu, kappa):
...     vmf = vonmises_fisher(mu, kappa)
...     samples = vmf.rvs(20)
...     ax.plot_surface(x, y, z, rstride=1, cstride=1, linewidth=0,
...                     alpha=0.2)
...     ax.scatter(samples[:, 0], samples[:, 1], samples[:, 2], c='k', s=5)
...     ax.scatter(mu[0], mu[1], mu[2], c='r', s=30)
...     ax.set_aspect('equal')
...     ax.view_init(azim=-130, elev=0)
...     ax.axis('off')
...     ax.set_title(rf"$\kappa={kappa}$")
>>> mu = np.array([-np.sqrt(0.5), -np.sqrt(0.5), 0])
>>> fig, axes = plt.subplots(nrows=1, ncols=3,
...                          subplot_kw={"projection": "3d"},
...                          figsize=(9, 4))
>>> left, middle, right = axes
>>> plot_vmf_samples(left, x, y, z, mu, 5)
>>> plot_vmf_samples(middle, x, y, z, mu, 20)
>>> plot_vmf_samples(right, x, y, z, mu, 100)
>>> plt.subplots_adjust(top=1, bottom=0.0, left=0.0,
...                     right=1.0, wspace=0.)
>>> plt.show()

The plots show that with increasing concentration :math:`\kappa` the
resulting samples are centered more closely around the mean direction.

**Fitting the distribution parameters**

The distribution can be fitted to data using the ``fit`` method returning
the estimated parameters. As a toy example let's fit the distribution to
samples drawn from a known von Mises-Fisher distribution.

>>> mu, kappa = np.array([0, 0, 1]), 20
>>> samples = vonmises_fisher(mu, kappa).rvs(1000, random_state=rng)
>>> mu_fit, kappa_fit = vonmises_fisher.fit(samples)
>>> mu_fit, kappa_fit
(array([0.01126519, 0.01044501, 0.99988199]), 19.306398751730995)

We see that the estimated parameters `mu_fit` and `kappa_fit` are
very close to the ground truth parameters.

c                 $   > [         TU ]  U5        g rz   r  r   s     r4   rp   vonmises_fisher_gen.__init__\  r  r6   c                     [        XUS9$ )zcCreate a frozen von Mises-Fisher distribution.

See `vonmises_fisher_frozen` for more information.
rS  )vonmises_fisher_frozenri   r  kappar   s       r4   r   vonmises_fisher_gen.__call___  s    
 &bd;;r6   c                    [         R                  " U5      nUR                  S:  a  [        S5      e[         R                  " [         R
                  R                  U5      S5      (       d  [        S5      eUR                  S:  d  [        S5      eSn[         R                  " U5      (       a  US:  a  [        U5      e[        U5      S:X  a  [        S	5      eUR                  nXAU4$ )
zf
Infer dimensionality from mu and ensure that mu is a one-dimensional
unit vector and kappa positive.
r   z%'mu' must have one-dimensional shape.r   z%'mu' must be a unit vector of norm 1.z$'mu' must have at least two entries.z"'kappa' must be a positive scalar.r   r   zFor 'kappa=0' the von Mises-Fisher distribution becomes the uniform distribution on the sphere surface. Consider using 'scipy.stats.uniform_direction' instead.)
r?   rW   r1   r]   allcloserZ   r   r   r   rM   )ri   r  r  kappa_error_msgr   s        r4   r   'vonmises_fisher_gen._process_parametersf  s    
 ZZ^77Q;DEE{{299>>"-r22DEEww{CDD>{{5!!UQY_--<2 H I I gg~r6   c                     UR                   S   U:w  a  [        S5      e[        R                  " [        R                  R                  USS9S5      (       d  Sn[        U5      eg )Nr8   znThe dimensionality of the last axis of 'x' must match the dimensionality of the von Mises Fisher distribution.rs   r   8'x' must be unit vectors of norm 1 along last dimension.)r   r]   r?   r  rZ   r   )ri   rO   r   rn   s       r4   _check_data_vs_dist'vonmises_fisher_gen._check_data_vs_dist~  s\    772;# > ? ? {{299>>!">5r::LCS/! ;r6   c                     SU-  nSUS-
  -  [         R                  " U5      -  U[        -  -
  [         R                  " [        US-
  U5      5      -
  U-
  $ Nr"  r-   r   )r?   rf   r   r
   ri   r   r  halfdims       r4   _log_norm_factor$vonmises_fisher_gen._log_norm_factor  sX     )sQwu-(0BBs7Q;./0278 	9r6   c                     [         R                  " U5      nU R                  X5        [         R                  " SX15      nU R	                  X$5      XE-  -   $ )zLog of the von Mises-Fisher probability density function.

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

zi,...i->...)r?   rW   r  r}  r  )ri   rO   r   r  r  dotproductss         r4   r   vonmises_fisher_gen._logpdf  sH     JJqM  (iir5$$S053FFFr6   c                 N    U R                  X#5      u  pBnU R                  XX#5      $ )aJ  Log of the von Mises-Fisher probability density function.

Parameters
----------
x : array_like
    Points at which to evaluate the log of the probability
    density function. The last axis of `x` must correspond
    to unit vectors of the same dimensionality as the distribution.
mu : array_like, default: None
    Mean direction of the distribution. Must be a one-dimensional unit
    vector of norm 1.
kappa : float, default: 1
    Concentration parameter. Must be positive.

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

)r   r   ri   rO   r  r  r   s        r4   r   vonmises_fisher_gen.logpdf  s)    * 11"<||AB..r6   c                 v    U R                  X#5      u  pBn[        R                  " U R                  XX#5      5      $ )a  Von Mises-Fisher probability density function.

Parameters
----------
x : array_like
    Points at which to evaluate the probability
    density function. The last axis of `x` must correspond
    to unit vectors of the same dimensionality as the distribution.
mu : array_like
    Mean direction of the distribution. Must be a one-dimensional unit
    vector of norm 1.
kappa : float
    Concentration parameter. Must be positive.

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

)r   r?   r   r   r  s        r4   r   vonmises_fisher_gen.pdf  s2    * 11"<vvdll12566r6   c                     [         R                  " US   US   5      nUR                  XRUS9n[         R                  " [         R                  " U5      [         R
                  " U5      /SS9nU$ )z
In 2D, the von Mises-Fisher distribution reduces to the
von Mises distribution which can be efficiently sampled by numpy.
This method is much faster than the general rejection
sampling based algorithm.

r   r   r  r8   rs   )r?   arctan2vonmisesstackcossin)ri   r  r  r   r   
mean_angleangle_samplesr  s           r4   _rvs_2dvonmises_fisher_gen._rvs_2d  s`     ZZ1r!u-
$--jd-K((BFF=1266-3HI "$r6   c           	         Uc  SnOUnUR                  U5      nS[        R                  " USU-
  [        R                  " SU-  5      -  -   5      U-  -   n[        R                  " S[        R
                  " U5      -
  5      n[        SXC5      n[        R                  " XVUS   -  XgS   -  /SS9nUc  [        R                  " U5      nU$ )	a0  
Generate samples from a von Mises-Fisher distribution
with mu = [1, 0, 0] and kappa. Samples then have to be
rotated towards the desired mean direction mu.
This method is much faster than the general rejection
sampling based algorithm.
Reference: https://www.mitsuba-renderer.org/~wenzel/files/vmf.pdf

r   r   rc  r-   r  ).r   r8   rs   )	randomr?   rf   r   ra   r   rt  r  r0   )	ri   r  r   r   sample_sizerO   tempuniformcircler  s	            r4   _rvs_3dvonmises_fisher_gen._rvs_3d  s     <KK ,R!Vrvvb5j'999:5@@ wwrBIIaL()1![O((AmF&;; #88: "$ <jj)Gr6   c                    US-
  nUb5  [         R                  " U5      (       d  U4n[        R                  " U5      nOSn[         R                  " SUS-  -  US-  -   5      nSU-  U-   U-  nUS:X  a  US-  US-  -  US-  S	-  US
-  -  -
  nSU-
  SU-   -  n	X)-  U[         R
                  " S5      [         R
                  " U5      -   S[         R                  " U5      -  -
  -  -   n
Sn[         R                  " U45      nSU-  nX:  a  UR                  XXk-
  S9nSSU-   U-  -
  SSU-
  U-  -
  -  nUR                  Xk-
  5      nX/-  U[         R
                  " SU-   U-
  X-  -   SU-   -  5      -  -   U
-
  [         R
                  " U5      :  n[         R                  " U5      nUU   XUU-   & UU-  nX:  a  M  [        X[U5      n[         R                  " S[         R                  " SUS-  -
  5      U5      n[         R                  " US   U/SS9nUb  UR                  X14-   5      nU$ [         R                  " U5      nU$ )z
Generate samples from a n-dimensional von Mises-Fisher distribution
with mu = [1, 0, ..., 0] and kappa via rejection sampling.
Samples then have to be rotated towards the desired mean direction mu.
Reference: https://doi.org/10.1080/03610919408813161
r   r  r  r-   rc  r   g      r  @   r  r   r"  r  z...,...i->...ir	  rs   )r?   r  rH  r  ra   rf   log1pr   betar  re   rt  r}  r  r   r0   )ri   r   r  r   r   dim_minus_one	n_samplesra   envelop_paramnode
correction
n_acceptedrO   r  sym_betacoord_x
accept_tol	criterionaccepted_iter
coord_restr  s                        r4   _rejection_sampling'vonmises_fisher_gen._rejection_sampling  s    a;;t$$x		$IIwwq5B;!);;<ed*m;A +1_ucz9,a/2UCZ?@M ]"rM'9: l]RVVM%::BHH]334&5 5
 
HHi]#%$#((.7.D ) FHA-99Q&(224G &,,Y-CDJ2661}+<w+F),*./-.?+A $B CC  !#z 2	3I
 FF9-M7>y7IAm34-'J% $( /}/;=
YYbgga!q&j1:?
..!I,
!;!DoodWn5G  jj)Gr6   c                    [         R                  " U45      nSUS'   [         R                  " USSS24   [         R                  " US-
  U45      /5      n[         R                  R	                  [         R
                  " U5      5      u  pg[         R                  " [         R                  " XdSS2S4   5      SS2S4   U5      (       a  SnOSn[         R                  " SXa5      U-  nU$ )aC  A QR decomposition is used to find the rotation that maps the
north pole (1, 0,...,0) to the vector mu. This rotation is then
applied to all samples.

Parameters
----------
samples: array_like, shape = [..., n]
mu : array-like, shape=[n, ]
    Point to parametrise the rotation.

Returns
-------
samples : rotated samples

r   r   Nr   r8   zij,...j->...i)	r?   r   r  rZ   r/  r|  r  r
  r}  )	ri   r  r  r   
base_pointembedded	rotmatrixr  rotsigns	            r4   _rotate_samples#vonmises_fisher_gen._rotate_samplesE  s      XXsg&

1>>2dAg;#'30H"IJyy||BLL$:;	;;ryyq$w,?@AFKKGG ))OY@7Jr6   c                     US:X  a  U R                  X#XE5      nO,US:X  a  U R                  X4U5      nOU R                  XUU5      nUS:w  a  U R                  XbU5      nU$ )Nr-   r  )r  r  r  r  )ri   r   r  r  r   r   r  s          r4   r:  vonmises_fisher_gen._rvsb  sg    !8ll2dAGAXll5=G..s4/;=G !8**7<Gr6   c                 v    U R                  X5      u  pQnU R                  U5      nU R                  XQX#U5      nU$ )aH  Draw random samples from a von Mises-Fisher distribution.

Parameters
----------
mu : array_like
    Mean direction of the distribution. Must be a one-dimensional unit
    vector of norm 1.
kappa : float
    Concentration parameter. Must be positive.
size : int or tuple of ints, optional
    Given a shape of, for example, (m,n,k), m*n*k samples are
    generated, and packed in an m-by-n-by-k arrangement.
    Because each sample is N-dimensional, the output shape
    is (m,n,k,N). If no shape is specified, a single (N-D)
    sample is returned.
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`.

Returns
-------
rvs : ndarray
    Random variates of shape (`size`, `N`), where `N` is the
    dimension of the distribution.

)r   r   r:  )ri   r  r  r   r   r   r  s          r4   r  vonmises_fisher_gen.rvso  s@    B 11"<--l;))CU,?r6   c                 n    SU-  nU R                  X5      * U[        X25      -  [        US-
  U5      -  -
  $ r  )r  r
   r  s       r4   r  vonmises_fisher_gen._entropy  sH    )&&s22UG#6$&)'A+u&=6> > 	?r6   c                 L    U R                  X5      u  p4nU R                  X25      $ )ar  Compute the differential entropy of the von Mises-Fisher
distribution.

Parameters
----------
mu : array_like, default: None
    Mean direction of the distribution. Must be a one-dimensional unit
    vector of norm 1.
kappa : float, default: 1
    Concentration parameter. Must be positive.

Returns
-------
h : scalar
    Entropy of the von Mises-Fisher distribution.

r  )ri   r  r  r   r  s        r4   r#  vonmises_fisher_gen.entropy  s'    $ 00;}}S((r6   c                   ^	^
 [         R                  " U5      nUR                  S:w  a  [        S5      e[         R                  " [         R
                  R                  USS9S5      (       d  Sn[        U5      eUR                  S   n[        U5      nUR                  nUR                  m
SU-  m	U	U
4S jn[        US	S
S9nUR                  nXX4$ )a  Fit the von Mises-Fisher distribution to data.

Parameters
----------
x : array-like
    Data the distribution is fitted to. Must be two dimensional.
    The second axis of `x` must be unit vectors of norm 1 and
    determine the dimensionality of the fitted
    von Mises-Fisher distribution.

Returns
-------
mu : ndarray
    Estimated mean direction.
kappa : float
    Estimated concentration parameter.

r-   z'x' must be two dimensional.r8   rs   r   r  r"  c                 B   > [        TTS-
  /U 5      nUS   US   -  T-
  $ )Nr   r   )r
   )r  bessel_valsr  r3  s     r4   solve_for_kappa0vonmises_fisher_gen.fit.<locals>.solve_for_kappa  s0    w!4e<Kq>+a.0144r6   brentq)g:0yE>g    eA)r.  bracket)r?   rW   r1   r]   r  rZ   r   r   r   mean_directionmean_resultant_lengthr   root)ri   rO   rn   r   dirstatsr  r  root_resr  r  r3  s            @@r4   r,  vonmises_fisher_gen.fit  s    ( JJqM66Q;;<<{{299>>!">5r::LCS/!ggbk %Q'$$** )	5 x'24yr6   r/   rz   Nr   Nr1  r0  )r   r   r   r   r   rp   r   r   r  r  r   r   r   r  r  r  r  r:  r  r  r#  r,  r   r   r   s   @r4   r  r    sh    Qd<0"9
G/070<FP:$L?
)*/ /r6   r  c                   :    \ rS rSrS	S jrS rS rS
S jrS rSr	g)r  i  Nc                     [        U5      U l        U R                  R                  X5      u  U l        U l        U l        g)aN  Create a frozen von Mises-Fisher distribution.

Parameters
----------
mu : array_like, default: None
    Mean direction of the distribution.
kappa : float, default: 1
    Concentration parameter. Must be positive.
seed : {None, int, `numpy.random.Generator`,
        `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

N)r  r   r   r   r  r  r  s       r4   rp   vonmises_fisher_frozen.__init__  s3    & ).
JJ**25 	&$'4:r6   c                 x    U R                   R                  XR                  U R                  U R                  5      $ )aG  
Parameters
----------
x : array_like
    Points at which to evaluate the log of the probability
    density function. The last axis of `x` must correspond
    to unit vectors of the same dimensionality as the distribution.

Returns
-------
logpdf : ndarray or scalar
    Log of probability density function evaluated at `x`.

)r   r   r   r  r  r=  s     r4   r   vonmises_fisher_frozen.logpdf  s)     zz!!!XXtww

CCr6   c                 L    [         R                  " U R                  U5      5      $ )a=  
Parameters
----------
x : array_like
    Points at which to evaluate the log of the probability
    density function. The last axis of `x` must correspond
    to unit vectors of the same dimensionality as the distribution.

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

r<  r=  s     r4   r   vonmises_fisher_frozen.pdf  s     vvdkk!n%%r6   c                     U R                   R                  U5      nU R                   R                  U R                  U R                  U R
                  UU5      $ )a  Draw random variates from the Von Mises-Fisher distribution.

Parameters
----------
size : int or tuple of ints, optional
    Given a shape of, for example, (m,n,k), m*n*k samples are
    generated, and packed in an m-by-n-by-k arrangement.
    Because each sample is N-dimensional, the output shape
    is (m,n,k,N). If no shape is specified, a single (N-D)
    sample is returned.
random_state : {None, int, `numpy.random.Generator`,
                `numpy.random.RandomState`}, optional
    If `seed` is None (or `np.random`), the `numpy.random.RandomState`
    singleton is used.
    If `seed` is an int, a new ``RandomState`` instance is used,
    seeded with `seed`.
    If `seed` is already a ``Generator`` or ``RandomState`` instance
    then that instance is used.

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

)r   r   r:  r   r  r  rE  s      r4   r  vonmises_fisher_frozen.rvs  sD    6 zz33LAzztxx$**d+- 	-r6   c                 b    U R                   R                  U R                  U R                  5      $ )z
Calculate the differential entropy of the von Mises-Fisher
distribution.

Returns
-------
h: float
    Entropy of the Von Mises-Fisher distribution.

)r   r  r   r  r}   s    r4   r#  vonmises_fisher_frozen.entropy>  s#     zz""488TZZ88r6   )r   r   r  r  r	  rI  )
r   r   r   r   rp   r   r   r  r#  r   r/   r6   r4   r  r    s    
0D"&"->9r6   r  c                   l    \ rS rSrSrSS jrS rSS jrS rSS jr	SS	 jr
SS
 jrS rS rSS jrSrg)normal_inverse_gamma_geniL  a  Normal-inverse-gamma distribution.

The normal-inverse-gamma distribution is the conjugate prior of a normal
distribution with unknown mean and variance.

Methods
-------
pdf(x, s2, mu=0, lmbda=1, a=1, b=1)
    Probability density function.
logpdf(x, s2, mu=0, lmbda=1, a=1, b=1)
    Log of the probability density function.
mean(mu=0, lmbda=1, a=1, b=1)
    Distribution mean.
var(mu=0, lmbda=1, a=1, b=1)
    Distribution variance.
rvs(mu=0, lmbda=1, a=1, b=1, size=None, random_state=None)
    Draw random samples.

Parameters
----------
mu, lmbda, a, b  : array_like
    Shape parameters of the distribution. See notes.
seed : {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`.

See Also
--------
norm
invgamma

Notes
-----

The probability density function of `normal_inverse_gamma` is:

.. math::

    f(x, \sigma^2; \mu, \lambda, \alpha, \beta) =
        \frac{\sqrt{\lambda}}{\sqrt{2 \pi \sigma^2}}
        \frac{\beta^\alpha}{\Gamma(\alpha)}
        \left( \frac{1}{\sigma^2} \right)^{\alpha + 1}
        \exp \left(- \frac{2 \beta + \lambda (x - \mu)^2} {2 \sigma^2} \right)

where all parameters are real and finite, and :math:`\sigma^2 > 0`,
:math:`\lambda > 0`, :math:`\alpha > 0`, and :math:`\beta > 0`.

Methods ``normal_inverse_gamma.pdf`` and ``normal_inverse_gamma.logpdf``
accept `x` and `s2` for arguments :math:`x` and :math:`\sigma^2`.
All methods accept `mu`, `lmbda`, `a`, and `b` for shape parameters
:math:`\mu`, :math:`\lambda`, :math:`\alpha`, and :math:`\beta`,
respectively.

.. versionadded:: 1.15

References
----------
.. [1] Normal-inverse-gamma distribution, Wikipedia,
       https://en.wikipedia.org/wiki/Normal-inverse-gamma_distribution

Examples
--------
Suppose we wish to investigate the relationship between the
normal-inverse-gamma distribution and the inverse gamma distribution.

>>> import numpy as np
>>> from scipy import stats
>>> import matplotlib.pyplot as plt
>>> rng = np.random.default_rng(527484872345)
>>> mu, lmbda, a, b = 0, 1, 20, 20
>>> norm_inv_gamma = stats.normal_inverse_gamma(mu, lmbda, a, b)
>>> inv_gamma = stats.invgamma(a, scale=b)

One approach is to compare the distribution of the `s2` elements of
random variates against the PDF of an inverse gamma distribution.

>>> _, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng)
>>> bins = np.linspace(s2.min(), s2.max(), 50)
>>> plt.hist(s2, bins=bins, density=True, label='Frequency density')
>>> s2 = np.linspace(s2.min(), s2.max(), 300)
>>> plt.plot(s2, inv_gamma.pdf(s2), label='PDF')
>>> plt.xlabel(r'$\sigma^2$')
>>> plt.ylabel('Frequency density / PMF')
>>> plt.show()

Similarly, we can compare the marginal distribution of `s2` against
an inverse gamma distribution.

>>> from scipy.integrate import quad_vec
>>> from scipy import integrate
>>> s2 = np.linspace(0.5, 3, 6)
>>> res = quad_vec(lambda x: norm_inv_gamma.pdf(x, s2), -np.inf, np.inf)[0]
>>> np.allclose(res, inv_gamma.pdf(s2))
True

The sample mean is comparable to the mean of the distribution.

>>> x, s2 = norm_inv_gamma.rvs(size=10000, random_state=rng)
>>> x.mean(), s2.mean()
(np.float64(-0.005254750127304425), np.float64(1.050438111436508))
>>> norm_inv_gamma.mean()
(np.float64(0.0), np.float64(1.0526315789473684))

Similarly, for the variance:

>>> x.var(ddof=1), s2.var(ddof=1)
(np.float64(1.0546150578185023), np.float64(0.061829865266330754))
>>> norm_inv_gamma.var()
(np.float64(1.0526315789473684), np.float64(0.061557402277623886))

Nc                     U R                  U5      n[        X4S9R                  XVS9nXr-  S-  n[        XS9R                  XVS9n	[        R
                  " SXX45      n
U	R                  U
5      UR                  U
5      4$ )a  Draw random samples from the distribution.

Parameters
----------
mu, lmbda, a, b : array_like, optional
    Shape parameters. `lmbda`, `a`, and `b` must be greater
    than zero.
size : int or tuple of ints, optional
    Shape of samples to draw.
random_state : {None, int, np.random.RandomState, np.random.Generator}, optional
    Used for drawing random variates.
    If `random_state` is `None`, the `~np.random.RandomState` singleton is used.
    If `random_state` is an int, a new ``RandomState`` instance is used, seeded
    with `random_state`.
    If `random_state` is already a ``RandomState`` or ``Generator`` instance,
    then that object is used.
    Default is `None`.

Returns
-------
x, s2 : ndarray
    Random variates.

)r  r  r"  )r  r  r   )r   r   r  r   r?   result_typer  )ri   r  lmbdar
  r	  r   r   s2r  rO   r<   s              r4   r  normal_inverse_gamma_gen.rvs  s~    2 --l;a!%%4%Kc!R%))t)OsBq4xx		% 000r6   c                    S[         R                  " U5      [         R                  " S[         R                  -  U-  5      -
  -  nU[         R                  " U5      -  [        R                  " U5      R                  UR                  5      -
  nUS-   * [         R                  " U5      -  n	SU-  XAU-
  S-  -  -   * SU-  -  n
Xx-   U	-   U
-   $ r  )r?   rf   r  r   r   r  r<   ri   rO   r  r  r  r
  r	  t1t2t3t4s              r4   r    normal_inverse_gamma_gen._logpdf  s    BFF5MBFF1ruu9r>$::;rvvay[7??1-44QWW==1uXr
"sUFQ;&&'1R40w|b  r6   c                 4   U R                  XX4XV5      u  pxUS   n[        R                  " SS9   [        R                  " U R                  " U6 5      n	SSS5        [        R
                  * W	US:*  '   [        R                  X'   U	S   $ ! , (       d  f       N<= f)aN  Log of the probability density function.

Parameters
----------
x, s2 : array_like
    Arguments. `s2` must be greater than zero.
mu, lmbda, a, b : array_like, optional
    Shape parameters. `lmbda`, `a`, and `b` must be greater
    than zero.

Returns
-------
logpdf : ndarray or scalar
    Log of the probability density function.

r   r  r$  Nr   r/   )_process_parameters_pdfr?   r#  rW   r   r   r  )
ri   rO   r  r  r  r
  r	  r  argsr   s
             r4   r   normal_inverse_gamma_gen.logpdf  s|    " 44QBqL!W[[X&ZZd 34F '66'rQw&&bz	 '&s   $B		
Bc                 D   [         R                  " US[         R                  -  U-  -  5      nXe-  [        R                  " U5      R                  UR                  5      -  nSU-  US-   -  n	[         R                  " SU-  XAU-
  S-  -  -   * SU-  -  5      n
Xx-  U	-  U
-  $ )Nr-   r   )r?   ra   r  r   gammar  r<   r   r  s              r4   _pdfnormal_inverse_gamma_gen._pdf  s    WWUa"%%i"n-.TGMM!$++AGG44"fAVVacEr6A+--.!B$78w|b  r6   c                    U R                  XX4XV5      u  pxUS   n[        R                  " SS9   [        R                  " U R                  " U6 5      n	SSS5        SW	US:*  '   [        R
                  X'   U	S   $ ! , (       d  f       N-= f)a@  The probability density function.

Parameters
----------
x, s2 : array_like
    Arguments. `s2` must be greater than zero.
mu, lmbda, a, b : array_like, optional
    Shape parameters. `lmbda`, `a`, and `b` must be greater
    than zero.

Returns
-------
logpdf : ndarray or scalar
    The probability density function.

r   r  r$  Nr   r/   )r%  r?   r#  rW   r*  r  )
ri   rO   r  r  r  r
  r	  r  r&  r   s
             r4   r   normal_inverse_gamma_gen.pdf	  su    " 44QBqL!W[[X&**TYY-.C 'B!Gvv2w	 '&s   $A::
Bc                    U R                  XX45      u  pVUu  pp4XSS:  ) -  n[        R                  " U5      R                  5       n[        R                  " XCS-
  -  5      n[        R                  Xu'   [        R                  X'   US   US   4$ )a  The mean of the distribution.

Parameters
----------
mu, lmbda, a, b : array_like, optional
    Shape parameters. `lmbda` and `b` must be greater
    than zero, and `a` must be greater than one.

Returns
-------
x, s2 : ndarray
    The mean of the distribution.

r   r/   )_process_shapesr?   rW   r  r  )	ri   r  r  r
  r	  r  r&  mean_xmean_s2s	            r4   r   normal_inverse_gamma_gen.mean#  s     ,,R=1U8B$$&**Qa%[)&&66bz72;&&r6   c                 B   U R                  XX45      u  pVUu  pp4XSS:  ) -  nXSS:  ) -  nXCS-
  U-  -  n	US-  US-
  S-  US-
  -  -  n
[        R                  " U	5      [        R                  " U
5      p[        R                  X'   [        R                  X'   U	S   U
S   4$ )a  The variance of the distribution.

Parameters
----------
mu, lmbda, a, b : array_like, optional
    Shape parameters. `lmbda` and `b` must be greater
    than zero, and `a` must be greater than two.

Returns
-------
x, s2 : ndarray
    The variance of the distribution.

r   r-   r/   )r/  r?   rW   r  )ri   r  r  r
  r	  r  r&  	invalid_x
invalid_s2var_xvar_s2s              r4   r  normal_inverse_gamma_gen.var;  s     ,,R=1Ah&	Qx'
!eu_%A!a%!q1u-.

5)2::f+=v66VVRy&*$$r6   c                     [         R                  " XX4XV5      n[         R                  " S/S U 5       Q76 nU V	s/ s H  oR                  USS9PM     nn	Uu  pp4pVUS:  US:  -  US:  -  ) n
X4$ s  sn	f )Nr   c              3   8   #    U  H  oR                   v   M     g 7frz   rK   .0args     r4   	<genexpr>Cnormal_inverse_gamma_gen._process_parameters_pdf.<locals>.<genexpr>W       %@4Cii4   Fr  r   r?   r  r  r  )ri   rO   r  r  r  r
  r	  r&  r<   r=  r  s              r4   r%  0normal_inverse_gamma_gen._process_parameters_pdfU  s    ""1"Q:sA%@4%@A9=>#

5u
->!%r!QY1q5)QU34} ?s   A1c                     [         R                  " XX45      n[         R                  " S/S U 5       Q76 nU Vs/ s H  owR                  USS9PM     nnUu  pp4US:  US:  -  US:  -  ) nX4$ s  snf )Nr   c              3   8   #    U  H  oR                   v   M     g 7frz   rK   r;  s     r4   r>  ;normal_inverse_gamma_gen._process_shapes.<locals>.<genexpr>_  r@  rA  FrB  r   rC  )	ri   r  r  r
  r	  r&  r<   r=  r  s	            r4   r/  (normal_inverse_gamma_gen._process_shapes]  s    ""2a3sA%@4%@A9=>#

5u
->1QY1q5)QU34} ?s   A/c                     [        XX4US9$ r  )normal_inverse_gamma_frozenri   r  r  r
  r	  r   s         r4   r   !normal_inverse_gamma_gen.__call__e  s    *2aFFr6   r/   )r   r   r   r   NN)r   r   r   r   r   r   r   r   N)r   r   r   r   r   r  r   r   r*  r   r   r  r%  r/  r   r   r/   r6   r4   r  r  L  s=    sh1@!4!4'0%4Gr6   r  c                   @    \ rS rSrS
S jrS rS rS rS rSS jr	S	r
g)rJ  il  Nc                 6    [        U5      U l        XX44U l        g rz   )r  r   _shapesrK  s         r4   rp   $normal_inverse_gamma_frozen.__init__n  s    -d3
!r6   c                 P    U R                   R                  " X/U R                  Q76 $ rz   )r   r   rP  ri   rO   r  s      r4   r   "normal_inverse_gamma_frozen.logpdfr  s     zz  666r6   c                 P    U R                   R                  " X/U R                  Q76 $ rz   )r   r   rP  rS  s      r4   r   normal_inverse_gamma_frozen.pdfu  s    zz~~a3dll33r6   c                 H    U R                   R                  " U R                  6 $ rz   )r   r   rP  r}   s    r4   r    normal_inverse_gamma_frozen.meanx  s    zz--r6   c                 H    U R                   R                  " U R                  6 $ rz   )r   r  rP  r}   s    r4   r  normal_inverse_gamma_frozen.var{  s    zz~~t||,,r6   c                 N    U R                   R                  " U R                  XS.6$ r  )r   r  rP  rE  s      r4   r  normal_inverse_gamma_frozen.rvs~  s    zz~~t||$RRr6   )r   rP  rM  r2  )r   r   r   r   rp   r   r   r   r  r  r   r/   r6   r4   rJ  rJ  l  s!    '74.-Sr6   rJ  )r   r   r   r  r  r2  )r/  rz   )rH  	threadingnumpyr?   scipy.linalgrY   
scipy._libr   scipy.specialr   r   r   r   r   r	   r
   r   r   scipy._lib._utilr   r   scipy.linalg.blasr   r   _continuous_distnsr   r   _discrete_distnsr   r   r   r   r   _qmvntr   
_morestatsr   scipy.optimizer   __all__rf   r  r   r  _LOG_PILockr   r   r5   rI   rP   rR   r   r   r   r   _mvn_doc_frozen_callparams_mvn_doc_frozen_callparams_noter   mvn_docdict_noparamsr   r   r   name__dict__r.  method_frozenr   r   rJ  rK  _matnorm_doc_frozen_callparams#_matnorm_doc_frozen_callparams_noterO  matnorm_docdict_noparamsrM  r   rT  r   _dirichlet_doc_frozen_callparams%_dirichlet_doc_frozen_callparams_noter  dirichlet_docdict_noparamsr  r  r  r  r   r  _wishart_doc_default_callparams_wishart_doc_callparams_note_wishart_doc_frozen_callparams#_wishart_doc_frozen_callparams_noter  wishart_docdict_noparamsr  r    r  rj  r!   rn  #_multinomial_doc_default_callparams _multinomial_doc_callparams_note"_multinomial_doc_frozen_callparams'_multinomial_doc_frozen_callparams_noter  multinomial_docdict_noparamsr  r"   r  r  r#   r  r   r$   r$  r;  r%   rA  rm  r&   rq  r|  r}  _mvt_doc_frozen_callparams_noter  mvt_docdict_noparamsr  r  r'   _mhg_doc_default_callparams_mhg_doc_callparams_note_mhg_doc_frozen_callparams_mhg_doc_frozen_callparams_noter  mhg_docdict_noparamsr  r(   r  r  r)   r  _ctab_doc_row_col_ctab_doc_x_ctab_doc_row_col_note_ctab_doc_mean_params_ctab_doc_row_col_note_frozen_ctab_docdictr  _ctab_docdict_frozenupdateri  rk  r*   ro  rt  r~  #_dirichlet_mn_doc_frozen_callparams(_dirichlet_mn_doc_frozen_callparams_noter  dirichlet_mn_docdict_noparamsr  r  r   r  r  r+   r  r  r,   rJ  r/   r6   r4   <module>r     sW
       * * *  ; 2 . # ' '  ) &#$ 66!bee)	
&&->>	 DK&U Up& &D< <     #B  $? 8*  $> ?* s. sl ./ b8 b8N 6D$--d3F.77=M",,V^^-ACM%%fnn6HIFN 6# 
   "$ 'B # (G$@*  (F$G* `*( `*F "#69? 69v 0D''-F(11$7M",,V^^-EGM%%fnn6LMFN 0% !
 $&  )B % *K*  *J* )X;*W8$ W8t O	> >: FD##D)F$--d3M",,24M%%fnn6NOFN F#   " !# 'B #  ?8*   >?* a	 " a	 H -5J_ 5Jt GD!!$'F"++D1M",,02M%%fnn6LMFN G]5[ ]5@ 
9J 9J| <D$$T*F"++D1M",,02M%%fnn6LMFN <' #$   &( "+B '  C<*   BC*  G4& G4T
 +B +B` 4D%%d+F&//5M",,46M%%fnn&@BFN 4^. ^B ./ < <<u& up < <<Y- Yx ,- )D )DXn( nb "#<? <<
  #B  $? 8*  $& ?* R#) R#j4BO 4Bn $%
 7D((.F)2248M",,V^^-ACM%%fnn6HIFN 7     #B   ;4*   :;* Q!1 Qh 45  9O  9J ;D'006F1::4@M",,,.M%%fnn&8:FN ;]E' ]E@  !9/ 92, % 
   
!B  +%-/ %))+    6 E 		= ),D&&t,F'006M]0&..AV]#	 -|, |~ *+ < <@	( $ ') #,B ( -Q*  -P*! LBX 0 Xv 23 2? 22 4D&//5F099$?M",,57M%%fnn&ACFN 4U	* U	p &'e9_ e9PZG/ ZGz 01 S/ S0 4D%..t4F/88>M",,V^^-ACM%%fnn6HIFN 4r6   