+
    –°³j""  ã                   ó^   € ^ RI t ^ RI Ht ^ RIHtHt ^ RIHt ^ RIHt R.t	 ! R R]4      t
R# )é    N©ÚTensor)ÚCategoricalÚconstraints)ÚMixtureSameFamilyConstraint©ÚDistributionÚMixtureSameFamilyc                   óF  a a€ ] tR t^t oRt/ tRtRV3R lV 3R llltRV 3R llt]	P                  R 4       t]V3R lR l4       t]V3R	 lR
 l4       t]V3R lR l4       t]V3R lR l4       tR tR t]P(                  ! 4       3R ltR tR tR tV3R ltRtVtV ;t# )r
   a>  
The `MixtureSameFamily` distribution implements a (batch of) mixture
distribution where all components are from different parameterizations of
the same distribution type. It is parameterized by a `Categorical`
"selecting distribution" (over `k` components) and a component
distribution, i.e., a `Distribution` with a rightmost batch shape
(equal to `[k]`) which indexes each (batch of) component.

Examples::

    >>> # xdoctest: +SKIP("undefined vars")
    >>> # Construct Gaussian Mixture Model in 1D consisting of 5 equally
    >>> # weighted normal distributions
    >>> mix = D.Categorical(torch.ones(5,))
    >>> comp = D.Normal(torch.randn(5,), torch.rand(5,))
    >>> gmm = MixtureSameFamily(mix, comp)

    >>> # Construct Gaussian Mixture Model in 2D consisting of 5 equally
    >>> # weighted bivariate normal distributions
    >>> mix = D.Categorical(torch.ones(5,))
    >>> comp = D.Independent(D.Normal(
    ...          torch.randn(5,2), torch.rand(5,2)), 1)
    >>> gmm = MixtureSameFamily(mix, comp)

    >>> # Construct a batch of 3 Gaussian Mixture Models in 2D each
    >>> # consisting of 5 random weighted bivariate normal distributions
    >>> mix = D.Categorical(torch.rand(3,5))
    >>> comp = D.Independent(D.Normal(
    ...         torch.randn(3,5,2), torch.rand(3,5,2)), 1)
    >>> gmm = MixtureSameFamily(mix, comp)

Args:
    mixture_distribution: `torch.distributions.Categorical`-like
        instance. Manages the probability of selecting components.
        The number of categories must match the rightmost batch
        dimension of the `component_distribution`. Must have either
        scalar `batch_shape` or `batch_shape` matching
        `component_distribution.batch_shape[:-1]`
    component_distribution: `torch.distributions.Distribution`-like
        instance. Right-most batch dimension indexes component.
Fc                ó>   <€ V ^8„  d   QhRS[ RS[RS[R,          RR/# )é   Úmixture_distributionÚcomponent_distributionÚvalidate_argsNÚreturn)r   r	   Úbool)ÚformatÚ__classdict__s   "€Úh/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributions/mixture_same_family.pyÚ__annotate__ÚMixtureSameFamily.__annotate__;   s7   ø€ ÷ 2
ñ 2
á)ð2
ñ !-ð2
ñ ˜d•{ð	2
ð
 
ñ2
ó    c                ó  <€ Wn         W n        \        V P                   \        4      '       g   \	        R 4      h\        V P                  \
        4      '       g   \	        R4      hV P                   P                  pV P                  P                  RR	 p\        \        V4      \        V4      4       F/  w  rgV^8w  g   K  V^8w  g   K  Wg8w  g   K  \	        RV RV R24      h	  V P                   P                  P                  R	,          pV P                  P                  R	,          p	Ve   V	e   W‰8w  d   \	        RV RV	 R24      hW€n        V P                  P                  p
\        V
4      V n        \        SV `A  VV
VR7       R# )
zU The Mixture distribution needs to be an  instance of torch.distributions.CategoricalzVThe Component distribution needs to be an instance of torch.distributions.DistributionNz$`mixture_distribution.batch_shape` (z>) is not compatible with `component_distribution.batch_shape`(Ú)z"`mixture_distribution component` (z;) does not equal `component_distribution.batch_shape[-1]` (©Úbatch_shapeÚevent_shaper   éÿÿÿÿ)Ú_mixture_distributionÚ_component_distributionÚ
isinstancer   Ú
ValueErrorr	   r   ÚzipÚreversedÚlogitsÚshapeÚ_num_componentr   ÚlenÚ_event_ndimsÚsuperÚ__init__)Úselfr   r   r   ÚmdbsÚcdbsÚsize1Úsize2ÚkmÚkcr   Ú	__class__s   &&&&       €r   r+   ÚMixtureSameFamily.__init__;   s‚  ø€ ð &:Ô"Ø'=Ô$ä˜$×4Ñ4´k×BÒBÜð?óð ô
 ˜$×6Ñ6¼×EÒEÜð?óð ð ×)Ñ)×5Ñ5ˆØ×+Ñ+×7Ñ7¸¸Ð<ˆÜ¤¨£´¸³Ö?‰LˆEØ˜Žz˜e qžj¨U®^Ü Ø:¸4¸&ð A$à$( 6¨ð,óð ñ @ð ×'Ñ'×.Ñ.×4Ñ4°RÕ8ˆØ×)Ñ)×5Ñ5°bÕ9ˆØŠ>˜bšn°´ÜØ4°R°Dð 9à�D˜ðóð ð
 !Ôà×2Ñ2×>Ñ>ˆÜ Ó,ˆÔÜ‰ÑàØ#Ø'ð	 	ö 	
r   c                óÂ  <€ \         P                  ! V4      pWP                  3,           pV P                  \        V4      pV P
                  P                  V4      Vn        V P                  P                  V4      Vn        V P                  Vn        V P                  Vn        VP
                  P                  p\        \        V`/  WR R7       V P                  Vn        V# )Fr   )ÚtorchÚSizer'   Ú_get_checked_instancer
   r    Úexpandr   r)   r   r*   r+   Ú_validate_args)r,   r   Ú	_instanceÚbatch_shape_compÚnewr   r3   s   &&&   €r   r9   ÚMixtureSameFamily.expando   sÉ   ø€ Ü—j’j Ó-ˆØ&×*=Ñ*=Ð)?Õ?ÐØ×(Ñ(Ô):¸IÓFˆØ&*×&BÑ&B×&IÑ&IØó'
ˆÔ#ð %)×$>Ñ$>×$EÑ$EÀkÓ$RˆÔ!Ø!×0Ñ0ˆÔØ×,Ñ,ˆÔØ×1Ñ1×=Ñ=ˆÜÔ Ñ.Ø#ÈEð 	/ô 	
ð "×0Ñ0ˆÔØˆ
r   c                ó@   € \        V P                  P                  4      # ©N)r   r    Úsupport©r,   s   &r   rA   ÚMixtureSameFamily.support€   s   € ô +¨4×+GÑ+G×+OÑ+OÓPÐPr   c                ó    <€ V ^8„  d   QhRS[ /# ©r   r   )r   )r   r   s   "€r   r   r   †   s   ø€ ÷ *ñ *¡kñ *r   c                ó   € V P                   # r@   )r   rB   s   &r   r   Ú&MixtureSameFamily.mixture_distribution…   s   € à×)Ñ)Ð)r   c                ó    <€ V ^8„  d   QhRS[ /# rE   r   )r   r   s   "€r   r   r   Š   s   ø€ ÷ ,ñ ,©ñ ,r   c                ó   € V P                   # r@   )r    rB   s   &r   r   Ú(MixtureSameFamily.component_distribution‰   s   € à×+Ñ+Ð+r   c                ó    <€ V ^8„  d   QhRS[ /# rE   r   )r   r   s   "€r   r   r   Ž   s   ø€ ÷ 
ñ 
‘fñ 
r   c                óÒ   € V P                  V P                  P                  4      p\        P                  ! WP
                  P                  ,          RV P                  ,
          R7      # ©é   ©Údimr   )Ú_pad_mixture_dimensionsr   Úprobsr6   Úsumr   Úmeanr)   )r,   rR   s   & r   rT   ÚMixtureSameFamily.mean�   sN   € à×,Ñ,¨T×-FÑ-F×-LÑ-LÓMˆÜ�yŠyØ×/Ñ/×4Ñ4Õ4¸"¸t×?PÑ?PÕ:Pô
ð 	
r   c                ó    <€ V ^8„  d   QhRS[ /# rE   r   )r   r   s   "€r   r   r   •   s   ø€ ÷ 
-ñ 
-™&ñ 
-r   c                óÆ  € V P                  V P                  P                  4      p\        P                  ! WP
                  P                  ,          RV P                  ,
          R7      p\        P                  ! WP
                  P                  V P                  V P                  4      ,
          P                  R4      ,          RV P                  ,
          R7      pW#,           # )rN   rO   g       @r   )rQ   r   rR   r6   rS   r   Úvariancer)   rT   Ú_padÚpow)r,   rR   Úmean_cond_varÚvar_cond_means   &   r   rX   ÚMixtureSameFamily.variance”   s¦   € ð ×,Ñ,¨T×-FÑ-F×-LÑ-LÓMˆÜŸ	š	Ø×/Ñ/×8Ñ8Õ8¸bÀ4×CTÑCTÕ>Tô
ˆô Ÿ	š	Ø×0Ñ0×5Ñ5¸¿	¹	À$Ç)Á)Ó8LÕL×QÑQÐRUÓVÕVØ�T×&Ñ&Õ&ô
ˆð Õ,Ð,r   c                óÂ   € V P                  V4      pV P                  P                  V4      pV P                  P                  p\
        P                  ! W#,          RR7      # rM   )rY   r   Úcdfr   rR   r6   rS   )r,   ÚxÚcdf_xÚmix_probs   &&  r   r_   ÚMixtureSameFamily.cdf¡   sJ   € Ø�I‰I�a‹LˆØ×+Ñ+×/Ñ/°Ó2ˆØ×,Ñ,×2Ñ2ˆä�yŠy˜Õ)¨rÔ2Ð2r   c                ó4  € V P                   '       d   V P                  V4       V P                  V4      pV P                  P	                  V4      p\
        P                  ! V P                  P                  RR7      p\
        P                  ! W#,           RR7      # rM   )
r:   Ú_validate_samplerY   r   Úlog_probr6   Úlog_softmaxr   r%   Ú	logsumexp)r,   r`   Ú
log_prob_xÚlog_mix_probs   &&  r   rf   ÚMixtureSameFamily.log_prob¨   sv   € Ø××ÐØ×!Ñ! !Ô$Ø�I‰I�a‹LˆØ×0Ñ0×9Ñ9¸!Ó<ˆ
Ü×(Ò(Ø×%Ñ%×,Ñ,°"ô
ˆô �Š˜zÕ8¸bÔAÐAr   c                óð  € \         P                  ! 4       ;_uu_ 4        \        V4      p\        V P                  4      pW#,           pV P                  pV P
                  P                  V4      pVP                  pV P                  P                  V4      pVP                  V\         P                  ! ^.\        V4      ^,           ,          4      ,           4      p	V	P                  \         P                  ! ^.\        V4      ,          4      \         P                  ! ^.4      ,           V,           4      p	\         P                  ! W„V	4      p
V
P                  V4      uuRRR4       #   + '       g   i     R# ; i)rN   N)r6   Úno_gradr(   r   r   r   Úsampler&   r   Úreshaper7   ÚrepeatÚgatherÚsqueeze)r,   Úsample_shapeÚ
sample_lenÚ	batch_lenÚ
gather_dimÚesÚ
mix_sampleÚ	mix_shapeÚcomp_samplesÚmix_sample_rÚsampless   &&         r   rn   ÚMixtureSameFamily.sample²   s  € Ü�]Š]�_�_Ü˜\Ó*ˆJÜ˜D×,Ñ,Ó-ˆIØ#Õ/ˆJØ×!Ñ!ˆBð ×2Ñ2×9Ñ9¸,ÓGˆJØ"×(Ñ(ˆIð  ×6Ñ6×=Ñ=¸lÓKˆLð &×-Ñ-ØœEŸJšJ¨ s¬c°"«g¸­kÕ':Ó;Õ;óˆLð (×.Ñ.Ü—
’
˜A˜3¤ Y£Õ/Ó0´5·:²:¸q¸c³?ÕBÀRÕGóˆLô —l’l <¸\ÓJˆGØ—?‘? :Ó.÷- �_�_‹_ús   žD;E$Å$E5	c                óF   € VP                  RV P                  ,
          4      # )rN   r   )Ú	unsqueezer)   )r,   r`   s   &&r   rY   ÚMixtureSameFamily._padË   s   € Ø�{‰{˜2 × 1Ñ 1Õ1Ó2Ð2r   c                ó„  € \        V P                  4      p\        V P                  P                  4      pV^8X  d   ^ MW#,
          pVP                  pVP	                  VRR \
        P                  ! V^.,          4      ,           VRR ,           \
        P                  ! V P                  ^.,          4      ,           4      pV# )rN   Nr   )r(   r   r   r&   ro   r6   r7   r)   )r,   r`   Údist_batch_ndimsÚcat_batch_ndimsÚ	pad_ndimsÚxss   &&    r   rQ   Ú)MixtureSameFamily._pad_mixture_dimensionsÎ   s§   € Ü˜t×/Ñ/Ó0ÐÜ˜d×7Ñ7×CÑCÓDˆØ(¨AÔ-‘AÐ3CÕ3Uˆ	Ø�W‰WˆØ�I‰IØˆs�ˆGÜ�jŠj˜ a S�Ó)õ*à��ˆgõô �jŠj˜×*Ñ*¨a¨SÕ0Ó1õ2ó
ˆð ˆr   c                óZ   € R V P                    RV P                   2pRV,           R,           # )z
  z,
  r   zMixtureSameFamily()r   r   )r,   Úargs_strings   & r   Ú__repr__ÚMixtureSameFamily.__repr__Û   s7   € à�4×,Ñ,Ð-¨U°4×3NÑ3NÐ2OÐPð 	ð )¨;Õ6¸Õ<Ð<r   c                óP   <€ V ^8„  d   Qh/ S[ S[S[P                  3,          ;R&   # )r   Úarg_constraints)ÚdictÚstrr   Ú
Constraint)r   r   s   "€r   r   r      s$   ø‡ ‚ ñV ™#™{×5Ñ5Ð5Õ6Ñ;òW r   )r    r)   r   r'   r@   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rŒ   Úhas_rsampler+   r9   r   Údependent_propertyrA   Úpropertyr   r   rT   rX   r_   rf   r6   r7   rn   rY   rQ   r‰   Ú__annotate_func__Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r3   r   s   @@r   r
   r
      sÅ   ù‡ € ñ(ðT :<€OØ€K÷2
õ 2
÷hð" ×#Ñ#ñQó $ðQð ÷*ó ð*ð ÷,ó ð,ð ÷
ó ð
ð ÷
-ó ð
-ò3òBð #(§*¢*£,ô /ò23òò=÷] … r   )r6   r   Útorch.distributionsr   r   Útorch.distributions.constraintsr   Ú torch.distributions.distributionr	   Ú__all__r
   © r   r   Ú<module>r¡      s.   ðó Ý ß 8Ý GÝ 9ð Ð
€ôR=˜ö R=r   