
    cri1                     ~    d dl Z d dlmZ d dlmZ 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gZ G d	 d          ZdS )
    N)Optional)
deprecated)Tensor)constraints)lazy_property)_sizeDistributionc            	       6    e Zd ZdZdZdZdZededdfd            Z	 e
j                     e
j                    dfde
j        d	e
j        d
ee         ddf fdZd'defdZede
j        fd            Zede
j        fd            Zedeeej        f         fd            Zedeej                 fd            Zedefd            Zedefd            Zedefd            Zedefd            Z e
j                    fdedefdZ e
j                    fdedefdZ e de!          de"defd            Z#dedefdZ$dedefdZ%dedefdZ&d(dedefd Z'defd!Z(defd"Z) e
j                    fdede
j        fd#Z*deddfd$Z+d'd%Z,defd&Z- xZ.S ))r	   aS  
    Distribution is the abstract base class for probability distributions.

    Args:
        batch_shape (torch.Size): The shape over which parameters are batched.
        event_shape (torch.Size): The shape of a single sample (without batching).
        validate_args (bool, optional): Whether to validate arguments. Default: None.
    FTvaluereturnNc                 4    | dvrt           | t          _        dS )a  
        Sets whether validation is enabled or disabled.

        The default behavior mimics Python's ``assert`` statement: validation
        is on by default, but is disabled if Python is run in optimized mode
        (via ``python -O``). Validation may be expensive, so you may want to
        disable it once a model is working.

        Args:
            value (bool): Whether to enable validation.
        )TFN)
ValueErrorr	   _validate_args)r   s    x/var/www/html/bestrading.cuttalo.com/models/btc_v9/venv/lib/python3.11/site-packages/torch/distributions/distribution.pyset_default_validate_argsz&Distribution.set_default_validate_args   s#     %%&+###    batch_shapeevent_shapevalidate_argsc                    || _         || _        ||| _        | j        r@	 | j        }n6# t          $ r) i }t          j        | j         ddz   dz   d           Y nw xY w|                                D ]\  }}t          j
        |          r|| j        vr1t          t          t          |           |          t                    rTt          | |          }|                    |          }t#          j        |          s_t'          d| dt          |          j         dt+          |j                   d	t/          |            d
