
    קgc                         d dl Z d dlZd dlmZmZ d dlmZmZ d dlmZ d dl	m
Z
mZ d dlmZ dgZ G d de          ZdS )	    N)infnan)Chi2constraints)Distribution)_standard_normalbroadcast_all)_sizeStudentTc                        e Zd ZdZej        ej        ej        dZej        ZdZ	e
d             Ze
d             Ze
d             Zd fd
	Zd fd	Z ej                    fdedej        fdZd Zd Z xZS )r   a  
    Creates a Student's t-distribution parameterized by degree of
    freedom :attr:`df`, mean :attr:`loc` and scale :attr:`scale`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = StudentT(torch.tensor([2.0]))
        >>> m.sample()  # Student's t-distributed with degrees of freedom=2
        tensor([ 0.1046])

    Args:
        df (float or Tensor): degrees of freedom
        loc (float or Tensor): mean of the distribution
        scale (float or Tensor): scale of the distribution
    )dflocscaleTc                 v    | j                             t          j                  }t          || j        dk    <   |S )Nmemory_format   )r   clonetorchcontiguous_formatr   r   selfms     X/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/distributions/studentT.pymeanzStudentT.mean(   s.    HNN)@NAA$'Q,    c                     | j         S N)r   )r   s    r   modezStudentT.mode.   s	    xr   c                    | j                             t          j                  }| j        | j         dk                                 d          | j         | j         dk             z  | j         | j         dk             dz
  z  || j         dk    <   t          || j         dk    | j         dk    z  <   t          || j         dk    <   |S )Nr      r   )r   r   r   r   r   powr   r   r   s     r   variancezStudentT.variance2   s    GMM(?M@@Jtw{#''**gdgk"#wtw{#a') 	
$'A+
 -047a<DGaK
()$'Q,r                 ?Nc                     t          |||          \  | _        | _        | _        t	          | j                  | _        | j                                        }t                                          ||           d S )Nvalidate_args)	r	   r   r   r   r   _chi2sizesuper__init__)r   r   r   r   r(   batch_shape	__class__s         r   r,   zStudentT.__init__>   sb    (5b#u(E(E%4:$']]
gllnnMBBBBBr   c                    |                      t          |          }t          j        |          }| j                            |          |_        | j                            |          |_        | j                            |          |_        | j                            |          |_        t          t          |          
                    |d           | j        |_        |S )NFr'   )_get_checked_instancer   r   Sizer   expandr   r   r)   r+   r,   _validate_args)r   r-   	_instancenewr.   s       r   r2   zStudentT.expandD   s    ((9==j--,,(//+..J%%k22	J%%k22	h%%k%GGG!0
r   sample_shapereturnc                    |                      |          }t          || j        j        | j        j                  }| j                            |          }|t          j        || j        z            z  }| j	        | j
        |z  z   S )N)dtypedevice)_extended_shaper   r   r9   r:   r)   rsampler   rsqrtr   r   )r   r6   shapeXZYs         r   r<   zStudentT.rsampleO   su     $$\22U$'-OOOJ|,,AK(((x$*q.((r   c                    | j         r|                     |           || j        z
  | j        z  }| j                                        d| j                                        z  z   dt          j        t          j                  z  z   t          j	        d| j        z            z   t          j	        d| j        dz   z            z
  }d| j        dz   z  t          j
        |dz  | j        z            z  |z
  S )N      ?r%   g      g       @)r3   _validate_sampler   r   logr   mathpir   lgammalog1p)r   valueyr@   s       r   log_probzStudentT.log_prob]   s     	)!!%(((TX+JNNDGKKMM!"DHTW%%%& l3=))* l3$'C-011	2 	
 tw}%AsFTW4D(E(EEIIr   c                    t          j        d| j        z            t          j        d          z   t          j        d| j        dz   z            z
  }| j                                        d| j        dz   z  t          j        d| j        dz   z            t          j        d| j        z            z
  z  z   d| j                                        z  z   |z   S )NrC   r   )r   rH   r   rF   r   rE   digamma)r   lbetas     r   entropyzStudentT.entropyj   s    Ltw''k#l3$'A+.//0 	 JNNw{}SDGaK011EM#-4P4PPRR DGKKMM!	"
 	
r   )r$   r%   Nr   )__name__
__module____qualname____doc__r   positiverealarg_constraintssupporthas_rsamplepropertyr   r   r#   r,   r2   r   r1   r
   Tensorr<   rL   rP   __classcell__)r.   s   @r   r   r      s@        " "% O
 GK  X
   X 	 	 X	C C C C C C	 	 	 	 	 	 -7EJLL ) )E )U\ ) ) ) )J J J
 
 
 
 
 
 
r   )rF   r   r   r   torch.distributionsr   r    torch.distributions.distributionr   torch.distributions.utilsr   r	   torch.typesr
   __all__r    r   r   <module>rc      s              1 1 1 1 1 1 1 1 9 9 9 9 9 9 E E E E E E E E       ,h
 h
 h
 h
 h
| h
 h
 h
 h
 h
r   