Ë
    ÷Q(hcœ  ã            
       ó¢  — d Z ddlZddlZddlZddlZddlmZmZ ddlZ	ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZmZ ddlmZ ddlmZmZmZ ddlmZmZm Z m!Z!m"Z" ddl#m$Z$m%Z% ddl&m'Z'm(Z(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. d„ Z/d„ Z0dddddd e	jb                  e	jd                  «      jf                  dœd„Z4d„ Z5 edgdgdgdœd¬«      dddddd e	jb                  e	jd                  «      jf                  ddœd „«       Z6 G d!„ d"e,«      Z7 G d#„ d$e7«      Z8ddddddd e	jb                  e	jd                  «      jf                  fd%„Z9 G d&„ d'e7«      Z:y)(zUGraphicalLasso: sparse inverse covariance estimation with an l1-penalized
estimator.
é    N)ÚIntegralÚReal)Úlinalgé   )Ú_fit_context)ÚConvergenceWarning)Ú_cd_fast)Úlars_path_gram)Úcheck_cvÚcross_val_score)ÚBunch)ÚIntervalÚ
StrOptionsÚvalidate_params)ÚMetadataRouterÚMethodMappingÚ_raise_for_paramsÚ_routing_enabledÚprocess_routing)ÚParallelÚdelayed)Ú_is_arraylike_not_scalarÚcheck_random_stateÚcheck_scalarÚvalidate_dataé   )ÚEmpiricalCovarianceÚempirical_covarianceÚlog_likelihoodc                 óV  — |j                   d   }dt        | |«      z  |t        j                  dt        j                  z  «      z  z   }||t        j
                  |«      j                  «       t        j
                  t        j                  |«      «      j                  «       z
  z  z  }|S )zùEvaluation of the graphical-lasso objective function

    the objective function is made of a shifted scaled version of the
    normalized log-likelihood (i.e. its empirical mean over the samples) and a
    penalisation term to promote sparsity
    r   ç       Àr   )Úshaper   ÚnpÚlogÚpiÚabsÚsumÚdiag)ÚmleÚ
precision_ÚalphaÚpÚcosts        ú]/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sklearn/covariance/_graph_lasso.pyÚ
_objectiver/   -   s†   € ð 	×Ñ˜Ñ€AØ”.  jÓ1Ñ1°A¼¿¹¸qÄ2Ç5Á5¹yÓ8IÑ4IÑI€DØˆE”R—V‘V˜JÓ'×+Ñ+Ó-´·±´r·w±w¸zÓ7JÓ0K×0OÑ0OÓ0QÑQÑRÑR€DØ€Kó    c                 ó  — t        j                  | |z  «      }||j                  d   z  }||t        j                  |«      j                  «       t        j                  t        j                  |«      «      j                  «       z
  z  z  }|S )z§Expression of the dual gap convergence criterion

    The specific definition is given in Duchi "Projected Subgradient Methods
    for Learning Sparse Gaussians".
    r   )r#   r'   r"   r&   r(   )Úemp_covr*   r+   Úgaps       r.   Ú	_dual_gapr4   :   sr   € ô �&‰&�˜:Ñ%Ó
&€CØˆ:×Ñ˜AÑÑ€CØˆ5”B—F‘F˜:Ó&×*Ñ*Ó,¬r¯v©v´b·g±g¸jÓ6IÓ/J×/NÑ/NÓ/PÑPÑQÑQ€CØ€Jr0   Úcdç-Cëâ6?éd   F)Úcov_initÚmodeÚtolÚenet_tolÚmax_iterÚverboseÚepsc                óÐ  — | j                   \  }	}
|dk(  rst        j                  | «      }dt        | |«      z  }||
t	        j
                  dt        j                  z  «      z  z  }t	        j                  | |z  «      |
z
  }| |||fdfS |€| j                  «       }n|j                  «       }|dz  }| j                  d d |
dz   …   }||j                  d d |
dz   …<   t        j                  |«      }t	        j                  |
«      }d}t        «       }|dk(  rt        dd¬	«      }nt        d¬
«      }	 t        j                  }t	        j                  |dd …dd …f   d¬«      }t        |«      D �]  }t        |
«      D �]X  }|dkD  r*|dz
  }||   ||k7     ||<   |d d …|f   ||k7     |d d …|f<   n|dd …dd …f   |d d  | |||k7  f   }t	        j                   di |¤Ž5  |dk(  rF|||k7  |f   |||f   d|z  z   z   }t#        j$                  ||d|||||t'        d «      d«
      \  }}	}	}	n't)        |||j*                  ||
dz
  z  d|dd¬«      \  }	}	}d d d «       d|||f   t	        j,                  |||k7  |f   «      z
  z  |||f<   |||f    |z  |||k7  |f<   |||f    |z  ||||k7  f<   t	        j,                  ||«      }|||||k7  f<   ||||k7  |f<   �Œ[ t	        j.                  |j                  «       «      st1        d«      ‚t3        | ||«      }t5        | ||«      }|rt7        d|||fz  «       |j9                  ||f«       t	        j:                  |«      |k  r nIt	        j.                  |«      r�Œ
|dkD  s�Œt1        d«      ‚ t=        j>                  d||fz  t@        «       ||||dz   fS # 1 sw Y   �ŒexY w# t0        $ r}|jB                  d   dz   f|_!        |‚d }~ww xY w)Nr   r!   r   gffffffî?r   r5   ÚraiseÚignore)ÚoverÚinvalid)rC   ÚC)Úorderiè  FTÚlars)ÚXyÚGramÚ	n_samplesÚ	alpha_minÚ	copy_Gramr>   ÚmethodÚreturn_pathg      ð?z1The system is too ill-conditioned for this solverz<[graphical_lasso] Iteration % 3i, cost % 3.2e, dual gap %.3ezANon SPD result: the system is too ill-conditioned for this solverzDgraphical_lasso: did not converge after %i iteration: dual gap: %.3ez3. The system is too ill-conditioned for this solver© )"r"   r   Úinvr   r#   r$   r%   r'   ÚcopyÚflatÚpinvhÚarangeÚlistÚdictÚinfÚrangeÚerrstateÚcd_fastÚenet_coordinate_descent_gramr   r
   ÚsizeÚdotÚisfiniteÚFloatingPointErrorr4   r/   ÚprintÚappendr&   ÚwarningsÚwarnr   Úargs)r2   r+   r8   r9   r:   r;   r<   r=   r>   Ú_Ú
