
    eThE                        S r SSKJrJr  SSKrSSKJr  SSKJrJrJ	r	J
r
JrJrJr   " S S\5      r " S S	\R                  5      r " S
 S\R                  5      r " S S5      r " S S\5      r " S S\5      r " S S\5      rg)z:
Time series distributional output classes and utilities.
    )CallableOptionalN)nn)AffineTransformDistributionIndependentNegativeBinomialNormalStudentTTransformedDistributionc                   d   ^  \ rS rSrSS\4U 4S jjjr\S 5       r\S 5       r\S 5       r	Sr
U =r$ )	AffineTransformed"   base_distributionc           	         > Uc  SOUU l         Uc  SOUU l        [        TU ]  U[	        U R                  U R                   US9/5        g )Ng      ?        locscale	event_dim)r   r   super__init__r   )selfr   r   r   r   	__class__s        V/var/www/auris/envauris/lib/python3.13/site-packages/transformers/time_series_utils.pyr   AffineTransformed.__init__#   sE    !MSu
+33*_QUQ[Q[gp-q,rs    c                 b    U R                   R                  U R                  -  U R                  -   $ )z'
Returns the mean of the distribution.
)	base_distmeanr   r   r   s    r   r    AffineTransformed.mean)   s&    
 ~~""TZZ/$((::r   c                 N    U R                   R                  U R                  S-  -  $ )z+
Returns the variance of the distribution.
   )r   variancer   r!   s    r   r%   AffineTransformed.variance0   s!    
 ~~&&Q66r   c                 6    U R                   R                  5       $ )z5
Returns the standard deviation of the distribution.
)r%   sqrtr!   s    r   stddevAffineTransformed.stddev7   s    
 }}!!##r   r   r   )NNr   )__name__
__module____qualname____firstlineno__r   r   propertyr    r%   r)   __static_attributes____classcell__r   s   @r   r   r   "   sS    t, t t ; ; 7 7 $ $r   r   c            	          ^  \ rS rSrS\S\\\4   S\S\\	R                     4   SS4U 4S jjrS	\	R                  S\\	R                     4S
 jrSrU =r$ )ParameterProjection?   in_featuresargs_dim
domain_map.returnNc           	         > [         TU ]  " S0 UD6  X l        [        R                  " UR                  5        Vs/ s H  n[        R                  " X5      PM     sn5      U l        X0l        g s  snf )N )	r   r   r8   r   
ModuleListvaluesLinearprojr9   )r   r7   r8   r9   kwargsdimr   s         r   r   ParameterProjection.__init__@   sV     	"6" MM(//J["\J[3299[#>J["\]	$ #]s    A-xc                 l    U R                    Vs/ s H
  o"" U5      PM     nnU R                  " U6 $ s  snf N)r@   r9   )r   rD   r@   params_unboundeds       r   forwardParameterProjection.forwardH   s4    04		:	DG	: 011 ;s   1)r8   r9   r@   )r,   r-   r.   r/   intdictstrr   tupletorchTensorr   rH   r1   r2   r3   s   @r   r5   r5   ?   sl    %%*.sCx.%FNsTYZ_ZfZfTgOgFh%	%2 2%*= 2 2r   r5   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )LambdaLayerN   c                 .   > [         TU ]  5         Xl        g rF   )r   r   function)r   rT   r   s     r   r   LambdaLayer.__init__O   s     r   c                 (    U R                   " U/UQ76 $ rF   rT   )r   rD   argss      r   rH   LambdaLayer.forwardS   s    }}Q&&&r   rW   )r,   r-   r.   r/   r   rH   r1   r2   r3   s   @r   rQ   rQ   N   s    !' 'r   rQ   c                      \ rS rSr% \\S'   \\S'   \\\4   \S'   SS\SS4S jjr	S	 r
  SS
