L iddlZddlmZddlZddlZddlmZddlmZddlm Z ddl m Z m Z dgZ dZgd Zgd Zgd Zgd ZeegZeegZdd Zej,j.dZGdde Zy)N)Optional)Tensor) constraints) Distribution) broadcast_all lazy_propertyVonMisescrt|}|j}|r|j||zz}|r|SN)listpop)ycoefresults c/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/torch/distributions/von_mises.py _eval_polyrs7 :D XXZF a&j(  M)g?g$ @g03@g,?N?g2t?gIx?gtHZr?) e3E?g-5?gՒ+Hub?gJNYgTPÂ?g'gZ?gUL+ߐg;^p?)?gY?g(z?g*O?gZ9?g.h?gӰ٩=5?) rg.kg?VmgtZOZ?g<Q g'8`?gP⥝gqJ:N?g;PJ4qcV|dk(s|dk(sJ|dz }||z}t|t|}|dk(r|j|z}|j}d|z }|d|jzz t|t|jz}t j |dk||}|S)zX Returns ``log(I_order(x))`` for ``x > 0``, where `order` is either 0 or 1. rg@r)r _COEF_SMALLabslog _COEF_LARGEtorchwhere)xorderrsmalllargers r_log_modified_bessel_fnr"Es A:!# # DA AA q+e, -E z% IIKE qA aeeg  1k%.@ A E E G GE [[T5% 0F Mrc6tj|jtj|j}|j stj d|jz|j|j}|j\}}}tjtj|z} d|| zz|| zz } ||| z z} | d| z z|z dkD| |z jdz| z dk\z} | jr>tj| |dz j| j!z|}|| z}|j s|tjz|zdtjzztjz S)Ndtypedevice)rrr)rzerosshapeboolr&allrandr%unbindcosmathpiranyrsignacos) loc concentration proposal_rrdoneuu1u2u3zfcaccepts r_rejection_samplerA\s< ;;qwwejj DDhhj JJtagg~SYYszz JXXZ B IIdggl # a JN 3 Z!^ ,A;#q(a"f\\^a-?!-Cq-HI ::< FR#XOO$5$@!DA&=Dhhj K# !dgg+ . 88rc reZdZdZej ej dZej ZdZ dde de de e ddffd Z d Zede fd Zede fd Zede fd Zej(ej*fdZdfd Zede fdZede fdZede fdZxZS)r aX A circular von Mises distribution. This implementation uses polar coordinates. The ``loc`` and ``value`` args can be any real number (to facilitate unconstrained optimization), but are interpreted as angles modulo 2 pi. Example:: >>> # xdoctest: +IGNORE_WANT("non-deterministic") >>> m = VonMises(torch.tensor([1.0]), torch.tensor([1.0])) >>> m.sample() # von Mises distributed with loc=1 and concentration=1 tensor([1.9777]) :param torch.Tensor loc: an angle in radians. :param torch.Tensor concentration: concentration parameter )r5r6FNr5r6 validate_argsreturnct||\|_|_|jj}t j }t ||||yr )rr5r6r*rSizesuper__init__)selfr5r6rC batch_shape event_shape __class__s rrHzVonMises.__init__sD (5S-'H$$$hhnn jjl  k=Arc |jr|j||jtj||j z z}|t jdt jzz t|jdz }|S)Nr(rr) _validate_args_validate_sampler6rr/r5r0rr1r")rIvaluelog_probs rrRzVonMises.log_probsy     ! !% (%% %$((2B(CC hhq477{# $%d&8&8B C  rcT|jjtjSr )r5tordoublerIs r_locz VonMises._locsxx{{5<<((rcT|jjtjSr )r6rTrrUrVs r_concentrationzVonMises._concentrations!!$$U\\22rc|j}ddd|dzzzjz}|d|zjz d|zz }d|dzzd|zz }d|z |z}tj|dk||S)Nrr(gh㈵>)rYsqrtrr)rIkappataurho _proposal_r_proposal_r_taylors rr`zVonMises._proposal_rs##1q5!8|#))++a#g^^%%!e)436za#g. Y.{{54<);[IIrcB|j|}tj||jj|j j }t|j|j|j|j|j jS)a The sampling algorithm for the von Mises distribution is based on the following paper: D.J. Best and N.I. Fisher, "Efficient simulation of the von Mises distribution." Applied Statistics (1979): 152-157. Sampling is always done in double precision internally to avoid a hang in _rejection_sample() for small values of the concentration, which starts to happen for single precision around 1e-4 (see issue #88443). r$) _extended_shaperemptyrWr%r5r&rArYr`rT)rI sample_shaper*rs rsamplezVonMises.samplesn$$\2 KKTYY__TXX__ M IIt**D,<,+. ." O MM--.>?M((//+.C ..55kBM4:c= N N  OsA.BBc|jS)z8 The provided mean is the circular one. r5rVs rmeanz VonMises.means xxrc|jSr rorVs rmodez VonMises.modes xxrcdt|jdt|jdz jz S)z< The provided variance is the circular one. rrNr)r"r6exprVs rvariancezVonMises.variances> '(:(:!D)$*<*rs  +9B ,  ~. ~. . 9 9n |n r