+
    –°³j–  ã                   ój   € R t ^ RIt^ 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# )zÍ
This closely follows the implementation in NumPyro (https://github.com/pyro-ppl/numpyro).

Original copyright notice:

# Copyright: Contributors to the Pyro project.
# SPDX-License-Identifier: Apache-2.0
N)ÚTensor)ÚBetaÚconstraints)ÚDistribution)Úbroadcast_allÚLKJCholeskyc                   óº   a a€ ] tR t^t oRtR]P                  /t]P                  t	R	V3R lV 3R lllt
R
V 3R llt]P                  ! 4       3R ltR tRtVtV ;t# )r   aµ  
LKJ distribution for lower Cholesky factor of correlation matrices.
The distribution is controlled by ``concentration`` parameter :math:`\eta`
to make the probability of the correlation matrix :math:`M` generated from
a Cholesky factor proportional to :math:`\det(M)^{\eta - 1}`. Because of that,
when ``concentration == 1``, we have a uniform distribution over Cholesky
factors of correlation matrices::

    L ~ LKJCholesky(dim, concentration)
    X = L @ L' ~ LKJCorr(dim, concentration)

Note that this distribution samples the
Cholesky factor of correlation matrices and not the correlation matrices
themselves and thereby differs slightly from the derivations in [1] for
the `LKJCorr` distribution. For sampling, this uses the Onion method from
[1] Section 3.

Example::

    >>> # xdoctest: +IGNORE_WANT("non-deterministic")
    >>> l = LKJCholesky(3, 0.5)
    >>> l.sample()  # l @ l.T is a sample of a correlation 3x3 matrix
    tensor([[ 1.0000,  0.0000,  0.0000],
            [ 0.3516,  0.9361,  0.0000],
            [-0.1899,  0.4748,  0.8593]])

Args:
    dimension (dim): dimension of the matrices
    concentration (float or Tensor): concentration/shape parameter of the
        distribution (often referred to as eta)

**References**

