Ë
    uwjÊŸ  ã            
       ó¢  — 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mZ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„ 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)ÚEmpiricalCovarianceÚempirical_covarianceÚlog_likelihood)Ú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_datac                 ó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   ç       Àé   )Úshaper	   ÚnpÚlogÚpiÚabsÚsumÚdiag)ÚmleÚ
precision_ÚalphaÚpÚcosts        úd/var/www/html/newmanjeet/manjet/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_gapr3   :   sr   € ô �&‰&�˜:Ñ%Ó
&€CØˆ:×Ñ˜AÑÑ€CØˆ5”B—F‘F˜:Ó&×*Ñ*Ó,¬r¯v©v´b·g±g¸jÓ6IÓ/J×/NÑ/NÓ/PÑPÑQÑQ€CØ€Jr/   Ú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 �]e  }|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(  rS|||k7  |f   |||f   d|z  z   z   }t#        j$                  ||d|||t'        d|«      |t)        d «      d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<   �Œh t	        j0                  |j                  «       «      st3        d«      ‚t5        | ||«      }t7        | ||«      }|rt9        d|||fz  «       |j;                  ||f«       t	        j<                  |«      |k  r nIt	        j0                  |«      r�Œ|dkD  s�Œt3        d«      ‚ t?        j@                  d||fz  tB        «       ||||dz   fS # 1 sw Y   �ŒexY w# t2        $ r}|jD                  d   dz   f|_"        |‚d }~ww xY w)Nr   r   r    gffffffî?é   r4   ÚraiseÚignore)ÚoverÚinvalid)rC   ÚC)Úorderiè  é   FT)Úwr*   ÚbetaÚQÚqÚyr;   r9   ÚrngÚrandomÚpositiveÚdo_screeningÚ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_gramÚmaxr   r   ÚsizeÚdotÚisfiniteÚFloatingPointErrorr3   r.   ÚprintÚappendr%   ÚwarningsÚwarnr
   Úargs)r1   r*   r7   r8   r9   r:   r;   r<   r=   Ú_Ú
n_featuresr)   r,   Úd_gapÚcovariance_ÚdiagonalÚindicesÚiÚcostsÚerrorsÚsub_covarianceÚidxÚdiÚrowÚcoefsÚes                             r-   Ú_graphical_lassor~   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Ô&ˆð[ô —‘ˆäŸ™ ¨Q©R°±¨VÑ!4¸CÔ@ˆÜ�x—ˆAÜ˜Z×(�ð ˜’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Ø#Ø"'Ø!"Ø,Ø!Ø!ô &)¨¨XÓ%6Ø (Ü 2°4Ó 8Ø#(Ø%*Ø)-ô#*™˜˜q !¡Qô( '5Ø"Ø!/Ø&)§h¡hØ&+¨z¸A©~Ñ&>Ø&*Ø #Ø#)Ø(-ô	'™˜˜1˜e÷7 +ðL (+Ø  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ðs )ôt —;‘;˜zŸ~™~Ó/Ô0Ü(ØGóð ô ˜g z°5Ó9ˆEÜ˜g z°5Ó9ˆDÙÜØRØ˜$ Ð&ñ'ôð �L‰L˜$ ˜Ô'Ü�v‰v�e‹}˜sÒ"ÙÜ—;‘;˜tÖ$¨¨Q¬Ü(ØWóð ðU !ô\ �M‰MØVØ˜UÐ#ñ$ä"ôð ˜
 E¨1¨q©5Ð0Ð0÷W +Ñ*ûôN ò Ø—&‘&˜‘)ÐSÑSÐUˆŒØˆûðús?   Ä0B*O
 ÇB N=ÉD&O
 ÎO
 Î	+O
 Î=OÏO
 Ï
	O2ÏO-Ï-O2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"   rZ   r[   r!   re   r%   )r1   ÚAs     r-   Ú	alpha_maxr�   Ó   sI   € ô 	�‰�Ó€AØ !€A‡F�FÑˆa�g‰g�a‰j˜1‰nÐÑÜ�6‰6”"—&‘&˜“)ÓÐr/   ú
array-likeÚboolean)r1   Úreturn_costsÚreturn_n_iter©Úprefer_skip_nested_validation)r8   r9   r:   r;   r<   r„   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.687,  0.212, -0.209],
           [ 0.212,  0.221, -0.0817],
           [-0.209, -0.0817, 0.232]])
    ÚprecomputedT)	r*   r8   Ú