n_featuresr*   r-   Úd_gapÚcovariance_ÚdiagonalÚindicesÚiÚcostsÚerrorsÚsub_covarianceÚidxÚdiÚrowÚcoefsÚes                             r.   Ú_graphical_lassors   G   s“  € ð —M‘M�M€A€zØ�‚zä—Z‘Z Ó(ˆ
Ø”n W¨jÓ9Ñ9ˆØ�
œRŸV™V A¬¯©¡IÓ.Ñ.Ñ.ˆÜ—‘�w Ñ+Ó,¨zÑ9ˆØ˜
 T¨5 M°1Ð4Ð4àÐØ—l‘l“n‰à—m‘m“oˆð �4Ñ€KØ�|‰|Ñ-˜z¨A™~Ð-Ñ.€HØ*2€K×ÑÑ&˜
 Q™Ð&Ñ'Ü—‘˜kÓ*€Jä�i‰i˜
Ó#€GØ	€AÜ‹F€Eàˆt‚|Ü˜7¨HÔ5‰ä˜gÔ&ˆðTô —‘ˆäŸ™ ¨Q©R°±¨VÑ!4¸CÔ@ˆÜ�x“ó K	ˆAÜ˜ZÓ(ó 29�ð ˜’7Ø˜q™�BØ)4°R©¸ÀC¹Ñ)H�N 2Ñ&Ø,7º¸2¸Ñ,>¸wÈ#¹~Ñ,N�N¢1 b 5Ò)à(3°A±B¸¹°FÑ(;�N¡1Ð%Ø˜c 7¨c¡>Ð1Ñ2�Ü—[‘[Ñ* 6Ñ*ñ Ø˜t’|ð ' w°#¡~°sÐ':Ñ;Ø)¨#¨s¨(Ñ3°d¸S±jÑ@ñBð!˜ô *1×)MÑ)MØ!Ø!ØØ*ØØØ$Ø$Ü.¨tÓ4Ø!ó*™˜˜q !¡Qô '5Ø"Ø!/Ø&)§h¡hØ&+¨z¸A©~Ñ&>Ø&*Ø #Ø#)Ø(-ô	'™˜˜1˜e÷)ð> (+Ø  S Ñ)Ü—f‘f˜[¨°C©¸Ð)<Ñ=¸uÓEñFñ(�
˜3 ˜8Ñ$ð 4>¸cÀ3¸hÑ3GÐ2GÈ%Ñ2O�
˜7 c™>¨3Ð.Ñ/Ø3=¸cÀ3¸hÑ3GÐ2GÈ%Ñ2O�
˜3 ¨3¡Ð.Ñ/ÜŸ™˜~¨uÓ5�Ø38�˜C ¨C¡Ð/Ñ0Ø38�˜G s™N¨CÐ/Ó0ðe29ôf —;‘;˜zŸ~™~Ó/Ô0Ü(ØGóð ô ˜g z°5Ó9ˆEÜ˜g z°5Ó9ˆDÙÜØRØ˜$ Ð&ñ'ôð �L‰L˜$ ˜Ô'Ü�v‰v�e‹}˜sÒ"ÙÜ—;‘;˜tÖ$¨¨Q¬Ü(ØWóð ðGK	ôN �M‰MØVØ˜UÐ#ñ$ä"ôð ˜
 E¨1¨q©5Ð0Ð0÷Iñ ûô@ ò Ø—&‘&˜‘)ÐSÑSÐUˆŒØˆûðús?   Ä0B*N= ÇA3N0ÉD&N= Í5N= Í<+N= Î0N:Î5N= Î=	O%ÏO Ï O%c                 óÀ   — t        j                  | «      }d|j                  dd|j                  d   dz   …<   t        j                  t        j
                  |«      «      S )a³  Find the maximum alpha for which there are some non-zeros off-diagonal.

    Parameters
    ----------
    emp_cov : ndarray of shape (n_features, n_features)
        The sample covariance matrix.

    Notes
    -----
    This results from the bound for the all the Lasso that are solved
    in GraphicalLasso: each time, the row of cov corresponds to Xy. As the
    bound for alpha is given by `max(abs(Xy))`, the result follows.
    r   Nr   )r#   rP   rQ   r"   Úmaxr&   )r2   ÚAs     r.   Ú	alpha_maxrw   Ì   sI   € ô 	�‰�Ó€AØ !€A‡F�FÑˆa�g‰g�a‰j˜1‰nÐÑÜ�6‰6”"—&‘&˜“)ÓÐr0   ú
array-likeÚboolean)r2   Úreturn_costsÚreturn_n_iter©Úprefer_skip_nested_validation)r9   r:   r;   r<   r=   rz   r>   r{   c                ó  — t        ||d|||||d¬«	      j                  | «      }
|
j                  |
j                  g}|r|j	                  |
j
                  «       |	r|j	                  |
