o
    Zh                     @   sn   d dl Z d dl mZ d dlmZ d dlmZ d dl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)Tensor)constraints)	Dirichlet)ExponentialFamily)broadcast_all)_Number_sizeBetac                       s   e Zd ZdZejejdZejZdZ	d  fdd	Z
d  fd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d	efddZdd Zdd Zed	efddZed	efddZed	eeef fddZdd Z  ZS )"r	   ar  
    Beta distribution parameterized by :attr:`concentration1` and :attr:`concentration0`.

    Example::

        >>> # xdoctest: +IGNORE_WANT("non-deterministic")
        >>> m = Beta(torch.tensor([0.5]), torch.tensor([0.5]))
        >>> m.sample()  # Beta distributed with concentration concentration1 and concentration0
        tensor([ 0.1046])

    Args:
        concentration1 (float or Tensor): 1st concentration parameter of the distribution
            (often referred to as alpha)
        concentration0 (float or Tensor): 2nd concentration parameter of the distribution
            (often referred to as beta)
    concentration1concentration0TNc                    sp   t |trt |trtt|t|g}nt||\}}t||gd}t||d| _t	 j
| jj|d d S )Nvalidate_args)
isinstancer   torchtensorfloatr   stackr   
_dirichletsuper__init__Z_batch_shape)selfr   r   r   Zconcentration1_concentration0	__class__ G/var/www/auris/lib/python3.10/site-packages/torch/distributions/beta.pyr   '   s   zBeta.__init__c                    sD   |  t|}t|}| j||_tt|j|dd | j|_|S )NFr   )	Z_get_checked_instancer	   r   Sizer   expandr   r   _validate_args)r   Zbatch_shapeZ	_instancenewr   r   r   r   8   s   
zBeta.expandreturnc                 C   s   | j | j | j  S Nr
   r   r   r   r   mean@   s   z	Beta.meanc                 C   s   | j jd S N).r   )r   moder#   r   r   r   r&   D      z	Beta.modec                 C   s*   | j | j }| j | j |d|d   S )N      )r   r   pow)r   totalr   r   r   varianceH   s   zBeta.variancer   sample_shapec                 C   s   | j |ddS )Nr   r   )r   rsampleselect)r   r-   r   r   r   r.   M   s   zBeta.rsamplec                 C   s0   | j r| | t|d| gd}| j|S )Ng      ?r   )r   Z_validate_sampler   r   r   log_prob)r   valueZheads_tailsr   r   r   r0   P   s   
zBeta.log_probc                 C   s
   | j  S r"   )r   entropyr#   r   r   r   r2   V   s   
zBeta.entropyc                 C   &   | j jd }t|trt|gS |S r%   r   Zconcentrationr   r   r   r   r   resultr   r   r   r   Y      
zBeta.concentration1c                 C   r3   )N).r)   r4   r5   r   r   r   r   a   r7   zBeta.concentration0c                 C   s   | j | jfS r"   r
   r#   r   r   r   _natural_paramsi   r'   zBeta._natural_paramsc                 C   s"   t |t | t ||  S r"   )r   lgamma)r   xyr   r   r   _log_normalizerm   s   "zBeta._log_normalizerr"   )r   )__name__
__module____qualname____doc__r   ZpositiveZarg_constraintsZunit_intervalZsupportZhas_rsampler   r   propertyr   r$   r&   r,   r   r.   r0   r2   r   r   tupler8   r<   __classcell__r   r   r   r   r	      s2    )r   r   Ztorch.distributionsr   Ztorch.distributions.dirichletr   Ztorch.distributions.exp_familyr   Ztorch.distributions.utilsr   Ztorch.typesr   r   __all__r	   r   r   r   r   <module>   s   