covariancer9   r:   r;   r<   r=   Úassume_centered)ÚGraphicalLassoÚfitrr   r)   rk   Úcosts_Ún_iter_Útuple)r1   r*   r8   r9   r:   r;   r<   r„   r=   r…   ÚmodelÚoutputs               r-   Úgraphical_lassor“   æ   s€   € ôl ØØØ ØØØØØØô
÷ 
�cˆ'ƒlð 
ð ×Ñ ×!1Ñ!1Ð2€FÙØ�‰�e—l‘lÔ#ÙØ�‰�e—m‘mÔ$Ü�‹=Ðr/   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Úleftr4   rP   r<   Úboth)r9   r:   r;   r8   r<   r=   Ú_parameter_constraintsÚstore_precisionr5   r6   Fc                 óz   •— t         ‰| �  |¬«       || _        || _        || _        || _        || _        || _        y )N©r‹   )ÚsuperÚ__init__r9   r:   r;   r8   r<   r=   )	Úselfr9   r:   r;   r8   r<   r=   r‹   Ú	__class__s	           €r-   r    zBaseGraphicalLasso.__init__|  s?   ø€ ô 	‰Ñ¨ÐÔ9ØˆŒØ ˆŒØ ˆŒØˆŒ	ØˆŒØˆ�r/   )Ú__name__Ú
__module__Ú__qualname__r   r›   r   r   r   r   r_   Ú__annotations__Úpopr"   ÚfinfoÚfloat64r=   r    Ú__classcell__©r¢   s   @r-   r•   r•   p  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Ó ×$Ñ$Ø÷ñ r/   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›   r4   r5   r6   F)r8   rŠ   r9   r:   r;   r<   r=   r‹   c          	      óN   •— t         ‰
| �  |||||||	¬«       || _        || _        y ©N)r9   r:   r;   r8   r<   r=   r‹   )rŸ   r    r*   rŠ   )r¡   r*   r8   rŠ   r9   r:   r;   r<   r=   r‹   r¢   s             €r-   r    zGraphicalLasso.__init__  s<   ø€ ô 	‰ÑØØØØØØØ+ð 	ô 	
ð ˆŒ
Ø$ˆ�r/   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*   r7   r8   r9   r:   r;   r<   r=   )r   rŠ   rZ   r"   Úzerosr!   Ú	location_r   r‹   Úmeanr~   r*   r8   r9   r:   r;   r<   r=   rr   r)   rŽ   r�   )r¡   ÚXrK   r1   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¬;¸¼ð ˆr/   )ç{®Gáz„?©N)r£   r¤   r¥   Ú__doc__r•   r›   r   r   r   r_   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ô(r/   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)re   r   rZ   r^   r~   rk   r	   ri   r"   r`   Únanrh   ÚsysÚstderrÚwriterj   )r¶   Úalphasr7   ÚX_testr8   r9   r:   r;   r<   r=   Úinner_verboser1   rr   Úcovariances_Úprecisions_Úscores_Útest_emp_covr*   r)   ro   Ú
this_scores                        r-   Úgraphical_lasso_pathrÈ   R  s¢  € ôV ˜˜7 Q™;Ó'€MÜ" 1Ó%€GØÐØ—l‘l“n‰àˆÜ“6€LÜ“&€KÜ‹f€GØÐÜ+¨FÓ3ˆãˆð	'ä,<ØØØ$ØØØ!Ø!Ø%Øô
-Ñ)ˆK˜ Q¨ð ×Ñ Ô,Ø×Ñ˜zÔ*ØÐ!Ü+¨L¸*ÓE�
ð
 ÐÜ—;‘;˜zÔ*Ü Ÿf™f˜W�
Ø�N‰N˜:Ô&Ø�aŠ<Ü�J‰J×Ñ˜SÕ!Ø�q‹[ØÐ!ÜØEØ˜jÐ)ñ*õô
 Ð:¸UÑBÕCðG ð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 )ÚGraphicalLassoCVaI  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])

    For an example comparing :class:`sklearn.covariance.GraphicalLassoCV`,
    :func:`sklearn.covariance.ledoit_wolf` shrinkage and the empirical covariance
    on high-dimensional gaussian data, see
    :ref:`sphx_glr_auto_examples_covariance_plot_sparse_cov.py`.
    r   Nr™   r—   r‚   r?   Ú	cv_object)rÀ   Ún_refinementsÚcvÚn_jobsr›   é   r5   r6   r4   F)rÀ   rÌ   rÍ   r9   r:   r;   r8   rÎ   r<   r=   r‹   c          	      ój   •— t         ‰| �  |||||	|
|¬«       || _        || _        || _        || _        y r®   )rŸ   r    rÀ   rÌ   rÍ   rÎ   )r¡   rÀ   rÌ   rÍ   r9   r:   r;   r8   rÎ   r<   r=   r‹   r¢   s               €r-   r    zGraphicalLassoCV.__init__–  sK   ø€ ô 	‰ÑØØØØØØØ+ð 	ô 	
ð ˆŒØ*ˆÔØˆŒØˆ�r/   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Á   r8   r9   r:   r;   r<   r=   N)r   rÈ   r8   r9   r:   Úintr;   r=   )Ú.0ÚtrainÚtestr¶   rÀ   rÂ   r¡   s      €€€€r-   Ú	<genexpr>z'GraphicalLassoCV.fit.<locals>.<genexpr>  sw   øè ø€ ð Oñ (V™˜˜tð 2”GÔ0Ó1Ø˜%™Ø%Ø  ™wØ!ŸY™YØ ŸH™HØ!%§¡Ü!$ S¨4¯=©=Ñ%8Ó!9Ø -Ø ŸH™H÷
ð 
ñ (Vù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*   r8   r9   r:   r;   r<   r=   )Ar   r   r‹   r"   r³   r!   r´   rµ   r   r   rÍ   r^   rÀ   re   r<   r   r   r   r`   rÌ   r�   ÚlogspaceÚlog10r   r   r   Útimera   rl   Úcatch_warningsÚsimplefilterr
   r   rÎ   r×   rØ   ÚzipÚextendÚsortedÚoperatorÚ