j                  «       t        |«      S )a<  L1-penalized covariance estimator.

    Read more in the :ref:`User Guide <sparse_inverse_covariance>`.

    .. versionchanged:: v0.20
        graph_lasso has been renamed to graphical_lasso

    Parameters
    ----------
    emp_cov : array-like of shape (n_features, n_features)
        Empirical covariance from which to compute the covariance estimate.

    alpha : float
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.
        Range is (0, inf].

    mode : {'cd', 'lars'}, default='cd'
        The Lasso solver to use: coordinate descent or LARS. Use LARS for
        very sparse underlying graphs, where p > n. Elsewhere prefer cd
        which is more numerically stable.

    tol : float, default=1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped. Range is (0, inf].

    enet_tol : float, default=1e-4
        The tolerance for the elastic net solver used to calculate the descent
        direction. This parameter controls the accuracy of the search direction
        for a given column update, not of the overall parameter estimate. Only
        used for mode='cd'. Range is (0, inf].

    max_iter : int, default=100
        The maximum number of iterations.

    verbose : bool, default=False
        If verbose is True, the objective function and dual gap are
        printed at each iteration.

    return_costs : bool, default=False
        If return_costs is True, the objective function and dual gap
        at each iteration are returned.

    eps : float, default=eps
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems. Default is `np.finfo(np.float64).eps`.

    return_n_iter : bool, default=False
        Whether or not to return the number of iterations.

    Returns
    -------
    covariance : ndarray of shape (n_features, n_features)
        The estimated covariance matrix.

    precision : ndarray of shape (n_features, n_features)
        The estimated (sparse) precision matrix.

    costs : list of (objective, dual_gap) pairs
        The list of values of the objective function and the dual gap at
        each iteration. Returned only if return_costs is True.

    n_iter : int
        Number of iterations. Returned only if `return_n_iter` is set to True.

    See Also
    --------
    GraphicalLasso : Sparse inverse covariance estimation
        with an l1-penalized estimator.
    GraphicalLassoCV : Sparse inverse covariance with
        cross-validated choice of the l1 penalty.

    Notes
    -----
    The algorithm employed to solve this problem is the GLasso algorithm,
    from the Friedman 2008 Biostatistics paper. It is the same algorithm
    as in the R `glasso` package.

    One possible difference with the `glasso` R package is that the
    diagonal coefficients are not penalized.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.datasets import make_sparse_spd_matrix
    >>> from sklearn.covariance import empirical_covariance, graphical_lasso
    >>> true_cov = make_sparse_spd_matrix(n_dim=3,random_state=42)
    >>> rng = np.random.RandomState(42)
    >>> X = rng.multivariate_normal(mean=np.zeros(3), cov=true_cov, size=3)
    >>> emp_cov = empirical_covariance(X, assume_centered=True)
    >>> emp_cov, _ = graphical_lasso(emp_cov, alpha=0.05)
    >>> emp_cov
    array([[ 1.68...,  0.21..., -0.20...],
           [ 0.21...,  0.22..., -0.08...],
           [-0.20..., -0.08...,  0.23...]])
    ÚprecomputedT)	r+   r9   Ú