[1] `Generating random correlation matrices based on vines and extended onion method` (2009),
Daniel Lewandowski, Dorota Kurowicka, Harry Joe.
Journal of Multivariate Analysis. 100. 10.1016/j.jmva.2009.04.008
Úconcentrationc                óN   <€ V ^8„  d   QhRS[ RS[S[,          RS[R,          RR/# )é   Údimr	   Úvalidate_argsNÚreturn)Úintr   ÚfloatÚbool)ÚformatÚ__classdict__s   "€Úa/home/luca/screen-checking/.venv/lib/python3.14/site-packages/torch/distributions/lkj_cholesky.pyÚ__annotate__ÚLKJCholesky.__annotate__B   sA   ø€ ÷ Bñ BáðBñ ¡•~ðBñ ˜d•{ð	Bð
 
ñBó    c                óž  <€ V^8  d   \        RV R24      hWn        \        V4      w  V n        V P                  P	                  4       p\
        P                  ! W34      pV P                  RV P                  ^,
          ,          ,           p\
        P                  ! V P                  ^,
          V P                  P                  V P                  P                  R7      p\
        P                  ! VP                  R4      V.4      pVR,           pVP                  R4      RV,          ,
          p	\        W‰4      V n        \        S
V `A  WEV4       R# )r   zDExpected dim to be an integer greater than or equal to 2. Found dim=Ú.ç      à?©ÚdtypeÚdeviceN)é   éÿÿÿÿ)Ú
ValueErrorr   r   r	   ÚsizeÚtorchÚSizeÚaranger   r   ÚcatÚ	new_zerosÚ	unsqueezer   Ú_betaÚsuperÚ__init__)Úselfr   r	   r   Úbatch_shapeÚevent_shapeÚmarginal_concÚoffsetÚ
beta_conc1Ú
beta_conc0Ú	__class__s   &&&&      €r   r*   ÚLKJCholesky.__init__B   s  ø€ ð �Œ7ÜØVÐWZÐV[Ð[\Ð]óð ð ŒÜ -¨mÓ <ÑˆÔ	Ø×(Ñ(×-Ñ-Ó/ˆÜ—j’j # Ó,ˆà×*Ñ*¨S°D·H±H¸qµLÕ-AÕAˆÜ—’Ø�H‰H�q�LØ×$Ñ$×*Ñ*Ø×%Ñ%×,Ñ,ô
ˆô
 —’˜F×,Ñ,¨TÓ2°FÐ;Ó<ˆØ˜c•\ˆ
Ø"×,Ñ,¨RÓ0°3¸µ<Õ?ˆ
Ü˜*Ó1ˆŒ
Ü‰Ñ˜°=ÖAr   c                ó„  <€ V P                  \        V4      p\        P                  ! V4      pV P                  Vn        V P
                  P                  V4      Vn        V P                  P                  WP                  3,           4      Vn        \        \        V`'  WP                  R R7       V P                  Vn        V# )F)r   )Ú_get_checked_instancer   r"   r#   r   r	   Úexpandr(   r)   r*   r-   Ú_validate_args)r+   r,   Ú	_instanceÚnewr2   s   &&& €r   r6   ÚLKJCholesky.expand]   sš   ø€ Ø×(Ñ(¬°iÓ@ˆÜ—j’j Ó-ˆØ—(‘(ˆŒØ ×.Ñ.×5Ñ5°kÓBˆÔØ—J‘J×%Ñ% k·X±X°KÕ&?Ó@ˆŒ	ÜŒk˜3Ñ(Ø×)Ñ)¸ð 	)ô 	
ð "×0Ñ0ˆÔØˆ
r   c                ó®  € V P                   P                  V4      P                  R4      p\        P                  ! V P                  V4      VP                  VP                  R7      P                  R4      pW3P                  RRR7      ,          pVR,          P                  R4       \        P                  ! V4      V,          p\        P                  ! VP                  4      P                  p\        P                  ! ^\        P                  ! V^,          RR7      ,
          VR7      P                  4       pV\        P                   ! V4      ,          pV# )	r   r   T)r   Úkeepdimg        ©r   )Úminr   ).é    :NNN)r(   Úsampler'   r"   ÚrandnÚ_extended_shaper   r   ÚtrilÚnormÚfill_ÚsqrtÚfinfoÚtinyÚclampÚsumÚ
diag_embed)r+   Úsample_shapeÚyÚu_normalÚu_hypersphereÚwÚepsÚ
diag_elemss   &&      r   r@   ÚLKJCholesky.samplei   sò   € ð �J‰J×Ñ˜lÓ+×5Ñ5°bÓ9ˆÜ—;’;Ø× Ñ  Ó.°a·g±gÀaÇhÁhô
ç
‰$ˆr‹(ð 	ð !§=¡=°RÀ =Ó#FÕFˆà�iÕ ×&Ñ& sÔ+Ü�JŠJ�q‹M˜MÕ)ˆä�kŠk˜!Ÿ'™'Ó"×'Ñ'ˆÜ—[’[ ¤U§Y¢Y¨q°!­t¸Ô%<Õ!<À#ÔF×KÑKÓMˆ
Ø	ŒU×Ò˜jÓ)Õ)ˆØˆr   c                ó4  € V P                   '       d   V P                  V4       VP                  RRR7      R,          p\        P                  ! ^V P
                  ^,           V P                  P                  R7      p^V P                  ^,
          P                  R4      ,          V P
                  ,           V,
          p\        P                  ! W2P                  4       ,          RR7      pV P
                  ^,
          pV P                  RV,          ,           p\        P                  ! V4      V,          p\        P                  ! VR,
          V4      pRV,          \        P                  ! \        P                  4      ,          p	W˜,           V,
          p
WJ,
          # )r   )Údim1Údim2)r   r=   r   r   éþÿÿÿ).:r   NN)r7   Ú_validate_sampleÚdiagonalr"   r$   r   r	   r   r'   rJ   ÚlogÚlgammaÚmvlgammaÚmathÚpi)r+   ÚvaluerR   ÚorderÚunnormalized_log_pdfÚdm1ÚalphaÚdenominatorÚ	numeratorÚpi_constantÚnormalize_terms   &&         r   Úlog_probÚLKJCholesky.log_prob~   s  € ð ××ÐØ×!Ñ! %Ô(Ø—^‘^¨°"�^Ó5°gÕ>ˆ
Ü—’˜Q §¡¨1¥°T×5GÑ5G×5NÑ5NÔOˆØ�T×'Ñ'¨!Õ+×6Ñ6°rÓ:Õ:¸T¿X¹XÕEÈÕMˆÜ$Ÿyšy¨·±Ó1AÕ)AÀrÔJÐà�h‰h˜�lˆØ×"Ñ" S¨3¥YÕ.ˆÜ—l’l 5Ó)¨CÕ/ˆÜ—N’N 5¨3¥;°Ó4ˆ	ð ˜C•i¤$§(¢(¬4¯7©7Ó"3Õ3ˆØ$Õ0°;Õ>ˆØ#Õ4Ð4r   )r(   r	   r   )g      ð?N)N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   ÚpositiveÚarg_constraintsÚcorr_choleskyÚsupportr*   r6   r"   r#   r@   rh   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r2   r   s   @@r   r   r      sS   ù‡ € ñ$ðN '¨×(<Ñ(<Ð=€OØ×'Ñ'€G÷Bõ B÷6
ð #(§*¢*£,ô ÷*5ò 5r   )rn   r]   r"   r   Útorch.distributionsr   r   Ú torch.distributions.distributionr   Útorch.distributions.utilsr   Ú__all__r   © r   r   Ú<module>r{      s5   ðñó ã Ý ß 1Ý 9Ý 3ð ˆ/€ôA5�,ö A5r   