L i}lddlZddlmZmZddlZddlmZmZddlmZm Z ddl m Z dgZ Gdde Z y)N)NumberReal)infnan) constraints Distribution) broadcast_allGeneralizedParetoc2eZdZdZej ej ej dZdZdfd Z dfd Z e jfdZ dZdZd Zd Zd Zd Zed ZedZdZedZej2dddZxZS)r a Creates a Generalized Pareto distribution parameterized by :attr:`loc`, :attr:`scale`, and :attr:`concentration`. The Generalized Pareto distribution is a family of continuous probability distributions on the real line. Special cases include Exponential (when :attr:`loc` = 0, :attr:`concentration` = 0), Pareto (when :attr:`concentration` > 0, :attr:`loc` = :attr:`scale` / :attr:`concentration`), and Uniform (when :attr:`concentration` = -1). This distribution is often used to model the tails of other distributions. This implementation is based on the implementation in TensorFlow Probability. Example:: >>> # xdoctest: +IGNORE_WANT("non-deterministic") >>> m = GeneralizedPareto(torch.tensor([0.1]), torch.tensor([2.0]), torch.tensor([0.4])) >>> m.sample() # sample from a Generalized Pareto distribution with loc=0.1, scale=2.0, and concentration=0.4 tensor([ 1.5623]) Args: loc (float or Tensor): Location parameter of the distribution scale (float or Tensor): Scale parameter of the distribution concentration (float or Tensor): Concentration parameter of the distribution )locscale concentrationTc&t|||\|_|_|_t |t r5t |t r%t |t rt j}n|jj}t|)||y)N validate_args) r r r r isinstancertorchSizesizesuper__init__)selfr r rr batch_shape __class__s l/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributions/generalized_pareto.pyrzGeneralizedPareto.__init__-sn3@  4 0$*d0 sF #5&)=&1**,K((--/K MBcj|jt|}tj|}|jj ||_|j j ||_|jj ||_tt|'|d|j|_ |S)NFr) _get_checked_instancer rrr expandr rrr_validate_args)rr _instancenewrs rrzGeneralizedPareto.expand;s(():IFjj- ((//+.JJ%%k2  ..55kB .{%.P!00 rc|j|}tj||jj|jj }|j |S)N)dtypedevice)_extended_shaperrandr r$r%icdf)r sample_shapeshapeus rrsamplezGeneralizedPareto.rsampleEsB$$\2 JJuDHHNN488?? Kyy|rc |jr|j||j|}tj|j tj d}tj|tj|j |j }d|z tj|z}tj|dk(||tj||zz}t|jtrtj|jn|jj}| tj|||z S)Nr)r _validate_sample_zrisclosertensorwhere ones_likelog1prr rmathlog)rvaluezeq_zero safe_concy where_nonzero log_scales rlog_probzGeneralizedPareto.log_probJs     ! !% ( GGEN-- 2 2ELL4EFKK U__T%7%78$:L:L   MEOOA. . AFAq5;;y1}3M/MN $.tzz4$@DHHTZZ djjnnFV zEKKMBBBrc|jr|j||j|}tj|j tj d}tj|tj|j |j }tj||z |z }tj|| |S)Nr.) r r0r1rr2rr3r4r5r6)rr9r:r;r<r>s rlog_survival_functionz'GeneralizedPareto.log_survival_functionYs     ! !% ( GGEN-- 2 2ELL4EFKK U__T%7%78$:L:L Y]33i? {{7QB 66rcrtjtj|j| SN)rr6exprBrr9s rlog_cdfzGeneralizedPareto.log_cdfds({{EIId&@&@&GHHIIrcJtj|j|SrD)rrErGrFs rcdfzGeneralizedPareto.cdfgsyye,--rc|j}|j}|j}tj|tj |}tj |tj||}tj| }|||z tj| |zzz}|||zz } tj || |SrD) r r rrr2 zeros_liker4r5r6expm1) rr9r r rr;r<logur> where_zeros rr(zGeneralizedPareto.icdfjshh ** -- u/?/? /NOKK)GW {{E6"ei/%++yj4>O2PPP 54<' {{7J >>rc:||jz |jz SrD)r r )rxs rr1zGeneralizedPareto._zusDHH  **rc|j}|dk}tj||d}|j|jd|z z z}tj||t S)Nr/?)rrr4r r rrrvalidr<results rmeanzGeneralizedPareto.meanxsW** !KK}c: DJJ!i-88{{5&#..rc|j}|dk}tj||d}|jdzd|z dzdd|zz zz }tj||tS)NrRg?r/)rrr4r rrSs rvariancezGeneralizedPareto.variancese** #KK}d; Q1y=Q"6!a)m:K"LM{{5&#..rctj|j|jzdz}tj||j S)Nr/)rr8r r broadcast_to _batch_shape)ranss rentropyzGeneralizedPareto.entropys=ii #d&8&881<!!#t'8'899rc|jSrD)r )rs rmodezGeneralizedPareto.modes xxrFr) is_discrete event_dimc|j}tj|jdk||j|jz z t }t j||S)Nr)r rr4rr rrinterval)rloweruppers rsupportzGeneralizedPareto.supportsT    "EDJJ9K9K,K$KS ##E511rrD)__name__ __module__ __qualname____doc__rrealpositivearg_constraints has_rsamplerrrrr,r@rBrGrIr(r1propertyrVrYr^r`dependent_propertyrg __classcell__)rs@rr r s0%%$))O K C$.5::< C 7J. ?+////:$[##C2D2r)r7numbersrrrrrtorch.distributionsrrtorch.distributions.utilsr __all__r rrrxs/ 93  H2 H2r