covariancer:   r;   r<   r=   r>   Úassume_centered)ÚGraphicalLassoÚfitrg   r*   r`   Úcosts_Ún_iter_Útuple)r2   r+   r9   r:   r;   r<   r=   rz   r>   r{   ÚmodelÚoutputs               r.   Úgraphical_lassor‰   ß   s€   € ôl ØØØ ØØØØØØô
÷ 
�cˆ'ƒlð 
ð ×Ñ ×!1Ñ!1Ð2€FÙØ�‰�e—l‘lÔ#ÙØ�‰�e—m‘mÔ$Ü�‹=Ðr0   c                   ó>  ‡ — e Zd ZU i ej                  ¥ eeddd¬«      g eeddd¬«      g eeddd¬«      g eddh«      gdg eeddd	¬«      gd
œ¥Ze	e
d<   ej                  d«       ddddd ej                  ej                  «      j                  dfˆ fd„	Zˆ xZS )ÚBaseGraphicalLassor   NÚright©ÚclosedÚleftr5   rF   r=   Úboth)r:   r;   r<   r9   r=   r>   Ú_parameter_constraintsÚstore_precisionr6   r7   Fc                 óz   •— t         ‰| �  |¬«       || _        || _        || _        || _        || _        || _        y )N©r�   )ÚsuperÚ__init__r:   r;   r<   r9   r=   r>   )	Úselfr:   r;   r<   r9   r=   r>   r�   Ú	__class__s	           €r.   r–   zBaseGraphicalLasso.__init__u  s?   ø€ ô 	‰Ñ¨ÐÔ9ØˆŒØ ˆŒØ ˆŒØˆŒ	ØˆŒØˆ�r0   )Ú__name__Ú
__module__Ú__qualname__r   r‘   r   r   r   r   rU   Ú__annotations__Úpopr#   ÚfinfoÚfloat64r>   r–   Ú__classcell__©r˜   s   @r.   r‹   r‹   i  sÄ   ø… ð$Ø
×
4Ñ
4ð$á˜˜q $¨wÔ7Ð8Ù˜d A t°GÔ<Ð=Ù˜h¨¨4¸Ô?Ð@Ù˜T 6˜NÓ+Ð,Ø�;Ù˜˜q $¨vÔ6Ð7ò$Ð˜Dó ð ×ÑÐ0Ô1ð ØØØØØˆB�H‰H�R—Z‘ZÓ ×$Ñ$Ø÷ñ r0   r‹   c            
       óü   ‡ — e Zd ZU dZi ej
                  ¥ eeddd¬«      g edh«      dgdœ¥Ze	e
d<   	 dd	dd
d
dd ej                  ej                  «      j                  ddœˆ fd„Z ed¬«      dd„«       Zˆ xZS )r‚   ag  Sparse inverse covariance estimation with an l1-penalized estimator.

    For a usage example see
    :ref:`sphx_glr_auto_examples_applications_plot_stock_market.py`.

    Read more in the :ref:`User Guide <sparse_inverse_covariance>`.

    .. versionchanged:: v0.20
        GraphLasso has been renamed to GraphicalLasso

    Parameters
    ----------
    alpha : float, default=0.01
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.
        Range is (0, inf].

    mode : {'cd', 'lars'}, default='cd'
        The Lasso solver to use: coordinate descent or LARS. Use LARS for
        very sparse underlying graphs, where p > n. Elsewhere prefer cd
        which is more numerically stable.

    covariance : "precomputed", default=None
        If covariance is "precomputed", the input data in `fit` is assumed
        to be the covariance matrix. If `None`, the empirical covariance
        is estimated from the data `X`.

        .. versionadded:: 1.3

    tol : float, default=1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped. Range is (0, inf].

    enet_tol : float, default=1e-4
        The tolerance for the elastic net solver used to calculate the descent
        direction. This parameter controls the accuracy of the search direction
        for a given column update, not of the overall parameter estimate. Only
        used for mode='cd'. Range is (0, inf].

    max_iter : int, default=100
        The maximum number of iterations.

    verbose : bool, default=False
        If verbose is True, the objective function and dual gap are
        plotted at each iteration.

    eps : float, default=eps
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems. Default is `np.finfo(np.float64).eps`.

        .. versionadded:: 1.3

    assume_centered : bool, default=False
        If True, data are not centered before computation.
        Useful when working with data whose mean is almost, but not exactly
        zero.
        If False, data are centered before computation.

    Attributes
    ----------
    location_ : ndarray of shape (n_features,)
        Estimated location, i.e. the estimated mean.

    covariance_ : ndarray of shape (n_features, n_features)
        Estimated covariance matrix

    precision_ : ndarray of shape (n_features, n_features)
        Estimated pseudo inverse matrix.

    n_iter_ : int
        Number of iterations run.

    costs_ : list of (objective, dual_gap) pairs
        The list of values of the objective function and the dual gap at
        each iteration. Returned only if return_costs is True.

        .. versionadded:: 1.3

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    graphical_lasso : L1-penalized covariance estimator.
    GraphicalLassoCV : Sparse inverse covariance with
        cross-validated choice of the l1 penalty.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.covariance import GraphicalLasso
    >>> true_cov = np.array([[0.8, 0.0, 0.2, 0.0],
    ...                      [0.0, 0.4, 0.0, 0.0],
    ...                      [0.2, 0.0, 0.3, 0.1],
    ...                      [0.0, 0.0, 0.1, 0.7]])
    >>> np.random.seed(0)
    >>> X = np.random.multivariate_normal(mean=[0, 0, 0, 0],
    ...                                   cov=true_cov,
    ...                                   size=200)
    >>> cov = GraphicalLasso().fit(X)
    >>> np.around(cov.covariance_, decimals=3)
    array([[0.816, 0.049, 0.218, 0.019],
           [0.049, 0.364, 0.017, 0.034],
           [0.218, 0.017, 0.322, 0.093],
           [0.019, 0.034, 0.093, 0.69 ]])
    >>> np.around(cov.location_, decimals=3)
    array([0.073, 0.04 , 0.038, 0.143])
    r   Nr�   r�   r   )r+   r€   r‘   r5   r6   r7   F)r9   r€   r:   r;   r<   r=   r>   r�   c          	      óN   •— t         ‰
| �  |||||||	¬«       || _        || _        y ©N)r:   r;   r<   r9   r=   r>   r�   )r•   r–   r+   r€   )r—   r+   r9   r€   r:   r;   r<   r=   r>   r�   r˜   s             €r.   r–   zGraphicalLasso.__init__  s<   ø€ ô 	‰ÑØØØØØØØ+ð 	ô 	
ð ˆŒ
Ø$ˆ�r0   Tr|   c                 óZ  — t        | |dd¬«      }| j                  dk(  r8|j                  «       }t        j                  |j
                  d   «      | _        nat        || j                  ¬«      }| j                  r(t        j                  |j
                  d   «      | _        n|j                  d«      | _        t        || j                  d| j                  | j                  | j                  | j                  | j                   | j"                  ¬«	      \  | _        | _        | _        | _        | S )	a€  Fit the GraphicalLasso model to X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Data from which to compute the covariance estimate.

        y : Ignored
            Not used, present for API consistency by convention.

        Returns
        -------
        self : object
            Returns the instance itself.
        r   )Úensure_min_featuresÚensure_min_samplesr   r   r”   r   N©r+   r8   r9   r:   r;   r<   r=   r>   )r   r€   rP   r#   Úzerosr"   Ú	location_r   r�   Úmeanrs   r+   r9   r:   r;   r<   r=   r>   rg   r*   r„   r…   )r—   ÚXÚyr2   s       r.   rƒ   zGraphicalLasso.fit  sà   € ô$ ˜$ °qÈQÔOˆà�?‰?˜mÒ+Ø—f‘f“hˆGÜŸX™X a§g¡g¨a¡jÓ1ˆD�Nä*¨1¸d×>RÑ>RÔSˆGØ×#Ò#Ü!#§¡¨!¯'©'°!©*Ó!5�•à!"§¡¨£�”äGWØØ—*‘*ØØ—‘Ø—‘Ø—]‘]Ø—]‘]Ø—L‘LØ—‘ô
H
ÑDˆÔ˜$œ/¨4¬;¸¼ð ˆr0   )ç{®Gáz„?©N)r™   rš   r›   Ú__doc__r‹   r‘   r   r   r   rU   rœ   r#   rž   rŸ   r>   r–   r   rƒ   r    r¡   s   @r.   r‚   r‚   ˆ  s£   ø… ñtðl$Ø
×
3Ñ
3ð$á˜4  D°Ô8Ð9Ù! = /Ó2°DÐ9ò$Ð˜Dó ð ð%ð ØØØØØØˆB�H‰H�R—Z‘ZÓ ×$Ñ$Øö%ñ2 °Ô5ò(ó 6ô(r0   r‚   c
                 ó4  — t        d|dz
  «      }
t        | «      }|€|j                  «       }n|}t        «       }t        «       }t        «       }|�t        |«      }|D ]Ñ  }	 t	        ||||||||
|	¬«	      \  }}}}|j                  |«       |j                  |«       |�t        |«      }|�7t        j                  «      st        j                   }|j                  |«       |dk(  r t        j                  j                  d«       Œ«|dkD  sŒ±|�t        d|fz  «       ŒÄt        d|z  «       ŒÓ |�|||fS ||fS # t        $ rR t        j                   }|j                  t        j                  «       |j                  t        j                  «       Y Œìw xY w)aŠ	  l1-penalized covariance estimator along a path of decreasing alphas

    Read more in the :ref:`User Guide <sparse_inverse_covariance>`.

    Parameters
    ----------
    X : ndarray of shape (n_samples, n_features)
        Data from which to compute the covariance estimate.

    alphas : array-like of shape (n_alphas,)
        The list of regularization parameters, decreasing order.

    cov_init : array of shape (n_features, n_features), default=None
        The initial guess for the covariance.

    X_test : array of shape (n_test_samples, n_features), default=None
        Optional test matrix to measure generalisation error.

    mode : {'cd', 'lars'}, default='cd'
        The Lasso solver to use: coordinate descent or LARS. Use LARS for
        very sparse underlying graphs, where p > n. Elsewhere prefer cd
        which is more numerically stable.

    tol : float, default=1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped. The tolerance must be a positive
        number.

    enet_tol : float, default=1e-4
        The tolerance for the elastic net solver used to calculate the descent
        direction. This parameter controls the accuracy of the search direction
        for a given column update, not of the overall parameter estimate. Only
        used for mode='cd'. The tolerance must be a positive number.

    max_iter : int, default=100
        The maximum number of iterations. This parameter should be a strictly
        positive integer.

    verbose : int or bool, default=False
        The higher the verbosity flag, the more information is printed
        during the fitting.

    eps : float, default=eps
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems. Default is `np.finfo(np.float64).eps`.

        .. versionadded:: 1.3

    Returns
    -------
    covariances_ : list of shape (n_alphas,) of ndarray of shape             (n_features, n_features)
        The estimated covariance matrices.

    precisions_ : list of shape (n_alphas,) of ndarray of shape             (n_features, n_features)
        The estimated (sparse) precision matrices.

    scores_ : list of shape (n_alphas,), dtype=float
        The generalisation error (log-likelihood) on the test data.
        Returned only if test data is passed.
    r   r   r¨   ú.z/[graphical_lasso_path] alpha: %.2e, score: %.2ez"[graphical_lasso_path] alpha: %.2e)ru   r   rP   rT   rs   r`   r   r^   r#   rV   Únanr]   ÚsysÚstderrÚwriter_   )r¬   Úalphasr8   ÚX_testr9   r:   r;   r<   r=   r>   Úinner_verboser2   rg   Úcovariances_Úprecisions_Úscores_Útest_emp_covr+   r*   rd   Ú
