o
    h6                     @   s   d dl Z d dlmZmZ d dlZd dlmZ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 deZdS )
    N)OptionalUnion)infnanTensor)Chi2constraints)Distribution)_standard_normalbroadcast_all)_sizeStudentTc                       s   e Zd ZdZejejejdZejZdZ	e
defddZe
defddZe
defd	d
Z			ddeeef deeef deeef dee ddf
 fddZd fdd	Ze fdedefddZdd Zdd Z  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scaleTreturnc                 C   s"   | j jtjd}t|| jdk< |S )NZmemory_format   )r   clonetorchcontiguous_formatr   r   selfm r   b/home/www/facesmatcher.com/frenv_anti/lib/python3.10/site-packages/torch/distributions/studentT.pymean*   s   zStudentT.meanc                 C   s   | j S N)r   )r   r   r   r   mode0   s   zStudentT.modec                 C   s~   | j jtjd}| j| j dk d| j | j dk  | j | j dk d  || j dk< t|| j dk| j dk@ < t|| j dk< |S )Nr      r   )r   r   r   r   r   powr   r   r   r   r   r   variance4   s   zStudentT.variance              ?Nr   r   r   validate_argsc                    sB   t |||\| _| _| _t| j| _| j }t j||d d S )Nr$   )	r   r   r   r   r   _chi2sizesuper__init__)r   r   r   r   r$   batch_shape	__class__r   r   r)   @   s   
zStudentT.__init__c                    sn   |  t|}t|}| j||_| j||_| j||_| j||_t	t|j
|dd | j|_|S )NFr%   )Z_get_checked_instancer   r   Sizer   expandr   r   r&   r(   r)   _validate_args)r   r*   Z	_instancenewr+   r   r   r.   L   s   
zStudentT.expandsample_shapec                 C   sP   |  |}t|| jj| jjd}| j|}|t|| j  }| j	| j
|  S )N)dtypedevice)Z_extended_shaper
   r   r2   r3   r&   rsampler   Zrsqrtr   r   )r   r1   shapeXZYr   r   r   r4   W   s
   
zStudentT.rsamplec                 C   s   | j r| | || j | j }| j d| j   dttj  t	d| j  t	d| jd   }d| jd  t
|d | j  | S )N      ?r#   g      g       @)r/   Z_validate_sampler   r   logr   mathpir   lgammalog1p)r   valueyr7   r   r   r   log_probe   s   
&zStudentT.log_probc                 C   s|   t d| j td t d| jd   }| j d| jd  t d| jd  t d| j    d| j   | S )Nr9   r   )r   r=   r   r;   r   r:   Zdigamma)r   Zlbetar   r   r   entropyr   s$   "zStudentT.entropy)r"   r#   Nr   )__name__
__module____qualname____doc__r   ZpositiverealZarg_constraintsZsupportZhas_rsamplepropertyr   r   r   r!   r   floatr   boolr)   r.   r   r-   r   r4   rA   rB   __classcell__r   r   r+   r   r      s@    


)r;   typingr   r   r   r   r   r   Ztorch.distributionsr   r   Z torch.distributions.distributionr	   Ztorch.distributions.utilsr
   r   Ztorch.typesr   __all__r   r   r   r   r   <module>   s   