t/          |           d|           t1                                                       d S )Nz$ does not define `arg_constraints`. zAPlease set `arg_constraints = {}` or initialize the distribution z2with `validate_args=False` to turn off validation.   
stacklevelzExpected parameter z (
 of shape z) of distribution z to satisfy the constraint , but found invalid values:
)_batch_shape_event_shaper   arg_constraintsNotImplementedErrorwarningswarn	__class__itemsr   is_dependent__dict__
isinstancegetattrtyper   checktorch_is_all_truer   __name__tupleshapereprsuper__init__)
selfr   r   r   r   param
constraintr   validr"   s
            r   r1   zDistribution.__init__/   s    ('$"/D 		"&"6&   "$~KKKYZJK  !	      &5%:%:%<%<  !z+J77 --*DJJ..3 3- e,,"((//)%00 $>e > > KK0> ><A%+<N<N> >+/::> > 6:*5E5E> > 7<	> >   	s   * 0AAc                     t           )a/  
        Returns a new distribution instance (or populates an existing instance
        provided by a derived class) with batch dimensions expanded to
        `batch_shape`. This method calls :class:`~torch.Tensor.expand` on
        the distribution's parameters. As such, this does not allocate new
        memory for the expanded distribution instance. Additionally,
        this does not repeat any args checking or parameter broadcasting in
        `__init__.py`, when an instance is first created.

        Args:
            batch_shape (torch.Size): the desired expanded size.
            _instance: new instance provided by subclasses that
                need to override `.expand`.

        Returns:
            New distribution instance with batch dimensions expanded to
            `batch_size`.
        r   )r2   r   	_instances      r   expandzDistribution.expandW   s
    & "!r   c                     | j         S )zF
        Returns the shape over which parameters are batched.
        )r   r2   s    r   r   zDistribution.batch_shapel       
   r   c                     | j         S )zJ
        Returns the shape of a single sample (without batching).
        )r   r;   s    r   r   zDistribution.event_shapes   r<   r   c                     t           )a
  
        Returns a dictionary from argument names to
        :class:`~torch.distributions.constraints.Constraint` objects that
        should be satisfied by each argument of this distribution. Args that
        are not tensors need not appear in this dict.
        r7   r;   s    r   r   zDistribution.arg_constraintsz   
     "!r   c                     t           )z
        Returns a :class:`~torch.distributions.constraints.Constraint` object
        representing this distribution's support.
        r7   r;   s    r   supportzDistribution.support   
     "!r   c                     t           )z7
        Returns the mean of the distribution.
        r7   r;   s    r   meanzDistribution.mean   
    
 "!r   c                 0    t          | j         d          )z7
        Returns the mode of the distribution.
        z does not implement mode)r   r"   r;   s    r   modezDistribution.mode   s    
 "T^"M"M"MNNNr   c                     t           )z;
        Returns the variance of the distribution.
        r7   r;   s    r   variancezDistribution.variance   rE   r   c                 4    | j                                         S )zE
        Returns the standard deviation of the distribution.
        )rI   sqrtr;   s    r   stddevzDistribution.stddev   s    
 }!!###r   sample_shapec                     t          j                    5  |                     |          cddd           S # 1 swxY w Y   dS )z
        Generates a sample_shape shaped sample or sample_shape shaped batch of
        samples if the distribution parameters are batched.
        N)r*   no_gradrsampler2   rM   s     r   samplezDistribution.sample   s    
 ]__ 	. 	.<<--	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.s   6::c                     t           )z
        Generates a sample_shape shaped reparameterized sample or sample_shape
        shaped batch of reparameterized samples if the distribution parameters
        are batched.
        r7   rQ   s     r   rP   zDistribution.rsample   rB   r   z=`sample_n(n)` will be deprecated. Use `sample((n,))` instead.)categorync                 R    |                      t          j        |f                    S )zq
        Generates n samples or n batches of samples if the distribution
        parameters are batched.
        )rR   r*   Size)r2   rU   s     r   sample_nzDistribution.sample_n   s"     {{5:qd++,,,r   c                     t           )z
        Returns the log of the probability density/mass function evaluated at
        `value`.

        Args:
            value (Tensor):
        r7   r2   r   s     r   log_probzDistribution.log_prob   r?   r   c                     t           )z
        Returns the cumulative density/mass function evaluated at
        `value`.

        Args:
            value (Tensor):
        r7   rZ   s     r   cdfzDistribution.cdf   r?   r   c                     t           )z
        Returns the inverse cumulative density/mass function evaluated at
        `value`.

        Args:
            value (Tensor):
        r7   rZ   s     r   icdfzDistribution.icdf   r?   r   r9   c                     t           )ar  
        Returns tensor containing all values supported by a discrete
        distribution. The result will enumerate over dimension 0, so the shape
        of the result will be `(cardinality,) + batch_shape + event_shape`
        (where `event_shape = ()` for univariate distributions).

        Note that this enumerates over all batched tensors in lock-step
        `[[0, 0], [1, 1], ...]`. With `expand=False`, enumeration happens
        along dim 0, but with the remaining batch dimensions being
        singleton dimensions, `[[0], [1], ..`.

        To iterate over the full Cartesian product use
        `itertools.product(m.enumerate_support())`.

        Args:
            expand (bool): whether to expand the support over the
                batch dims to match the distribution's `batch_shape`.

        Returns:
            Tensor iterating over dimension 0.
        r7   )r2   r9   s     r   enumerate_supportzDistribution.enumerate_support   s
    , "!r   c                     t           )z
        Returns entropy of distribution, batched over batch_shape.

        Returns:
            Tensor of shape batch_shape.
        r7   r;   s    r   entropyzDistribution.entropy   s
     "!r   c                 N    t          j        |                                           S )z
        Returns perplexity of distribution, batched over batch_shape.

        Returns:
            Tensor of shape batch_shape.
        )r*   exprc   r;   s    r   
perplexityzDistribution.perplexity  s     y(((r   c                     t          |t          j                  st          j        |          }t          j        || j        z   | j        z             S )ax  
        Returns the size of the sample returned by the distribution, given
        a `sample_shape`. Note, that the batch and event shapes of a distribution
        instance are fixed at the time of construction. If this is empty, the
        returned shape is upcast to (1,).

        Args:
            sample_shape (torch.Size): the size of the sample to be drawn.
        )r&   r*   rW   r   r   rQ   s     r   _extended_shapezDistribution._extended_shape  sG     ,
33 	4 :l33Lz,)::T=NNOOOr   c                    t          |t          j                  st          d          t	          |                                          t	          | j                  z
  }|                                |d         | j        k    r-t          d|                                 d| j         d          |                                }| j        | j        z   }t          t          |          t          |                    D ]-\  }}|dk    r"|dk    r||k    rt          d| d| d          .	 | j
        }n5# t          $ r( t          j        | j         dd	z   d