this_scores                        r.   Úgraphical_lasso_pathr¿   K  s©  € ôV ˜˜7 Q™;Ó'€MÜ" 1Ó%€GØÐØ—l‘l“n‰àˆÜ“6€LÜ“&€KÜ‹f€GØÐÜ+¨FÓ3ˆàò #Dˆð	'ä,<ØØØ$ØØØ!Ø!Ø%Øô
-Ñ)ˆK˜ Q¨ð ×Ñ Ô,Ø×Ñ˜zÔ*ØÐ!Ü+¨L¸*ÓE�
ð
 ÐÜ—;‘;˜zÔ*Ü Ÿf™f˜W�
Ø�N‰N˜:Ô&Ø�aŠ<Ü�J‰J×Ñ˜SÕ!Ø�q‹[ØÐ!ÜØEØ˜jÐ)ñ*õô
 Ð:¸UÑBÕCðG#DðH ÐØ˜[¨'Ð1Ð1Ø˜Ð$Ð$øô) "ò 	'ÜŸ&™&˜ˆJØ×Ñ¤§¡Ô'Ø×ÑœrŸv™vÖ&ð	'ús   Á!A	D<Ä<AFÆFc                   ó  ‡ — e Zd ZU dZi ej
                  ¥ eeddd¬«      dg eeddd¬«      gdgedgd	œ¥Zee	d
