
    Αi$                        S SK Jr  S SKrS SKJr  S SKJr  S SKrS SKJ	r	  S SK
Jr  S SKJrJr  S SKJr  \(       a  S S	KJrJr   " S
 S\R&                  5      rg)    )annotationsN)Sequence)TYPE_CHECKING)
check_type)Variable)Gammadistribution)in_dynamic_mode)Tensordtypec                     ^  \ rS rSr% SrS\S'   S\S'   S\S'   S\S'   S	\S	'    S         SU 4S
 jjjrSS jr\SS j5       r	\SS j5       r
/ 4SS jjrSS jrSS jrSS jrSrU =r$ )StudentT   ay
  
The StudentT distribution with parameters: `df`, `loc`, `scale`.

In probability theory and statistics, the StudentT distribution is one of the basic continuous probability distributions
defined on the real number set.

The probability density function (pdf) is

.. math::

    pdf(x; \nu, \mu, \sigma) = \frac{\Gamma[(\nu+1)/2]}{\sigma\sqrt{\nu\pi}\Gamma(\nu/2)[1+(\frac{x-\mu}{\sigma})^2/\nu]^{(1+\nu)/2}}

In the above equation:

* :math:`df = \nu`: is the degree of freedom.
* :math:`loc = \mu`: is the center parameter.
* :math:`scale = \sigma`: is the scale parameter.
* :math:`\Gamma(\cdot)`: is the gamma function.

Args:
    df (float|Tensor): The degree of freedom of the distribution, which should be non-negative. If the input data type is float,
        the data type of `df` will be converted to a 1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.
    loc (float|Tensor): The center of the distribution. If the input data type is float, the data type of `loc` will be converted to a
        1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.
    scale (float|Tensor): The scale of the distribution, which should be non-negative. If the input data type is float, the data type
        of `scale` will be converted to a 1-D Tensor with paddle global default dtype. Supported dtype: float32, float64.
    name(str|None, optional): Name for the operation (optional, default is None). For more information, please refer to :ref:`api_guide_Name`.

Examples:
    .. code-block:: python

        >>> import paddle
        >>> from paddle.distribution import StudentT
        >>> paddle.set_device('cpu')
        >>> paddle.seed(100)
        >>> dist = StudentT(df=10.0, loc=0.0, scale=1.0)
        >>> dist.sample([3])
        Tensor(shape=[3, 1], dtype=float32, place=Place(cpu), stop_gradient=True,
        [[-2.07709980],
         [ 0.27981189],
         [ 0.00881413]])

        >>> dist2 = StudentT(df=paddle.to_tensor([10.0, 5.0]), loc=paddle.to_tensor([0.0, 0.0]), scale=paddle.to_tensor([1.0, 2.0]))
        >>> value_tensor = paddle.to_tensor([0.8], dtype="float32")
        >>> lp = dist2.log_prob(value_tensor)
        >>> print(lp)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [-1.28509235, -1.75626254])

        >>> p = dist2.prob(value_tensor)
        >>> print(p)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [0.27662504, 0.17268908])

        >>> entropy = dist2.entropy()
        >>> print(entropy)
        Tensor(shape=[2], dtype=float32, place=Place(cpu), stop_gradient=True,
        [1.52126312, 2.32064891])

