
    קg                         d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZm	Z	 dgZ
d Zg dZg dZg d	Zg d
ZeegZeegZddZej        j        d             Z G d de          ZdS )    N)constraints)Distribution)broadcast_alllazy_propertyVonMisesc                     t          |          }|                                }|r|                                | |z  z   }||S N)listpop)ycoefresults      Y/var/www/html/ai-engine/env/lib/python3.11/site-packages/torch/distributions/von_mises.py
_eval_polyr      sG    ::DXXZZF
 )a&j(  )M    )g      ?g$@g03@g,?N?g2t?gIx?gtHZr?)	 e3E?g-5?gՒ+Hub?gJNYgTPÂ?g'gZ?gUL+ߐg;^p?)      ?gY?g(z?g*O?gZ9?g.h?gӰ٩=5?)	r   g.kg?VmgtZOZ?g<Q g'8`?gP⥝gqJ:N?g;PJ4qc                    |dk    s|dk    sJ | dz  }||z  }t          |t          |                   }|dk    r|                                 |z  }|                                }d| z  }| d|                                 z  z
  t          |t          |                                                   z   }t          j        | dk     ||          }|S )zX
    Returns ``log(I_order(x))`` for ``x > 0``,
    where `order` is either 0 or 1.
    r      g      @r   )r   _COEF_SMALLabslog_COEF_LARGEtorchwhere)xorderr   smalllarger   s         r   _log_modified_bessel_fnr    C   s    
 A::! 	
DA	AAq+e,--Ezz%IIKKE 	qAaeegg
1k%.@ A A E E G GGE[T5%00FMr   c                    t          j        |j        t           j        | j                  }|                                st          j        d|j        z   | j        | j                  }|                                \  }}}t          j	        t          j        |z            }	d||	z  z   ||	z   z  }
|||
z
  z  }|d|z
  z  |z
  dk    ||z                                  dz   |z
  dk    z  }|                                rEt          j        ||dz
                                  |
                                z  |          }||z  }|                                |t          j        z   | z   dt          j        z  z  t          j        z
  S )Ndtypedevice)   r      r   r   )r   zerosshapeboolr$   allrandr#   unbindcosmathpir   anyr   signacos)locconcentration
proposal_rr   doneuu1u2u3zfcaccepts                r   _rejection_sampler?   Z   sP   ;qwejDDDDhhjj 	!Jtag~SYszJJJXXZZ
BIdgl##aJN3Z!^,A;#q(a"f\\^^a-?!-Cq-HI::<< 	!FR#XOO$5$5$@!DDA&=D hhjj 	! K#!dg+.88r   c                   6    e Zd ZdZej        ej        dZej        ZdZ	d fd	Z
d Zed             Zed             Zed	             Z ej                     ej                    fd
            Z fdZed             Zed             Zed             Z xZS )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
    )r3   r4   FNc                     t          ||          \  | _        | _        | j        j        }t	          j                    }t                                          |||           d S r	   )r   r3   r4   r(   r   Sizesuper__init__)selfr3   r4   validate_argsbatch_shapeevent_shape	__class__s         r   rD   zVonMises.__init__   sR    '4S-'H'H$$$hnjllk=AAAAAr   c                     | j         r|                     |           | j        t          j        || j        z
            z  }|t          j        dt          j        z            z
  t          | j        d          z
  }|S )Nr&   r   r   )
_validate_args_validate_sampler4   r   r-   r3   r.   r   r/   r    )rE   valuelog_probs      r   rO   zVonMises.log_prob   s     	)!!%(((%	%$(2B(C(CChq47{##$%d&8BBBC 	
 r   c                 J    | j                             t          j                  S r	   )r3   tor   doublerE   s    r   _loczVonMises._loc   s    x{{5<(((r   c                 J    | j                             t          j                  S r	   )r4   rQ   r   rR   rS   s    r   _concentrationzVonMises._concentration   s    !$$U\222r   c                     | j         }ddd|dz  z  z                                   z   }|d|z                                  z
  d|z  z  }d|dz  z   d|z  z  }d|z  |z   }t          j        |dk     ||          S )Nr      r&   gh㈵>)rV   sqrtr   r   )rE   kappataurho_proposal_r_proposal_r_taylors         r   r]   zVonMises._proposal_r   s    #1q5!8|#))+++a#g^^%%%!e)436za#g.Y.{54<);[IIIr   c                     |                      |          }t          j        || j        j        | j        j                  }t          | j        | j        | j	        |          
                    | j        j                  S )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_shaper   emptyrT   r#   r3   r$   r?   rV   r]   rQ   )rE   sample_shaper(   r   s       r   samplezVonMises.sample   si     $$\22KTY_TX_MMM It*D,<a
 

"TX^

	r   c                 :   	 t                                          |          S # t          $ rl | j                            d          }| j                            |          }| j                            |          } t          |           |||          cY S w xY w)NrL   )rF   )rC   expandNotImplementedError__dict__getr3   r4   type)rE   rG   rF   r3   r4   rI   s        r   re   zVonMises.expand   s    	O77>>+..." 	O 	O 	O M--.>??M(//+..C .55kBBM4::c=NNNNNN		Os    $ A3BBc                     | j         S )z8
        The provided mean is the circular one.
        r3   rS   s    r   meanzVonMises.mean   s    
 xr   c                     | j         S r	   rk   rS   s    r   modezVonMises.mode   s	    xr   c                     dt          | j        d          t          | j        d          z
                                  z
  S )z<
        The provided variance is the circular one.
        r   rK   r   )r    r4   exprS   s    r   variancezVonMises.variance   sF     '(:!DDD)$*<AFFFGcee		
r   r	   )__name__
__module____qualname____doc__r   realpositivearg_constraintssupporthas_rsamplerD   rO   r   rT   rV   r]   r   no_gradrB   rc   re   propertyrl   rn   rq   __classcell__)rI   s   @r   r   r   j   st        " *.AUVVOGKB B B B B B	 	 	 ) ) ]) 3 3 ]3 J J ]J U]__",%*,,    _ O O O O O   X   X 

 

 ]

 

 

 

 

r   )r   )r.   r   	torch.jittorch.distributionsr    torch.distributions.distributionr   torch.distributions.utilsr   r   __all__r   _I0_COEF_SMALL_I0_COEF_LARGE_I1_COEF_SMALL_I1_COEF_LARGEr   r   r    jitscript_if_tracingr?   r    r   r   <module>r      sD         + + + + + + 9 9 9 9 9 9 B B B B B B B B ,    
 
 
  
 
 
 ~.~.   . 9 9 9i
 i
 i
 i
 i
| i
 i
 i
 i
 i
r   