<   ddddddddd e
j                  e
j                  «      j                  ddœˆ fd„
Z ed¬«      dd„«       Zd„ Zˆ xZS )ÚGraphicalLassoCVa?  Sparse inverse covariance w/ cross-validated choice of the l1 penalty.

    See glossary entry for :term:`cross-validation estimator`.

    Read more in the :ref:`User Guide <sparse_inverse_covariance>`.

    .. versionchanged:: v0.20
        GraphLassoCV has been renamed to GraphicalLassoCV

    Parameters
    ----------
    alphas : int or array-like of shape (n_alphas,), dtype=float, default=4
        If an integer is given, it fixes the number of points on the
        grids of alpha to be used. If a list is given, it gives the
        grid to be used. See the notes in the class docstring for
        more details. Range is [1, inf) for an integer.
        Range is (0, inf] for an array-like of floats.

    n_refinements : int, default=4
        The number of times the grid is refined. Not used if explicit
        values of alphas are passed. Range is [1, inf).

    cv : int, cross-validation generator or iterable, default=None
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 5-fold cross-validation,
        - integer, to specify the number of folds.
        - :term:`CV splitter`,
        - An iterable yielding (train, test) splits as arrays of indices.

        For integer/None inputs :class:`~sklearn.model_selection.KFold` is used.

        Refer :ref:`User Guide <cross_validation>` for the various
        cross-validation strategies that can be used here.

        .. versionchanged:: 0.20
            ``cv`` default value if None changed from 3-fold to 5-fold.

    tol : float, default=1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped. Range is (0, inf].

    enet_tol : float, default=1e-4
        The tolerance for the elastic net solver used to calculate the descent
        direction. This parameter controls the accuracy of the search direction
        for a given column update, not of the overall parameter estimate. Only
        used for mode='cd'. Range is (0, inf].

    max_iter : int, default=100
        Maximum number of iterations.

    mode : {'cd', 'lars'}, default='cd'
        The Lasso solver to use: coordinate descent or LARS. Use LARS for
        very sparse underlying graphs, where number of features is greater
        than number of samples. Elsewhere prefer cd which is more numerically
        stable.

    n_jobs : int, default=None
        Number of jobs to run in parallel.
        ``None`` means 1 unless in a :obj:`joblib.parallel_backend` context.
        ``-1`` means using all processors. See :term:`Glossary <n_jobs>`
        for more details.

        .. versionchanged:: v0.20
           `n_jobs` default changed from 1 to None

    verbose : bool, default=False
        If verbose is True, the objective function and duality gap are
        printed at each iteration.

    eps : float, default=eps
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems. Default is `np.finfo(np.float64).eps`.

        .. versionadded:: 1.3

    assume_centered : bool, default=False
        If True, data are not centered before computation.
        Useful when working with data whose mean is almost, but not exactly
        zero.
        If False, data are centered before computation.

    Attributes
    ----------
    location_ : ndarray of shape (n_features,)
        Estimated location, i.e. the estimated mean.

    covariance_ : ndarray of shape (n_features, n_features)
        Estimated covariance matrix.

    precision_ : ndarray of shape (n_features, n_features)
        Estimated precision matrix (inverse covariance).

    costs_ : list of (objective, dual_gap) pairs
        The list of values of the objective function and the dual gap at
        each iteration. Returned only if return_costs is True.

        .. versionadded:: 1.3

    alpha_ : float
        Penalization parameter selected.

    cv_results_ : dict of ndarrays
        A dict with keys:

        alphas : ndarray of shape (n_alphas,)
            All penalization parameters explored.

        split(k)_test_score : ndarray of shape (n_alphas,)
            Log-likelihood score on left-out data across (k)th fold.

            .. versionadded:: 1.0

        mean_test_score : ndarray of shape (n_alphas,)
            Mean of scores over the folds.

            .. versionadded:: 1.0

        std_test_score : ndarray of shape (n_alphas,)
            Standard deviation of scores over the folds.

            .. versionadded:: 1.0

    n_iter_ : int
        Number of iterations run for the optimal alpha.

    n_features_in_ : int
        Number of features seen during :term:`fit`.

        .. versionadded:: 0.24

    feature_names_in_ : ndarray of shape (`n_features_in_`,)
        Names of features seen during :term:`fit`. Defined only when `X`
        has feature names that are all strings.

        .. versionadded:: 1.0

    See Also
    --------
    graphical_lasso : L1-penalized covariance estimator.
    GraphicalLasso : Sparse inverse covariance estimation
        with an l1-penalized estimator.

    Notes
    -----
    The search for the optimal penalization parameter (`alpha`) is done on an
    iteratively refined grid: first the cross-validated scores on a grid are
    computed, then a new refined grid is centered around the maximum, and so
    on.

    One of the challenges which is faced here is that the solvers can
    fail to converge to a well-conditioned estimate. The corresponding
    values of `alpha` then come out as missing values, but the optimum may
    be close to these missing values.

    In `fit`, once the best parameter `alpha` is found through
    cross-validation, the model is fit again using the entire training set.

    Examples
    --------
    >>> import numpy as np
    >>> from sklearn.covariance import GraphicalLassoCV
    >>> true_cov = np.array([[0.8, 0.0, 0.2, 0.0],
    ...                      [0.0, 0.4, 0.0, 0.0],
    ...                      [0.2, 0.0, 0.3, 0.1],
    ...                      [0.0, 0.0, 0.1, 0.7]])
    >>> np.random.seed(0)
    >>> X = np.random.multivariate_normal(mean=[0, 0, 0, 0],
    ...                                   cov=true_cov,
    ...                                   size=200)
    >>> cov = GraphicalLassoCV().fit(X)
    >>> np.around(cov.covariance_, decimals=3)
    array([[0.816, 0.051, 0.22 , 0.017],
           [0.051, 0.364, 0.018, 0.036],
           [0.22 , 0.018, 0.322, 0.094],
           [0.017, 0.036, 0.094, 0.69 ]])
    >>> np.around(cov.location_, decimals=3)
    array([0.073, 0.04 , 0.038, 0.143])
    r   Nr�   r�   rx   r   Ú	cv_object)r·   Ún_refinementsÚcvÚn_jobsr‘   é   r6   r7   r5   F)r·   rÃ   rÄ   r:   r;   r<   r9   rÅ   r=   r>   r�   c          	      ój   •— t         ‰| �  |||||	|
|¬«       || _        || _        || _        || _        y r¤   )r•   r–   r·   rÃ   rÄ   rÅ   )r—   r·   rÃ   rÄ   r:   r;   r<   r9   rÅ   r=   r>   r�   r˜   s               €r.   r–   zGraphicalLassoCV.__init__Š  sK   ø€ ô 	‰ÑØØØØØØØ+ð 	ô 	
ð ˆŒØ*ˆÔØˆŒØˆ�r0   Tr|   c           
      óî  ‡ ‡‡‡— t        |‰ d«       t        ‰ ‰d¬«      Š‰ j                  r(t        j                  ‰j
                  d   «      ‰ _        n‰j                  d«      ‰ _        t        ‰‰ j                  ¬«      }t        ‰ j                  |d¬«      }t        «       }‰ j                  }t        d‰ j                  dz
  «      Št        |«      rC‰ j                  D ]%  }t!        |d	t"        dt        j$                  d