r   dflocscalestrnamer   c                  > [        5       (       d  [        US[        [        [        R
                  R                  4S5        [        US[        [        [        R
                  R                  4S5        [        US[        [        [        R
                  R                  4S5        Ub  UOSU l        U R                  XU5      u  U l	        U l
        U l        U R                  U R                  5      (       d  [        S5      eU R                  U R                  5      (       d  [        S5      eU R                  R                  n[        TU ]A  U5        [#        SU R                  -  [        R$                  " U R                  S5      5      U l        g )Nr   r   r   r   z<Every element of input parameter `df` should be nonnegative.z?Every element of input parameter `scale` should be nonnegative.      ?)r
   r   floatr   paddlepirValuer   _broadcast_allr   r   r   _check_nonnegative
ValueErrorshapesuper__init__r   	full_like_chi2)selfr   r   r   r   batch_shape	__class__s         ]/var/www/html/banglarbhumi/venv/lib/python3.13/site-packages/paddle/distribution/student_t.pyr    StudentT.__init__b   sQ      JJ$$
 	 JJ$$
 	 JJ$$
 	 !,D*	(,(;(;BU(K%4:&&tww//N  &&tzz22Q  ggmm%3=&*:*:477C*HI
    c                (    US:  R                  5       $ )zrCheck the non-negative constraint for input parameters

Args:
    value (Tensor)

Returns:
    bool: pass or not.
g        )allr#   values     r&   r   StudentT._check_nonnegative   s     !!##r(   c           
         [         R                  " U R                  S:  U R                  [         R                  " U R                  [        S5      S95      $ )zAMean of StudentT distribution.

Returns:
    Tensor: mean value.
      ?nan
fill_value)r   wherer   r   r!   r   )r#   s    r&   meanStudentT.mean   s?     ||GGcMHHTXX%,?
 	
r(   c           
        U R                   R                  5       R                  5       nU R                   S:  n[        R                  " UU R
                  R                  S5      U-  US-
  -  [        R                  " U[        S5      S95      nU R                   S:*  R                  U R                   S:  5      n[        R                  " U[        R                  " U[        S5      S9U5      nU$ )zIVariance of StudentT distribution.

Returns:
    Tensor: variance value.
       @   r0   r1   r/   inf)
r   clonedetachr   r3   r   powr!   r   logical_and)r#   varvar_conditioninf_conditions       r&   varianceStudentT.variance   s     ggmmo$$&#llJJNN1#sQw/SU5\:

 C44TWWs]Cll6++CE%LI3
 
r(   c                D   [        U[        5      (       d  [        S5      eU R                  U5      n[        R
                  " US9nU R                  R                  U5      nU[        R                  " X@R                  -  5      -  nU R                  U R                  U-  -   $ )a  Generate StudentT samples of the specified shape. The final shape would be ``shape+batch_shape`` .

Args:
    shape (Sequence[int], optional): Prepended shape of the generated samples.

Returns:
    Tensor: Sampled data with shape `sample_shape` + `batch_shape`.
z%sample shape must be Sequence object.)r   )
isinstancer   	TypeError_extend_shaper   normalr"   samplersqrtr   r   r   )r#   r   output_shapezchi2xs         r&   rH   StudentT.sample   s     %**CDD))%0MM-zz  'TGG^,,xx$**q.((r(   c                   [         R                  " SU R                  -  5      [        R                  " S5      -   [         R                  " SU R                  S-   -  5      -
  nU R                  R                  5       SU R                  S-   -  [         R                  " SU R                  S-   -  5      [         R                  " SU R                  -  5      -
  -  -   SU R                  R                  5       -  -   U-   $ )a  Shannon entropy in nats.

The entropy is

.. math::

    H = \log(\frac{\Gamma(\nu/2)\Gamma(1/2) \sigma \sqrt{\nu}}{\Gamma[(1+\nu)/2]}) + \frac{(1+\nu)}{2} \cdot \{\psi[(1+\nu)/2] - \psi(\nu/2)\}

In the above equation:

* :math:`\nu`: is the degree of freedom.
* :math:`\Gamma()`: is the gamma function.
* :math:`\psi()`: is the digamma function.

Returns:
    Tensor: Shannon entropy of StudentT distribution. The data type is the same as `df`.
r      )r   lgammar   mathr   logdigamma)r#   lbetas     r&   entropyStudentT.entropy   s    & MM#-(kk#mmC477Q;/01 	 JJNNww{ sdggk23..tww/0 DGGKKM!" 
	
r(   c                >   U R                  U R                  U5      nXR                  -
  U R                  -  nU R                  R	                  5       SU R                  R	                  5       -  -   S[
        R                  " [
        R                  5      -  -   [        R                  " SU R                  -  5      -   [        R                  " SU R                  S-   -  5      -
  nSU R                  S-   -  [        R                  " US-  U R                  -  5      -  U-
  $ )zLog probability density function.

Args:
  value (Tensor): The input tensor.

Returns:
  Tensor: log probability density. The data type is the same as `df`.
r   r/   g      r7   )
_check_values_dtype_in_probsr   r   r   rS   rR   pir   rQ   log1p)r#   r,   yZs       r&   log_probStudentT.log_prob   s     11$''5AXX+JJNNDGGKKM!"DHHTWW%%& mmC$''M*+ mmC477S=12	3 	
 tww}%QVdgg5E(FFJJr(   c                L    [         R                  " U R                  U5      5      $ )zProbability density function.

Args:
    value (Tensor): The input tensor.

Returns:
    Tensor: probability density. The data type is the same as `df`.
)r   expr^   r+   s     r&   probStudentT.prob  s     zz$--.//r(   )r"   r   r   r   r   )N)
r   float | Tensorr   rd   r   rd   r   z
str | NonereturnNone)r,   r   re   bool)re   r   )r   zSequence[int]re   r   )r,   r   re   r   )__name__
__module____qualname____firstlineno____doc____annotations__r    r   propertyr4   rA   rH   rV   r^   rb   __static_attributes____classcell__)r%   s   @r&   r   r      s    ;z 	J	KM
IL  5J5J 5J 	5J
 5J 
5J 5Jn	$ 

 

  & -/ )$!
FK(	0 	0r(   r   )
__future__r   rR   collections.abcr   typingr   r   paddle.base.data_feederr   paddle.base.frameworkr   paddle.distributionr   r	   paddle.frameworkr
   r   r   Distributionr    r(   r&   <module>rz      s<    #  $    . * 3 ,$y0|(( y0r(   