
    Z j8                        S r SSK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.
    )CallableN)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        o/root/GenerationalWealth/GenerationalWealth/venv/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   r7   r   
ModuleListvaluesLinearprojr8   )r   r6   r7   r8   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?   r8   )r   rC   r?   params_unboundeds       r   forwardParameterProjection.forwardH   s4    04		:	DG	: 011 ;s   1)r7   r8   r?   )r+   r,   r-   r.   intdictstrr   tupletorchTensorr   rG   r0   r1   r2   s   @r   r4   r4   ?   sl    %%*.sCx.%FNsTYZ_ZfZfTgOgFh%	%2 2%*= 2 2r   r4   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 rE   )r   r   function)r   rS   r   s     r   r   LambdaLayer.__init__O   s     r   c                 (    U R                   " U/UQ76 $ rE   rS   )r   rC   argss      r   rG   LambdaLayer.forwardS   s    }}Q&&&r   rV   )r+   r,   r-   r.   r   rG   r0   r1   r2   s   @r   rP   rP   N   s    !' 'r   rP   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-  S\R                  S-  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_classr6   r7   rA   r9   Nc                 |    Xl         U R                   Vs0 s H  o"XR                  U   -  _M     snU l        g s  snf rE   )rA   r7   )r   rA   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   rA   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   )rd   r   r   )r   rc   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.
ra   r;   )rA   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.
)lenrk   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.
)r6   r7   r8   )r4   r7   rP   r8   )r   r6   s     r   get_parameter_projection+DistributionOutput.get_parameter_projection   s'     ##]]"4??3
 	
r   rW   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   rW   s     r   r8   DistributionOutput.domain_map   s     "##r   rC   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      @       @)rM   r'   square)rC   s    r   
squareplusDistributionOutput.squareplus   s*     EJJu||A455<<r   )r7   rA   )ra   NN)r+   r,   r-   r.   type__annotations__rI   rJ   rK   r   rd   rM   rN   r   rh   r/   rL   rk   r   floatrq   r   Modulert   r8   staticmethodr|   r0   r;   r   r   rZ   rZ   W   s   38nKC K KH $(%)	
\ \\D 
\ ||d"	
\
 

\ 4U 4 4 %3 % % %  
C 
BII 
$ $ =ell =u|| = =r   rZ   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.
ra   )dfr   r   r7   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$ )Nrz   r|   	clamp_minrM   finfodtypeepssqueeze)clsr   r   r   s       r   r8   StudentTOutput.domain_map   sg    u%//EKK0H0L0LM3>>"%%zz"~s{{2b0AAAr   r;   N)r+   r,   r-   r.   __doc__r7   rJ   rK   rI   r   r
   r\   r   classmethodrM   rN   r8   r0   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.
ra   r*   r7   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   r8   NormalOutput.domain_map   sJ    u%//EKK0H0L0LM{{2b 111r   r;   N)r+   r,   r-   r.   r   r7   rJ   rK   rI   r   r	   r\   r   r   rM   rN   r8   r0   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-  S\R                  S-  S
\4S jjrSrg)NegativeBinomialOutput   z.
Negative Binomial distribution output class.
ra   total_countlogitsr7   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   r8   !NegativeBinomialOutput.domain_map   s/    nn[1""2&r(:::r   r9   c                 z    Uu  p#U R                   S:X  a  U R                  X#S9$ [        U R                  X#S9S5      $ )Nra   r   rb   )r   rc   r   r   s       r   rd   )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      $ rE   )logrd   )r   rc   r   r   r   r   s         r   rh   #NegativeBinomialOutput.distribution   s4     )iik!F&&'<==r   r;   r~   )r+   r,   r-   r.   r   r7   rJ   rK   rI   r   r   r\   r   r   rM   rN   r8   r   rd   rh   r0   r;   r   r   r   r      s     01A>Hd38n>//;U\\ ;5<< ; ;c c Y]	>$||d2	>BG,,QUBU	>		> 	>r   r   )r   collections.abcr   rM   r   torch.distributionsr   r   r   r   r	   r
   r   r   r   r4   rP   rZ   r   r   r   r;   r   r   <module>r      s    %    $/ $:2")) 2'")) 'J= J=ZB' B2% 2 >/  >r   