¬«       Œ' ‰ j                  Šd}	n_‰ j&                  }	t)        |«      }
d|
z  }t        j*                  t        j,                  |«      t        j,                  |
«      |«      ddd…   Št/        «       rt1        ‰ dfi |¤Ž}nt3        t3        i ¬«      ¬«      }t5        j4                  «       }t7        |	«      D �]˜  }t9        j:                  «       5  t9        j<                  dt>        «        tA        ‰ jB                  ‰ j                  ¬«      ˆˆˆˆ fd„ |jD                  ‰|fi |jF                  jD                  ¤ŽD «       «      }ddd«       tI        Ž \  }}}tI        |Ž }tI        |Ž }|jK                  tI        ‰||«      «       tM        |tO        jP                  d«      d¬«      }t        j$                   }d}tS        |«      D ]‚  \  }\  }}}t        j                  |«      }|dt        jT                  t        jV                  «      jX                  z  k\  rt        jZ                  }t        j\                  |«      r|}||k\  sŒ|}|}Œ„ dk(  r|d   d   }
|d   d   }ne||k(  r%|t_        |«      dz
  k(  s||   d   }
||dz      d   }n;|t_        |«      dz
  k(  r||   d   }
d||   d   z  }n||dz
     d   }
||dz      d   }t        |«      sEt        j*                  t        j,                  |
«      t        j,                  |«      |dz   «      Š‰dd Š‰ j                  s�Œi|	dkD  s�Œpta        d|dz   |	t5        j4                  «       |z
  fz  «       �Œ› t        tI        |Ž «      }t        |d   «      }t        |d   «      Š‰jc                  d«       |jc                  te        tg        «       ‰|‰ jB                  ‰|¬«      «       t        jh                  |«      }dt        jh                  ‰«      i‰ _5        t7        |j
                  d   «      D ]  }|dd…|f   ‰ jj                  d|› d�<   Œ t        j                  |d¬«      ‰ jj                  d<   t        jl                  |d¬«      ‰ jj                  d<   ‰   }|‰ _7        tq        ||‰ jr                  ‰ jt                  ‰ jv                  ‰ jx                  ‰‰ jX                  ¬«      \  ‰ _=        ‰ _>        ‰ _?        ‰ _@        ‰ S # 1 sw Y   �ŒžxY w) aX  Fit the GraphicalLasso covariance model to X.

        Parameters
        ----------
        X : array-like of shape (n_samples, n_features)
            Data from which to compute the covariance estimate.

        y : Ignored
            Not used, present for API consistency by convention.

        **params : dict, default=None
            Parameters to be passed to the CV splitter and the
            cross_val_score function.

            .. versionadded:: 1.5
                Only available if `enable_metadata_routing=True`,
                which can be set by using
                ``sklearn.set_config(enable_metadata_routing=True)``.
                See :ref:`Metadata Routing User Guide <metadata_routing>` for
                more details.

        Returns
        -------
        self : object
            Returns the instance itself.
        rƒ   r   )r¦   r   r   r”   F)Ú