z   d           Y dS w xY w|J |                    |          }t          j        |          s\t          dt#          |          j         dt'          |j                   dt+          |           dt+          |            d| 
          dS )a  
        Argument validation for distribution methods such as `log_prob`,
        `cdf` and `icdf`. The rightmost dimensions of a value to be
        scored via these methods must agree with the distribution's batch
        and event shapes.

        Args:
            value (Tensor): the tensor whose log probability is to be
                computed by the `log_prob` method.
        Raises
            ValueError: when the rightmost dimensions of `value` do not match the
                distribution's batch and event shapes.
        z/The value argument to log_prob must be a TensorNz5The right-most size of value must match event_shape: z vs .   z9Value is not broadcastable with batch_shape+event_shape: z% does not define `support` to enable z;sample validation. Please initialize the distribution with z-`validate_args=False` to turn off validation.r   r   zExpected value argument (r   z) to be within the support (z) of the distribution r   )r&   r*   r   r   lensizer   r   zipreversedrA   r   r    r!   r"   r)   r+   r(   r,   r-   r.   r/   )	r2   r   event_dim_startactual_shapeexpected_shapeijrA   r5   s	            r   _validate_samplezDistribution._validate_sample  sY    %.. 	PNOOOejjll++c$2C.D.DD::<<(()T->>>n

nnZ^Zknnn   zz||*T->>..0H0HII 	 	DAqAvv!q&&Q!VV sP\ssbpsss  		lGG" 	 	 	M>HHHOPAB 	    FF	 """e$$!%(( 	6KK(6 649%+4F4F6 6-1']]6 6 (,Dzz6 6 /4	6 6  	 	s   .D6 6.E('E(c                     |Bt          |           j        |j        k    r%t          d| j        j         d|j         d          |"|                     t          |                     n|S )Nz	Subclass z of zR that defines a custom __init__ method must also define a custom .expand() method.)r(   r1   r   r"   r,   __new__)r2   clsr8   s      r   _get_checked_instancez"Distribution._get_checked_instanceL  s|    d!4!D!D%>DN3 > > > > >   ,5+<t||DJJ''')Kr   c                       fd j                                         D             }d                     fd|D                       } j        j        dz   |z   dz   S )Nc                 ,    g | ]\  }}|j         v |S  )r%   ).0k_r2   s      r   
<listcomp>z)Distribution.__repr__.<locals>.<listcomp>U  s)    XXXTQQ$-EWEWqEWEWEWr   z, c                     g | ]V}| d j         |                                         dk    rj         |         nj         |                                          WS )z: rk   )r%   numelrm   )r}   pr2   s     r   r   z)Distribution.__repr__.<locals>.<listcomp>W  st        hhDM!,<,B,B,D,D,I,Ia((t}]^O_OdOdOfOfhh  r   ())r   r#   joinr"   r,   )r2   param_namesargs_strings   `  r   __repr__zDistribution.__repr__T  s    XXXXT%9%?%?%A%AXXXii   $  
 
 ~&,{:S@@r   )N)T)/r,   
__module____qualname____doc__has_rsamplehas_enumerate_supportr   staticmethodboolr   r*   rW   r   r1   r   r9   propertyr   r   dictstrr   
Constraintr   rA   r   rD   rG   rI   rL   rR   rP   r   FutureWarningintrX   r[   r]   r_   ra   rc   rf   rh   ru   ry   r   __classcell__)r"   s   @r   r	   r	      sY         K!N, ,$ , , , \,$ #-%*,,",%*,,(,	& &Z& Z&  ~	&
 
& & & & & &P" "% " " " "* !UZ ! ! ! X! !UZ ! ! ! X! "c;+A&A!B " " " X" "+"89 " " " X" "f " " " X" Of O O O XO "& " " " X" $ $ $ $ X$ ,65:<< . .5 .F . . . . -7EJLL " "E "V " " " " ZG  -# -& - - -	 -"f " " " " "" "F " " " ""& "V " " " "" " " " " " "0" " " " ")F ) ) ) ) 5?EJLL P PE PUZ P P P P1f 1 1 1 1 1fL L L LA# A A A A A A A Ar   )r    typingr   typing_extensionsr   r*   r   torch.distributionsr   torch.distributions.utilsr   torch.typesr   __all__r	   r|   r   r   <module>r      s           ( ( ( ( ( (        + + + + + + 3 3 3 3 3 3       
LA LA LA LA LA LA LA LA LA LAr   