K i;8ddlmZddlmZddlmZddlmZddlm Z m Z ddl m Z ddl mZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZddlmZddlmZddlm Z m!Z!m"Z"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)gdZ*e#jVe"dZ,GddeZ-Gdde-Z.Gdde.Z/Gdde.Z0Gdde.Z1d Z2d!Z3d"Z4d#Z5Gd$d%e-Z6Gd&d'e6Z7Gd(d)e6Z8Gd*d+e6Z9d,Z:d-Z;d.Zd1Z?d2Z@y3)4)Product)Sum)Basic)Lambda)Ipi)S)Dummy)Abs)exp)gamma)Integral) MatrixSymbol)Trace) IndexedBase)_sympify)_symbol_converterDensityRandomMatrixSymbol is_random)JointDistributionHandmade)RandomMatrixPSpace)ArrayComprehension) CircularEnsembleCircularUnitaryEnsembleCircularOrthogonalEnsembleCircularSymplecticEnsembleGaussianEnsembleGaussianUnitaryEnsembleGaussianOrthogonalEnsembleGaussianSymplecticEnsemblejoint_eigen_distributionJointEigenDistributionlevel_spacing_distributioncy)NT)xs f/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/stats/random_matrix_models.py_r)#s cHeZdZdZddZedZedZdZdZ y) RandomMatrixEnsembleModelz Base class for random matrix ensembles. It acts as an umbrella and contains the methods common to all the ensembles defined in sympy.stats.random_matrix_models. Nct|t|}}|jdk(rtd|zt j |||S)NFzGDimension of the random matrices must be integers, received %s instead.)rr is_integer ValueErrorr__new__)clssymdims r(r0z!RandomMatrixEnsembleModel.__new__/sQ$S)8C=S >>U "ABEGH H}}S#s++r*c |jdS)Nrargsselfs r(z"RandomMatrixEnsembleModel.6s499Q<r*c |jdS)Nr5r7s r(r9z"RandomMatrixEnsembleModel.7sdiilr*ct|SN)rr8exprs r(densityz!RandomMatrixEnsembleModel.density9s t}r*c$|j|Sr=)r@r>s r(__call__z"RandomMatrixEnsembleModel.__call__<s||D!!r*r=) __name__ __module__ __qualname____doc__r0propertysymbol dimensionr@rBr&r*r(r,r,(s. ,/ 0F23I"r*r,ceZdZdZdZdZy)GaussianEnsembleModela Abstract class for Gaussian ensembles. Contains the properties common to all the gaussian ensembles. References ========== .. [1] https://en.wikipedia.org/wiki/Random_matrix#Gaussian_ensembles .. [2] https://arxiv.org/pdf/1712.07903.pdf ct|}fd}tddd}t|||d|fj}d|zz |z|dz zdz |dz zz}dtz|dz z}||z|zS)a Helper function for computing normalization constant for joint probability density of eigen values of Gaussian ensembles. References ========== .. [1] https://en.wikipedia.org/wiki/Selberg_integral#Mehta's_integral ctdt|zdz zttjtdz zz S)Nr;)r r One)jbetas r(r9zGGaussianEnsembleModel._compute_normalization_constant..Ws7eAQqT ! O4U1554!9;L5MMr*rPTintegerpositiver;rN)r r rdoitr)r8rQn prod_termrPterm1term2term3s ` r(_compute_normalization_constantz5GaussianEnsembleModel._compute_normalization_constantKs aDM #td 3 ! q!Qi0557DFtAvq1u~a/!A#5621 u}u$$r*c `|j}|j||}td}tddd}tddd}tddd}t t | dz t ||dz|d|fjz}t|tt||||z |z||dz|f} t| |j|d|dz fj} t|||d|fj} tt| || z|z S) z Helper function for computing the joint probability distribution of eigen values of the random matrix. liTrRrPkrNr;) rIr\rr r r rrVrrr rtuple) r8rQrWZbnr^r_rPr`rYsub_termrZsymss r(!_compute_joint_eigen_distributionz7GaussianEnsembleModel._compute_joint_eigen_distribution^s" NN224;   #td 3 #td 3 #td 3adU1WAaD!GaAY 7 < < >>?!WS1!%5t%;aQ]KL ((*Q1q5M:??A!!A$Aq 2779eDkEEM3#677r*N)rCrDrErFr\rer&r*r(rKrK?s %&8r*rKc.eZdZedZdZdZdZy)GaussianUnitaryEnsembleModelcn|j}dt|dz ztt|dzdz zzSNrN)rIr r)r8rWs r(normalization_constantz3GaussianUnitaryEnsembleModel.normalization_constantqs2 NN1Q46{R!AqD'!)_,,r*c |j|j}}td|}td|||}t |t t | dz t|dzz|z |SNPmodelHpspacerNrIrjrrrr r r)r8r?rWZGUEh_pspacerps r(r@z$GaussianUnitaryEnsembleModel.densityvf..$"="=4%c6 sAq :9vaadU1WuQT{23D89$??r*c6|jtdSrirer r7s r(r"z5GaussianUnitaryEnsembleModel.joint_eigen_distribution|55ad;;r*ctd}dtdzz |dzztdtz |dzzz}t||S)Ns rNr rr rr8r{fs r(r$z7GaussianUnitaryEnsembleModel.level_spacing_distributionsC #J AX1 c2b5!Q$,/ /a|r*NrCrDrErGrjr@r"r$r&r*r(rgrgps$ --@ <r*rgc.eZdZedZdZdZdZy)GaussianOrthogonalEnsembleModelc |j}td||}ttt | dz t |dzzS)N_HrUrNrIrrr r rr8rWrs r(rjz6GaussianOrthogonalEnsembleModel.normalization_constants@ NN $1 %QqTE!GeBEl2344r*c |j|j}}td|}td|||}t |t t | dz t|dzz|z |S)NrmrnrprqrUrNrs)r8r?rWZGOErurps r(r@z'GaussianOrthogonalEnsembleModel.densityrvr*c@|jtjSr=rer rOr7s r(r"z8GaussianOrthogonalEnsembleModel.joint_eigen_distribution55aee< <r*rc~t|t|}}t||}t||}t ||||SNrnrq)rrrKrrr2r3rormps r(rr= %x}C !#s +E S .C c3C 88r*c~t|t|}}t||}t||}t ||||S)a- Represents Gaussian Unitary Ensembles. Examples ======== >>> from sympy.stats import GaussianUnitaryEnsemble as GUE, density >>> from sympy import MatrixSymbol >>> G = GUE('U', 2) >>> X = MatrixSymbol('X', 2, 2) >>> density(G)(X) exp(-Trace(X**2))/(2*pi**2) rnrq)rrrgrrrs r(rrs?!%x}C (c 2E S .C c3C 88r*c~t|t|}}t||}t||}t ||||S)aN Represents Gaussian Orthogonal Ensembles. Examples ======== >>> from sympy.stats import GaussianOrthogonalEnsemble as GOE, density >>> from sympy import MatrixSymbol >>> G = GOE('U', 2) >>> X = MatrixSymbol('X', 2, 2) >>> density(G)(X) exp(-Trace(X**2)/2)/Integral(exp(-Trace(_H**2)/2), _H) rnrq)rrrrrrs r(r r ?!%x}C +C 5E S .C c3C 88r*c~t|t|}}t||}t||}t ||||S)aN Represents Gaussian Symplectic Ensembles. Examples ======== >>> from sympy.stats import GaussianSymplecticEnsemble as GSE, density >>> from sympy import MatrixSymbol >>> G = GSE('U', 2) >>> X = MatrixSymbol('X', 2, 2) >>> density(G)(X) exp(-2*Trace(X**2))/Integral(exp(-2*Trace(_H**2)), _H) rnrq)rrrrrrs r(r!r!rr*ceZdZdZdZdZy)CircularEnsembleModelz Abstract class for Circular ensembles. Contains the properties and methods common to all the circular ensembles. References ========== .. [1] https://en.wikipedia.org/wiki/Circular_ensemble ctd|z)NzeSupport for Haar measure hasn't been implemented yet, therefore the density of %s cannot be computed.)NotImplementedErrorr>s r(r@zCircularEnsembleModel.densitys!"#;<@#BC Cr*c R|j}dtz|zt||zdz dztt|dz dz|zz z}t d}t ddt ddt dd}}}t |||d|fj}ttttt||ztt||zz |z||dz|fj|d|dz fj} tt|| |z S) z Helper function to compute the joint distribution of phases of the complex eigen values of matrices belonging to any circular ensembles. rNr;tr_T)rSrPr`)rIrr r rr rrVrr r rrra) r8rQrWrbrr_rPr`rdrs r(rez7CircularEnsembleModel._compute_joint_eigen_distributions NN"qy5aA.qtAvz1B/CQ/FFG  d+U3-Ed+1!!A$Aq 2779 GCAadF c!AaD&k 9:D@1a!eQ-PUUW1q5M ##'46 eDk1S5))r*N)rCrDrErFr@rer&r*r(rrs C*r*rceZdZdZy)CircularUnitaryEnsembleModelc6|jtdSrirxr7s r(r"z5CircularUnitaryEnsembleModel.joint_eigen_distributionryr*NrCrDrEr"r&r*r(rr>> from sympy.stats import CircularUnitaryEnsemble as CUE >>> from sympy.stats import joint_eigen_distribution >>> C = CUE('U', 1) >>> joint_eigen_distribution(C) Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k]))**2, (_j, _k + 1, 1), (_k, 1, 0))/(2*pi)) Note ==== As can be seen above in the example, density of CiruclarUnitaryEnsemble is not evaluated because the exact definition is based on haar measure of unitary group which is not unique. rnrq)rrrrrrs r(rr!s?(!%x}C (c 2E S .C c3C 88r*c~t|t|}}t||}t||}t ||||S)a> Represents Circular Orthogonal Ensembles. Examples ======== >>> from sympy.stats import CircularOrthogonalEnsemble as COE >>> from sympy.stats import joint_eigen_distribution >>> C = COE('O', 1) >>> joint_eigen_distribution(C) Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k])), (_j, _k + 1, 1), (_k, 1, 0))/(2*pi)) Note ==== As can be seen above in the example, density of CiruclarOrthogonalEnsemble is not evaluated because the exact definition is based on haar measure of unitary group which is not unique. rnrq)rrrrrrs r(rr:?(!%x}C +C 5E S .C c3C 88r*c~t|t|}}t||}t||}t ||||S)aA Represents Circular Symplectic Ensembles. Examples ======== >>> from sympy.stats import CircularSymplecticEnsemble as CSE >>> from sympy.stats import joint_eigen_distribution >>> C = CSE('S', 1) >>> joint_eigen_distribution(C) Lambda(t[1], Product(Abs(exp(I*t[_j]) - exp(I*t[_k]))**4, (_j, _k + 1, 1), (_k, 1, 0))/(2*pi)) Note ==== As can be seen above in the example, density of CiruclarSymplecticEnsemble is not evaluated because the exact definition is based on haar measure of unitary group which is not unique. rnrq)rrrrrrs r(rrSrr*ct|tstd|z|jjj S)aA For obtaining joint probability distribution of eigen values of random matrix. Parameters ========== mat: RandomMatrixSymbol The matrix symbol whose eigen values are to be considered. Returns ======= Lambda Examples ======== >>> from sympy.stats import GaussianUnitaryEnsemble as GUE >>> from sympy.stats import joint_eigen_distribution >>> U = GUE('U', 2) >>> joint_eigen_distribution(U) Lambda((l[1], l[2]), exp(-l[1]**2 - l[2]**2)*Product(Abs(l[_i] - l[_j])**2, (_j, _i + 1, 2), (_i, 1, 1))/pi) z&%s is not of type, RandomMatrixSymbol.) isinstancerr/rrror"mats r(r"r"ls92 c- .A3GHH ::   4 4 66r*c|jd}tdt|Ds tdt |S)a Creates joint distribution of eigen values of matrices with random expressions. Parameters ========== mat: Matrix The matrix under consideration. Returns ======= JointDistributionHandmade Examples ======== >>> from sympy.stats import Normal, JointEigenDistribution >>> from sympy import Matrix >>> A = [[Normal('A00', 0, 1), Normal('A01', 0, 1)], ... [Normal('A10', 0, 1), Normal('A11', 0, 1)]] >>> JointEigenDistribution(Matrix(A)) JointDistributionHandmade(-sqrt(A00**2 - 2*A00*A11 + 4*A01*A10 + A11**2)/2 + A00/2 + A11/2, sqrt(A00**2 - 2*A00*A11 + 4*A01*A10 + A11**2)/2 + A00/2 + A11/2) T)multiplec32K|]}t|ywr=)r).0eigenvals r( z)JointEigenDistribution..sBxy"BszWEigen values do not have any random expression, joint distribution cannot be generated.) eigenvalsallsetr/r)rrs r(r#r#sF8 t ,I B3y>B BCD D $i 00r*cJ|jjjS)a For obtaining distribution of level spacings. Parameters ========== mat: RandomMatrixSymbol The random matrix symbol whose eigen values are to be considered for finding the level spacings. Returns ======= Lambda Examples ======== >>> from sympy.stats import GaussianUnitaryEnsemble as GUE >>> from sympy.stats import level_spacing_distribution >>> U = GUE('U', 2) >>> level_spacing_distribution(U) Lambda(_s, 32*_s**2*exp(-4*_s**2/pi)/pi**2) References ========== .. [1] https://en.wikipedia.org/wiki/Random_matrix#Distribution_of_level_spacings )rrror$rs r(r$r$s< ::   6 6 88r*N)Asympy.concrete.productsrsympy.concrete.summationsrsympy.core.basicrsympy.core.functionrsympy.core.numbersrrsympy.core.singletonr sympy.core.symbolr $sympy.functions.elementary.complexesr &sympy.functions.elementary.exponentialr 'sympy.functions.special.gamma_functionsr sympy.integrals.integralsr"sympy.matrices.expressions.matexprr sympy.matrices.expressions.tracersympy.tensor.indexedrsympy.core.sympifyrsympy.stats.rvrrrrsympy.stats.joint_rv_typesrsympy.stats.random_matrixrsympy.tensor.arrayr__all__registerr)r,rKrgrrrrr r!rrrrrrrrr"r#r$r&r*r(rs+)"&&"#469.;2,'TT@81 &'(""./85/8b#8(&;*&;*9 9&9&9& *5 *D<#8<=&;=<&;<9 9292927: 1D9r*