classifierr+   rŒ   )Úmin_valÚmax_valÚinclude_boundariesr®   Néÿÿÿÿ)Úsplit)ÚsplitterrA   )rÅ   r=   c              3   óè   •K  — | ]i  \  }} t        t        «      ‰|   ‰‰|   ‰j                  ‰j                  ‰j                  t        d ‰j                  z  «      ‰‰j                  ¬«	      –— Œk y­w)çš™™™™™¹?)r·   r¸   r9   r:   r;   r<   r=   r>   N)r   r¿   r9   r:   r;   Úintr<   r>   )Ú.0ÚtrainÚtestr¬   r·   r¹   r—   s      €€€€r.   ú	<genexpr>z'GraphicalLassoCV.fit.<locals>.<genexpr>÷  st   øè ø€ ò Oñ $˜˜tð 2”GÔ0Ó1Ø˜%™Ø%Ø  ™wØ!ŸY™YØ ŸH™HØ!%§¡Ü!$ S¨4¯=©=Ñ%8Ó!9Ø -Ø ŸH™H÷
ð 
ñOùs   ƒA/A2T)ÚkeyÚreverserÑ   z8[GraphicalLassoCV] Done refinement % 2i out of %i: % 3is)rÄ   rÅ   r=   Úparamsr·   rÎ   Ú_test_score)ÚaxisÚmean_test_scoreÚstd_test_score)r+   r9   r:   r;   r<   r=   r>   )Ar   r   r�   r#   r©   r"   rª   r«   r   r   rÄ   rT   r·   ru   r=   r   r   r   rV   rÃ   rw   ÚlogspaceÚlog10r   r   r   ÚtimerW   ra   Úcatch_warningsÚsimplefilterr   r   rÅ   rÎ   rÏ   ÚzipÚextendÚsortedÚoperatorÚ
itemgetterÚ	enumeraterž   rŸ   r>   r³   r]   Úlenr_   r`   r   r   ÚarrayÚcv_results_ÚstdÚalpha_rs   r9   r:   r;   r<   rg   r*   r„   r…   )r—   r¬   r­   rÙ   r2   rÄ   ÚpathÚn_alphasr+   rÃ   Úalpha_1Úalpha_0Úrouted_paramsÚt0rj   Ú	this_pathÚcovsrd   ÚscoresÚ
best_scoreÚlast_finite_idxÚindexr¾   Ú
best_indexÚgrid_scoresÚ
best_alphar·   r¹   s   ``                        @@r.   rƒ   zGraphicalLassoCV.fit§  sp  û€ ô: 	˜& $¨Ô.ä˜$ °qÔ9ˆØ×ÒÜŸX™X a§g¡g¨a¡jÓ1ˆD�NàŸV™V A›YˆDŒNÜ& q¸$×:NÑ:NÔOˆä�d—g‘g˜q¨UÔ3ˆô ‹vˆØ—;‘;ˆÜ˜A˜tŸ|™|¨aÑ/Ó0ˆä# HÔ-ØŸ™ò �ÜØØÜØÜŸF™FØ'.öðð —[‘[ˆFØ‰Mà ×.Ñ.ˆMÜ Ó(ˆGØ˜W‘nˆGÜ—[‘[¤§¡¨'Ó!2´B·H±H¸WÓ4EÀxÓPÑQUÐSUÐQUÑVˆFäÔÜ+¨D°%ÑB¸6ÑB‰Mä!¬5°r¬?Ô;ˆMä�Y‰Y‹[ˆÜ�}Ó%ó K	ˆAÜ×(Ñ(Ó*ñ ô ×%Ñ% hÔ0BÔCð OœH¨D¯K©KÀÇÁÔNö Oð (0 r§x¡x°°1Ñ'U¸×8NÑ8N×8TÑ8TÑ'UôOó �	÷ô4 " 9˜o‰OˆD�!�VÜ˜�:ˆDÜ˜&�\ˆFØ�K‰Kœ˜F F¨DÓ1Ô2Ü˜$¤H×$7Ñ$7¸Ó$:ÀDÔIˆDô
 Ÿ&™&˜ˆJØˆOÜ-6°t«_ò 'Ñ)�Ñ)˜˜v qÜŸW™W V›_�
Ø ¤r§x¡x´·
±
Ó';×'?Ñ'?Ñ!?Ò?Ü!#§¡�JÜ—;‘;˜zÔ*Ø&+�OØ Ó+Ø!+�JØ!&‘Jð'ð ˜QŠð ˜q™' !™*�Ø˜q™' !™*‘Ø˜Ò.°zÄSÈÃYÐQRÁ]Ò7Rð ˜zÑ*¨1Ñ-�Ø˜z¨A™~Ñ.¨qÑ1‘Øœs 4›y¨1™}Ò,Ø˜zÑ*¨1Ñ-�Ø  jÑ!1°!Ñ!4Ñ4‘à˜z¨A™~Ñ.¨qÑ1�Ø˜z¨A™~Ñ.¨qÑ1�ä+¨HÔ5ÜŸ™¤R§X¡X¨gÓ%6¼¿¹ÀÓ8IÈ8ÐVWÉ<ÓX�Ø  "˜�à�|Œ| °Ô 1ÜØNØ˜1‘u˜m¬T¯Y©Y«[¸2Ñ-=Ð>ñ?öðQK	ôZ ”C˜�JÓˆÜ˜4 ™7“mˆÜ�d˜1‘g“ˆà�‰�aÔØ×ÑÜÜ#Ó%ØØØ—{‘{Ø%Øôô		
ô —h‘h˜{Ó+ˆà$¤b§h¡h¨vÓ&6Ð7ˆÔä�{×(Ñ(¨Ñ+Ó,ò 	IˆAØ7BÂ1ÀaÀ4Ñ7HˆD×Ñ˜u Q C {Ð3Ò4ð	Iô /1¯g©g°kÈÔ.Jˆ×ÑÐ*Ñ+Ü-/¯V©V°KÀaÔ-Hˆ×ÑÐ)Ñ*à˜JÑ'ˆ
Ø ˆŒô HXØØØ—‘Ø—‘Ø—]‘]Ø—]‘]Ø!Ø—‘ô	H
ÑDˆÔ˜$œ/¨4¬;¸¼ð ˆ÷gñ ús   ÇA4W*×*W4	c                 óÀ   — t        | j                  j                  ¬«      j                  t	        | j
                  «      t        «       j                  dd¬«      ¬«      }|S )aj  Get metadata routing of this object.

        Please check :ref:`User Guide <metadata_routing>` on how the routing
        mechanism works.

        .. versionadded:: 1.5

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        )ÚownerrÎ   rƒ   )ÚcalleeÚcaller)rÏ   Úmethod_mapping)r   r˜   r™   Úaddr   rÄ   r   )r—   Úrouters     r.   Úget_metadata_routingz%GraphicalLassoCV.get_metadata_routingb  sQ   € ô   d§n¡n×&=Ñ&=Ô>×BÑBÜ˜dŸg™gÓ&Ü(›?×.Ñ.°gÀeÐ.ÓLð Có 
ˆð ˆr0   r¯   )r™   rš   r›   r°   r‹   r‘   r   r   rU   rœ   r#   rž   rŸ   r>   r–   r   rƒ   r  r    r¡   s   @r.   rÁ   rÁ   Ë  s»   ø… ñtðl$Ø
×
3Ñ
3ð$á˜H a¨°fÔ=¸|ÐLÙ" 8¨Q°¸VÔDÐEØˆmØ˜TÐ"ò$Ð˜Dó ð ØØØØØØØØØˆB�H‰H�R—Z‘ZÓ ×$Ñ$Øöñ: °Ô5òxó 6ðxötr0   rÁ   );r°   ræ   r´   rà   ra   Únumbersr   r   Únumpyr#   Úscipyr   Úbaser   Ú
exceptionsr   Úlinear_modelr	   rY   r
   Úmodel_selectionr   r   Úutilsr   Úutils._param_validationr   r   r   Úutils.metadata_routingr   r   r   r   r   Úutils.parallelr   r   Úutils.validationr   r   r   r   Ú r   r   r   r/   r4   rž   rŸ   r>   rs   rw   r‰   r‹   r‚   r¿   rÁ   rN   r0   r.   ú<module>r     se  ðñó Û 
Û Û ß "ã Ý å Ý +õ /Ý )ß 7Ý ß KÑ K÷õ ÷ /÷ó ÷ HÑ Gò

ò	ð" Ø	ØØØØØˆ�‰�—‘Ó× Ñ ôB1òJñ& à �>Ø"˜Ø#˜ñð
 #(ôð 
ØØØØØØˆ�‰�—‘Ó× Ñ ØóóðôDÐ,ô ô>Ð'ô ðL ØØ	ØØØØØˆ�‰�—‘Ó× Ñ ó}%ô@iÐ)õ ir0   