
    [ThB(                        S r SSKJrJr  SSKJr  / SQr " S S5      r\" 5       r\" 5       r	\R                  \R                  5      \	R                  \R                  5      S 5       5       r\R                  \R                  5      S 5       r\	R                  \R                  5      S	 5       r\R                  \R                   5      \R                  \R"                  5      \	R                  \R                   5      \	R                  \R"                  5      S
 5       5       5       5       r\R                  \R&                  5      \R                  \R(                  5      \	R                  \R&                  5      \	R                  \R(                  5      S 5       5       5       5       r\R                  \R,                  5      \	R                  \R,                  5      S 5       5       r\R                  \R0                  5      \R                  \R2                  5      \	R                  \R0                  5      \	R                  \R2                  5      S 5       5       5       5       r\R                  \R6                  5      S 5       r\	R                  \R6                  5      S 5       r\	R                  \R<                  5      S 5       r\	R                  \R@                  5      \	R                  \RB                  5      S 5       5       r"\R                  \RF                  5      \	R                  \RF                  5      S 5       5       r$\R                  \RJ                  5      S 5       r&\	R                  \RJ                  5      S 5       r'\R                  \RP                  5      S 5       r)\	R                  \RP                  5      S 5       r*g)aF  
PyTorch provides two global :class:`ConstraintRegistry` objects that link
:class:`~torch.distributions.constraints.Constraint` objects to
:class:`~torch.distributions.transforms.Transform` objects. These objects both
input constraints and return transforms, but they have different guarantees on
bijectivity.

1. ``biject_to(constraint)`` looks up a bijective
   :class:`~torch.distributions.transforms.Transform` from ``constraints.real``
   to the given ``constraint``. The returned transform is guaranteed to have
   ``.bijective = True`` and should implement ``.log_abs_det_jacobian()``.
2. ``transform_to(constraint)`` looks up a not-necessarily bijective
   :class:`~torch.distributions.transforms.Transform` from ``constraints.real``
   to the given ``constraint``. The returned transform is not guaranteed to
   implement ``.log_abs_det_jacobian()``.

The ``transform_to()`` registry is useful for performing unconstrained
optimization on constrained parameters of probability distributions, which are
indicated by each distribution's ``.arg_constraints`` dict. These transforms often
overparameterize a space in order to avoid rotation; they are thus more
suitable for coordinate-wise optimization algorithms like Adam::

    loc = torch.zeros(100, requires_grad=True)
    unconstrained = torch.zeros(100, requires_grad=True)
    scale = transform_to(Normal.arg_constraints["scale"])(unconstrained)
    loss = -Normal(loc, scale).log_prob(data).sum()

The ``biject_to()`` registry is useful for Hamiltonian Monte Carlo, where
samples from a probability distribution with constrained ``.support`` are
propagated in an unconstrained space, and algorithms are typically rotation
invariant.::

    dist = Exponential(rate)
    unconstrained = torch.zeros(100, requires_grad=True)
    sample = biject_to(dist.support)(unconstrained)
    potential_energy = -dist.log_prob(sample).sum()

.. note::

    An example where ``transform_to`` and ``biject_to`` differ is
    ``constraints.simplex``: ``transform_to(constraints.simplex)`` returns a
    :class:`~torch.distributions.transforms.SoftmaxTransform` that simply
    exponentiates and normalizes its inputs; this is a cheap and mostly
    coordinate-wise operation appropriate for algorithms like SVI. In
    contrast, ``biject_to(constraints.simplex)`` returns a
    :class:`~torch.distributions.transforms.StickBreakingTransform` that
    bijects its input down to a one-fewer-dimensional space; this a more
    expensive less numerically stable transform but is needed for algorithms
    like HMC.

The ``biject_to`` and ``transform_to`` objects can be extended by user-defined
constraints and transforms using their ``.register()`` method either as a
function on singleton constraints::

    transform_to.register(my_constraint, my_transform)

or as a decorator on parameterized constraints::

    @transform_to.register(MyConstraintClass)
    def my_factory(constraint):
        assert isinstance(constraint, MyConstraintClass)
        return MyTransform(constraint.param1, constraint.param2)

You can create your own registry by creating a new :class:`ConstraintRegistry`
object.
    )constraints
transforms)_Number)ConstraintRegistry	biject_totransform_toc                   <   ^  \ rS rSrSrU 4S jrSS jrS rSrU =r	$ )r   P   z-
Registry to link constraints to transforms.
c                 0   > 0 U l         [        TU ]	  5         g N)	_registrysuper__init__)self	__class__s    _/var/www/auris/envauris/lib/python3.13/site-packages/torch/distributions/constraint_registry.pyr   ConstraintRegistry.__init__U   s        c                   ^ ^ Uc  UU 4S j$ [        T[        R                  5      (       a  [        T5      m[        T[        5      (       a  [	        T[        R                  5      (       d  [        ST 35      eUT R                  T'   U$ )a  
Registers a :class:`~torch.distributions.constraints.Constraint`
subclass in this registry. Usage::

    @my_registry.register(MyConstraintClass)
    def construct_transform(constraint):
        assert isinstance(constraint, MyConstraint)
        return MyTransform(constraint.arg_constraints)

Args:
    constraint (subclass of :class:`~torch.distributions.constraints.Constraint`):
        A subclass of :class:`~torch.distributions.constraints.Constraint`, or
        a singleton object of the desired class.
    factory (Callable): A callable that inputs a constraint object and returns
        a  :class:`~torch.distributions.transforms.Transform` object.
c                 (   > TR                  TU 5      $ r   )register)factory
constraintr   s    r   <lambda>-ConstraintRegistry.register.<locals>.<lambda>l   s    4==W#Er   zLExpected constraint to be either a Constraint subclass or instance, but got )
isinstancer   
Constrainttype
issubclass	TypeErrorr   r   r   r   s   `` r   r   ConstraintRegistry.registerY   s    $ ?EE j+"8"899j)J*d++:..4
 4
 ^_i^jk  &-z"r   c                      U R                   [        U5         nU" U5      $ ! [         a$    [        S[        U5      R                   S35      Sef = f)a   
Looks up a transform to constrained space, given a constraint object.
Usage::

    constraint = Normal.arg_constraints["scale"]
    scale = transform_to(constraint)(torch.zeros(1))  # constrained
    u = transform_to(constraint).inv(scale)  # unconstrained

Args:
    constraint (:class:`~torch.distributions.constraints.Constraint`):
        A constraint object.

Returns:
    A :class:`~torch.distributions.transforms.Transform` object.

Raises:
    `NotImplementedError` if no transform has been registered.
zCannot transform z constraintsN)r   r   KeyErrorNotImplementedError__name__r!   s      r   __call__ConstraintRegistry.__call__|   s`    (	nnT*%56G
 z""	  	%#D$4$=$=#>lK	s	   " .A)r   r   )
r&   
__module____qualname____firstlineno____doc__r   r   r'   __static_attributes____classcell__)r   s   @r   r   r   P   s    !F# #r   r   c                 "    [         R                  $ r   )r   identity_transformr   s    r   _transform_to_realr2      s     (((r   c                 l    [        U R                  5      n[        R                  " XR                  5      $ r   )r   base_constraintr   IndependentTransformreinterpreted_batch_ndimsr   base_transforms     r   _biject_to_independentr9      s.    z99:N**<< r   c                 l    [        U R                  5      n[        R                  " XR                  5      $ r   )r   r4   r   r5   r6   r7   s     r   _transform_to_independentr;      s.    !*"<"<=N**<< r   c                 ,    [         R                  " 5       $ r   )r   ExpTransformr1   s    r   _transform_to_positiver>      s    
 ""$$r   c                     [         R                  " [         R                  " 5       [         R                  " U R                  S5      /5      $ )N   )r   ComposeTransformr=   AffineTransformlower_boundr1   s    r   _transform_to_greater_thanrD      s>    
 &&##%&&z'='=qA	
 r   c                     [         R                  " [         R                  " 5       [         R                  " U R                  S5      /5      $ )N)r   rA   r=   rB   upper_boundr1   s    r   _transform_to_less_thanrH      s>     &&##%&&z'='=rB	
 r   c                    [        U R                  [        5      =(       a    U R                  S:H  n[        U R                  [        5      =(       a    U R                  S:H  nU(       a  U(       a  [        R
                  " 5       $ U R                  nU R                  U R                  -
  n[        R                  " [        R
                  " 5       [        R                  " X45      /5      $ )Nr   r@   )r   rC   r   rG   r   SigmoidTransformrA   rB   )r   
lower_is_0
upper_is_1locscales        r   _transform_to_intervalrO      s     	:))73S
8N8NRS8S  	:))73S
8N8NRS8S  j**,,

 
 C""Z%;%;;E&&		$	$	&
(B(B3(NO r   c                 ,    [         R                  " 5       $ r   )r   StickBreakingTransformr1   s    r   _biject_to_simplexrR          ,,..r   c                 ,    [         R                  " 5       $ r   )r   SoftmaxTransformr1   s    r   _transform_to_simplexrV      s    &&((r   c                 ,    [         R                  " 5       $ r   )r   LowerCholeskyTransformr1   s    r   _transform_to_lower_choleskyrY      rS   r   c                 ,    [         R                  " 5       $ r   )r   PositiveDefiniteTransformr1   s    r   _transform_to_positive_definiter\      s     //11r   c                 ,    [         R                  " 5       $ r   )r   CorrCholeskyTransformr1   s    r   _transform_to_corr_choleskyr_     s     ++--r   c                     [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  U R
                  5      $ s  snf r   )r   CatTransformcseqr   dimlengthsr   cs     r   _biject_to_catrg   
  s@    "")/!1/ASAS /   Ac                     [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  U R
                  5      $ s  snf r   )r   ra   rb   r   rc   rd   re   s     r   _transform_to_catrj     s@    """,//2/Qa/2JNNJDVDV 2rh   c                     [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  5      $ s  snf r   )r   StackTransformrb   r   rc   re   s     r   _biject_to_stackrm     s8    $$)/!1/ /   Ac                     [         R                  " U R                   Vs/ s H  n[        U5      PM     snU R                  5      $ s  snf r   )r   rl   rb   r   rc   re   s     r   _transform_to_stackrp     s8    $$",//2/Qa/2JNN 2rn   N)+r,   torch.distributionsr   r   torch.typesr   __all__r   r   r   r   realr2   independentr9   r;   positivenonnegativer>   greater_thangreater_than_eqrD   	less_thanrH   intervalhalf_open_intervalrO   simplexrR   rV   lower_choleskyrY   positive_definitepositive_semidefiniter\   corr_choleskyr_   catrg   rj   stackrm   rp    r   r   <module>r      s  AF 8 F# F#R  	!# K$$%{''() ) &) K++, - {../ 0 K(()
K++,{++,{../% 0 - - *% K,,-
K//0{//0{223 4 1 1 . K))*{,,- . + K(()
K223{++,{556 7 - 4 *$ K''(/ )/ {**+) ,)
 {112/ 3/ {445{8892 : 62 K--.{001. 2 /. KOO$ % {' ( K%%& ' {(() *r   