L iEdZddlmZmZddlZddlmZddlmZmZm Z m Z m Z m Z m Z Gdde ZGdd ejZGd d ejZGd d ZGddeZGddeZGddeZy)z: Time series distributional output classes and utilities. )CallableOptionalN)nn)AffineTransform Distribution IndependentNegativeBinomialNormalStudentTTransformedDistributioncVeZdZddeffd ZedZedZedZxZ S)AffineTransformedbase_distributionc|dn||_|dn||_t| |t |j|j|gy)Ng?locscale event_dim)rrsuper__init__r)selfrrrr __class__s d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/time_series_utils.pyrzAffineTransformed.__init__#sE!MSu +33 *_QUQ[Q[gp-q,rscb|jj|jz|jzS)z7 Returns the mean of the distribution. ) base_distmeanrrrs rrzAffineTransformed.mean)s& ~~""TZZ/$((::rcN|jj|jdzzS)z; Returns the variance of the distribution. )rvariancerrs rr"zAffineTransformed.variance0s! ~~&&Q66rc6|jjS)zE Returns the standard deviation of the distribution. )r"sqrtrs rstddevzAffineTransformed.stddev7s }}!!##r)NNr) __name__ __module__ __qualname__rrpropertyrr"r% __classcell__rs@rrr"sMt,t ;; 77 $$rrc eZdZdedeeefdedeejfddffd Z dejdeejfd Z xZ S) ParameterProjection in_featuresargs_dim domain_map.returnNc t|di|||_tj|j Dcgc]}tj ||c}|_||_ycc}w)N) rrr/r ModuleListvaluesLinearprojr0)rr.r/r0kwargsdimrs rrzParameterProjection.__init__@sV "6"  MM(//J["\3299[##>"\] $#]sA*xch|jDcgc] }|| }}|j|Scc}wN)r7r0)rr:r7params_unboundeds rforwardzParameterProjection.forwardHs504 :DG::t 011;s/) r&r'r(intdictstrrtupletorchTensorrr>r*r+s@rr-r-?sg%%*.sCx.%FNsTYZ_ZfZfTgOgFh% %22% *=2rr-c$eZdZfdZdZxZS) LambdaLayerc0t|||_yr<)rrfunction)rrHrs rrzLambdaLayer.__init__Os   rc(|j|g|Sr<)rH)rr:argss rr>zLambdaLayer.forwardSst}}Q&&&r)r&r'r(rr>r*r+s@rrFrFNs !'rrFcdeZdZUeed<eed<eeefed<ddeddfdZdZ dd e e jd e e jde fd Zedefd Zedefd ZedefdZdedej,fdZde jfdZede jde jfdZy)DistributionOutputdistribution_classr.r/r9r1Nc|||_|jDcic]}|||j|zc}|_ycc}wr<)r9r/)rr9ks rrzDistributionOutput.__init__\s5<@MMJqC$--"222J Js9cp|jdk(r|j|St|j|dS)Nr9rMr)r distr_argss r_base_distributionz%DistributionOutput._base_distribution`s; 88q=*4**J7 76t66 CQG Grrrcb|j|}|||St||||jS)Nr)rTrr)rrSrrdistrs r distributionzDistributionOutput.distributionfs7 '' 3 ;5=L$U5DNN[ [rc>|jdk(rdS|jfS)zo Shape of each individual event contemplated by the distributions that this object constructs. rQr3)r9rs r event_shapezDistributionOutput.event_shapers XX]r3 3rc,t|jS)z Number of event dimensions, i.e., length of the `event_shape` tuple, of the distributions that this object constructs. )lenrYrs rrzDistributionOutput.event_dimys 4##$$rcy)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. rr3rs rvalue_in_supportz#DistributionOutput.value_in_supports rcXt||jt|jS)z~ Return the parameter projection layer that maps the input to the appropriate parameters of the distribution. )r.r/r0)r-r/rFr0)rr.s rget_parameter_projectionz+DistributionOutput.get_parameter_projections'##]]"4??3  rrJct)a 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)rrJs rr0zDistributionOutput.domain_maps "##rr:cd|tjtj|dzzdz 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@@)rCr$square)r:s r squarepluszDistributionOutput.squarepluss* EJJu||A455<>"% %zz"~s{{2 b0AAArN)r&r'r(__doc__r/r@rAr?rhr rMrg classmethodrCrDr0r3rrrmrmse'(A>Hd38n>''BELLBu||BELLBBrrmceZdZUdZdddZeeefed<e Z e ed<e de jde jfdZy ) NormalOutputz+ Normal distribution output class. rQ)rrr/rMrrc|j|jtj|jj }|j d|j dfSNrprq)rwrrs rr0zNormalOutput.domain_mapsJu%// EKK0H0L0LM{{2 b 111rN)r&r'r(rxr/r@rAr?rhr rMrgryrCrDr0r3rrr{r{sS()15Hd38n5%%2U\\2%,,22rr{ceZdZUdZdddZeeefed<e Z e ed<e de jde jfdZd efd Z dd ee jd ee jd efdZy )NegativeBinomialOutputz6 Negative Binomial distribution output class. rQ total_countlogitsr/rMrrch|j|}|jd|jdfSr})rerv)rwrrs rr0z!NegativeBinomialOutput.domain_maps/nn[1 ""2&r(:::rr1c|\}}|jdk(r|j||St|j||dS)NrQrrR)rrSrrs rrTz)NegativeBinomialOutput._base_distributionsL( V 88q=**{6*R Rt66;W]6^`ab brNrrc\|\}}|||jz }|j||fSr<)logrT)rrSrrrrs rrWz#NegativeBinomialOutput.distributions:) V   eiik !F&& V'<==rrf)r&r'r(rxr/r@rAr?rhr rMrgryrCrDr0rrTrrWr3rrrrs01A>Hd38n>//;U\\;5<<;;c c_c >' 5 >EMellE[ >  >rr)rxtypingrrrCrtorch.distributionsrrrr r r r rrjr-rFrLrmr{rr3rrrs& $/$: 2")) 2'"))'J=J=Z B' B 2% 2 >/ >r