itemgetterÚ	enumerater¨   r©   r=   r¼   rh   Úlenrj   rk   r   r   ÚarrayÚcv_results_ÚstdÚalpha_r~   r8   r9   r:   r;   rr   r)   rŽ   r�   )r¡   r¶   rK   râ   r1   rÍ   ÚpathÚn_alphasr*   rÌ   Úalpha_1Úalpha_0Úrouted_paramsÚt0ru   Ú	this_pathÚcovsro   ÚscoresÚ
best_scoreÚlast_finite_idxÚindexrÇ   Ú
best_indexÚgrid_scoresÚ
best_alpharÀ   rÂ   s   ``                        @@r-   r�   zGraphicalLassoCV.fit³  sQ  û€ ô: 	˜& $¨Ô.ä˜$ °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‹[ˆÜ�}×%ˆ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 &ôZ ”C˜�JÓˆÜ˜4 ™7“mˆÜ�d˜1‘g“ˆà�‰�aÔØ×ÑÜÜ#Ó%ØØØ—{‘{Ø%Øôô		
ô —h‘h˜{Ó+ˆà$¤b§h¡h¨vÓ&6Ð7ˆÔä�{×(Ñ(¨Ñ+Ö,ˆAØ7BÂ1ÀaÀ4Ñ7HˆD×Ñ˜u Q C {Ð3Ò4ð -ô /1¯g©g°kÈÔ.Jˆ×ÑÐ*Ñ+Ü-/¯V©V°KÀaÔ-Hˆ×ÑÐ)Ñ*à˜JÑ'ˆ
Ø ˆŒô HXØØØ—‘Ø—‘Ø—]‘]Ø—]‘]Ø!Ø—‘ô	H
ÑDˆÔ˜$œ/¨4¬;¸¼ð ˆ÷g +Ñ*ús   ÇA4W*×*W4	c                 ó˜   — t        | ¬«      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   Úaddr   rÍ   r   )r¡   Úrouters     r-   Úget_metadata_routingz%GraphicalLassoCV.get_metadata_routingn  sF   € ô   dÔ+×/Ñ/Ü˜dŸg™gÓ&Ü(›?×.Ñ.°gÀeÐ.ÓLð 0ó 
ˆð ˆr/   r¸   )r£   r¤   r¥   r¹   r•   r›   r   r   r_   r¦   r"   r¨   r©   r=   r    r   r�   r  rª   r«   s   @r-   rÊ   rÊ   Ò  s»   ø… ñyðv$Ø
×
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r/   rÊ   );r¹   rï   r½   ré   rl   Únumbersr   r   Únumpyr"   Úscipyr   Úsklearn.baser   Úsklearn.covariancer   r   r	   Úsklearn.exceptionsr
   Úsklearn.linear_modelr   rc   r   Úsklearn.model_selectionr   r   Úsklearn.utilsr   Úsklearn.utils._param_validationr   r   r   Úsklearn.utils.metadata_routingr   r   r   r   r   Úsklearn.utils.parallelr   r   Úsklearn.utils.validationr   r   r   r   r.   r3   r¨   r©   r=   r~   r�   r“   r•   rŒ   rÈ   rÊ   rX   r/   r-   Ú<module>r     sb  ðñó Û 
Û Û ß "ã Ý å %ß XÑ XÝ 1õ 5Ý /ß =Ý ß QÑ Q÷õ ÷ 5÷ó ò
ò	ð" Ø	ØØØØØˆ�‰�—‘Ó× Ñ ôI1òXñ& à �>Ø"˜Ø#˜ñð
 #(ôð 
ØØØØØØˆ�‰�—‘Ó× Ñ ØóóðôDÐ,ô ô>Ð'ô ðL ØØ	ØØØØØˆ�‰�—‘Ó× Ñ ó}%ô@nÐ)õ nr/   