\\R                     S\\R                     S\4S jjr\S\4S j5       r\S\4S j5       r\S\4S j5       rS\S\R.                  4S jrS\R                  4S jr\S\R                  S\R                  4S j5       rSrg)DistributionOutputW   distribution_classr7   r8   rB   r:   Nc                 |    Xl         U R                   Vs0 s H  o"XR                  U   -  _M     snU l        g s  snf rF   )rB   r8   )r   rB   ks      r   r   DistributionOutput.__init__\   s3    <@MMJMqC--"222MJJs   9c                 r    U R                   S:X  a  U R                  " U6 $ [        U R                  " U6 S5      $ )N   rB   r]   r   )r   
distr_argss     r   _base_distribution%DistributionOutput._base_distribution`   s6    88q=**J77t66
CQGGr   r   r   c                 \    U R                  U5      nUc  Uc  U$ [        XBX0R                  S9$ )Nr   )re   r   r   )r   rd   r   r   distrs        r   distributionDistributionOutput.distributionf   s3     ''
3;5=L$U5NN[[r   c                 @    U R                   S:X  a  S$ U R                   4$ )z_
Shape of each individual event contemplated by the distributions that this object constructs.
rb   r<   )rB   r!   s    r   event_shapeDistributionOutput.event_shaper   s    
 XX]r33r   c                 ,    [        U R                  5      $ )zx
Number of event dimensions, i.e., length of the `event_shape` tuple, of the distributions that this object
constructs.
)lenrl   r!   s    r   r   DistributionOutput.event_dimy   s     4##$$r   c                     g)z
A float that will have a valid numeric value when computing the log-loss of the corresponding distribution. By
default 0.0. This value will be used when padding data series.
r   r<   r!   s    r   value_in_support#DistributionOutput.value_in_support   s     r   c                 R    [        UU R                  [        U R                  5      S9$ )zn
Return the parameter projection layer that maps the input to the appropriate parameters of the distribution.
)r7   r8   r9   )r5   r8   rQ   r9   )r   r7   s     r   get_parameter_projection+DistributionOutput.get_parameter_projection   s'     ##]]"4??3
 	
r   rX   c                     [        5       e)z
Converts arguments to the right shape and domain. The domain depends on the type of distribution, while the
correct shape is obtained by reshaping the trailing axis in such a way that the returned tensors define a
distribution of the right event_shape.
)NotImplementedError)r   rX   s     r   r9   DistributionOutput.domain_map   s     "##r   rD   c                 h    U [         R                  " [         R                  " U 5      S-   5      -   S-  $ )z
Helper to map inputs to the positive orthant by applying the square-plus operation. Reference:
https://twitter.com/jon_barron/status/1387167648669048833
g      @       @)rN   r(   square)rD   s    r   
squareplusDistributionOutput.squareplus   s*     EJJu||A455<<r   )r8   rB   )rb   NN)r,   r-   r.   r/   type__annotations__rJ   rK   rL   r   re   r   rN   rO   r   ri   r0   rM   rl   r   floatrr   r   Moduleru   r9   staticmethodr}   r1   r<   r   r   r[   r[   W   s   38nKC K KH '+(,	
\ ell#
\ %	
\
 

\ 4U 4 4 %3 % % %  
C 
BII 
$ $ =ell =u|| = =r   r[   c                       \ rS rSr% SrSSSS.r\\\4   \	S'   \
r\\	S'   \S\R                  S\R                  S	\R                  4S
 j5       rSrg)StudentTOutput   z&
Student-T distribution output class.
rb   )dfr   r   r8   r]   r   r   r   c                    U R                  U5      R                  [        R                  " UR                  5      R
                  5      nSU R                  U5      -   nUR                  S5      UR                  S5      UR                  S5      4$ )Nr{   r}   	clamp_minrN   finfodtypeepssqueeze)clsr   r   r   s       r   r9   StudentTOutput.domain_map   sg    u%//EKK0H0L0LM3>>"%%zz"~s{{2b0AAAr   r<   N)r,   r-   r.   r/   __doc__r8   rK   rL   rJ   r   r   r]   r   classmethodrN   rO   r9   r1   r<   r   r   r   r      se     '(A>Hd38n>''BELL Bu|| BELL B Br   r   c                       \ rS rSr% SrSSS.r\\\4   \	S'   \
r\\	S'   \S\R                  S\R                  4S	 j5       rS
rg)NormalOutput   z#
Normal distribution output class.
rb   r+   r8   r]   r   r   c                     U R                  U5      R                  [        R                  " UR                  5      R
                  5      nUR                  S5      UR                  S5      4$ Nr   r   )r   r   r   s      r   r9   NormalOutput.domain_map   sJ    u%//EKK0H0L0LM{{2b 111r   r<   N)r,   r-   r.   r/   r   r8   rK   rL   rJ   r   r
   r]   r   r   rN   rO   r9   r1   r<   r   r   r   r      sS     ()15Hd38n5%%2U\\ 2%,, 2 2r   r   c                       \ rS rSr% SrSSS.r\\\4   \	S'   \
r\\	S'   \S\R                  S\R                  4S	 j5       rS
\4S jr SS\\R                     S\\R                     S
\4S jjrSrg)NegativeBinomialOutput   z.
Negative Binomial distribution output class.
rb   total_countlogitsr8   r]   r   r   c                 h    U R                  U5      nUR                  S5      UR                  S5      4$ r   )r}   r   )r   r   r   s      r   r9   !NegativeBinomialOutput.domain_map   s/    nn[1""2&r(:::r   r:   c                 z    Uu  p#U R                   S:X  a  U R                  X#S9$ [        U R                  X#S9S5      $ )Nrb   r   rc   )r   rd   r   r   s       r   re   )NegativeBinomialOutput._base_distribution   sE    (88q=**{*RRt66;6^`abbr   Nr   r   c                 X    Uu  pEUb  XSR                  5       -  nU R                  XE45      $ rF   )logre   )r   rd   r   r   r   r   s         r   ri   #NegativeBinomialOutput.distribution   s4     )iik!F&&'<==r   r<   r   )r,   r-   r.   r/   r   r8   rK   rL   rJ   r   r	   r]   r   r   rN   rO   r9   r   re   r   ri   r1   r<   r   r   r   r      s     01A>Hd38n>//;U\\ ;5<< ; ;c c _c	>'5	>EMellE[	>		> 	>r   r   )r   typingr   r   rN   r   torch.distributionsr   r   r   r	   r
   r   r   r   r   r5   rQ   r[   r   r   r   r<   r   r   <module>r      s    &    $/ $:2")) 2'")) 'J= J=ZB' B2% 2 >/  >r   