L iddlmZmZddlZddlmcmZddlmZddl m Z ddl m Z ddl mZddlmZmZmZmZdgZGd de Zy) )OptionalUnionN)Tensor) constraints) Distribution)Gamma) broadcast_all lazy_propertylogits_to_probsprobs_to_logitsNegativeBinomialc eZdZdZej dej ddejdZejZ dde e e fdee d ee d eed df fd Zdfd ZdZed e fdZed e fdZed e fdZed e fdZed e fdZed ej6fdZed efdZej6fdZdZ xZ!S)r ao Creates a Negative Binomial distribution, i.e. distribution of the number of successful independent and identical Bernoulli trials before :attr:`total_count` failures are achieved. The probability of success of each Bernoulli trial is :attr:`probs`. Args: total_count (float or Tensor): non-negative number of negative Bernoulli trials to stop, although the distribution is still valid for real valued count probs (Tensor): Event probabilities of success in the half open interval [0, 1) logits (Tensor): Event log-odds for probabilities of success r?) total_countprobslogitsNrrr validate_argsreturnc|du|duk(r td|Dt||\|_|_|jj |j|_nG|Jt||\|_|_|jj |j |_| |jn |j |_|j j}t|%||y)Nz;Either `probs` or `logits` must be specified, but not both.r) ValueErrorr rrtype_asr_paramsizesuper__init__)selfrrrr batch_shape __class__s k/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributions/negative_binomial.pyrzNegativeBinomial.__init__+s TMv~ .M   k51   #//77 CD % %%k62   #//77 DD $)$5djj4;; kk&&(  MBc|jt|}tj|}|jj ||_d|j vr1|jj ||_|j|_d|j vr1|jj ||_ |j|_tt|/|d|j|_ |S)NrrFr) _get_checked_instancer torchSizerexpand__dict__rrrrr_validate_args)rr _instancenewr s r!r'zNegativeBinomial.expandHs(()99Ejj- **11+> dmm # ))+6CICJ t}} $++K8CJCJ -k-O!00 r"c:|jj|i|SN)rr+)rargskwargss r!_newzNegativeBinomial._newVst{{///r"cZ|jtj|jzSr-)rr%exprrs r!meanzNegativeBinomial.meanYs %))DKK"888r"c|jdz |jjzjj dS)Nr)min)rrr2floorclampr3s r!modezNegativeBinomial.mode]s:!!A%)::AACIIcIRRr"c\|jtj|j z Sr-)r4r%sigmoidrr3s r!variancezNegativeBinomial.varianceas yy5==$++666r"c0t|jdSNT) is_binary)r rr3s r!rzNegativeBinomial.logitsestzzT::r"c0t|jdSr?)r rr3s r!rzNegativeBinomial.probsist{{d;;r"c6|jjSr-)rrr3s r! param_shapezNegativeBinomial.param_shapems{{!!r"cnt|jtj|j dS)NF) concentrationrater)rrr%r2rr3s r!_gammazNegativeBinomial._gammaqs/**DKK<(  r"ctj5|jj|}tj|cdddS#1swYyxYw)N) sample_shape)r%no_gradrGsamplepoisson)rrIrFs r!rKzNegativeBinomial.samplezsC ]]_ ';;%%<%@D==& ' ' 's 1AAc|jr|j||jtj|j z|tj|j zz}t j|j|z t jd|zzt j|jz}|j|j|zdk(d}||z S)Nrr) r)_validate_samplerF logsigmoidrr%lgamma masked_fill)rvaluelog_unnormalized_problog_normalizations r!log_probzNegativeBinomial.log_probs     ! !% ( $ 0 01<< [[L4 ! ALL- -!. \\$**U2 3 3ll3;' (ll4++, - .99   u $ +S %'888r")NNNr-)"__name__ __module__ __qualname____doc__rgreater_than_eqhalf_open_intervalrealarg_constraintsnonnegative_integersupportrrfloatrboolrr'r0propertyr4r:r=r rrr%r&rCrrGrKrV __classcell__)r s@r!r r s 3{2215///S9""O --G #'#'(, C65=)CC C  ~ C  C: 09f99SfSS7&77;;;ros?" +9+  ~9|~9r"