o
    +ôj  ã                   @   sf   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gZG dd„ deƒZdS )é    N)ÚinfÚnan)ÚChi2Úconstraints)ÚDistribution)Ú_standard_normalÚbroadcast_allÚStudentTc                       s�   e Zd ZdZejejejdœZejZdZ	e
dd„ ƒZe
dd„ ƒZe
dd	„ ƒZd‡ fdd„	Zd‡ fdd„	Z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ÚscaleTc                 C   s"   | j jtjd�}t|| jdk< |S )N©Úmemory_formaté   )r   ÚcloneÚtorchÚcontiguous_formatr   r
   ©ÚselfÚm© r   úo/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/torch/distributions/studentT.pyÚmean%   s   zStudentT.meanc                 C   s   | j S ©N)r   )r   r   r   r   Úmode+   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   Úvariance/   s   ÿþÿzStudentT.varianceç        ç      ð?Nc                    sB   t |||ƒ\| _| _| _t| jƒ| _| j ¡ }tƒ j||d� d S )N©Úvalidate_args)	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    )Ú_get_checked_instancer	   r   ÚSizer
   Úexpandr   r   r"   r$   r%   Ú_validate_args)r   r&   Ú	_instanceÚnewr'   r   r   r+   A   s   
zStudentT.expandc                 C   sP   |   |¡}t|| jj| jjd�}| j |¡}|t || j ¡ }| j	| j
|  S )N)ÚdtypeÚdevice)Ú_extended_shaper   r
   r/   r0   r"   Úrsampler   Úrsqrtr   r   )r   Úsample_shapeÚshapeÚXÚZÚYr   r   r   r2   L   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,   Ú_validate_sampler   r   Úlogr
   ÚmathÚpir   ÚlgammaÚlog1p)r   ÚvalueÚyr7   r   r   r   Úlog_probZ   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;   Údigamma)r   Zlbetar   r   r   Úentropyg   s$   ÿþÿÿ"þÿüûÿzStudentT.entropy)r   r   Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚpositiveÚrealÚarg_constraintsÚsupportÚhas_rsampleÚpropertyr   r   r   r%   r+   r   r*   r2   rB   rD   Ú__classcell__r   r   r'   r   r	      s&    ý


)r<   r   r   r   Ztorch.distributionsr   r   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   r   Ú__all__r	   r   r   r   r   Ú<module>   s    