ó
cÂY]c           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l 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 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 m Z d „  Z  d „  Z! d „  Z" e# d d d d e$ e$ e j% e j& ƒ j' e$ d „	 Z( d e f d „  ƒ  YZ) e# e# d d d d e$ d „ Z* d e) f d „  ƒ  YZ+ e d ƒ e# d d d d e$ e$ e j% e j& ƒ j' e$ d „	 ƒ Z, e d ƒ d e) f d „  ƒ  Yƒ Z- e d  ƒ d! e+ f d" „  ƒ  Yƒ Z. d S(#   sU   GraphicalLasso: sparse inverse covariance estimation with an l1-penalized
estimator.
iÿÿÿÿN(   t   linalgi   (   t   empirical_covariancet   EmpiricalCovariancet   log_likelihoodi   (   t   ConvergenceWarning(   t   check_random_statet   check_array(   t
   deprecated(   t	   _Sequence(   t	   lars_path(   t   cd_fast(   t   check_cvt   cross_val_score(   t   Parallelt   delayedc         C   su   | j  d } d t |  | ƒ | t j d t j ƒ } | | t j | ƒ j ƒ  t j t j | ƒ ƒ j ƒ  7} | S(   sù   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
    i    g       Ài   (   t   shapeR   t   npt   logt   pit   abst   sumt   diag(   t   mlet
   precision_t   alphat   pt   cost(    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt
   _objective   s
    +!c         C   sa   t  j |  | ƒ } | | j d 8} | | t  j | ƒ j ƒ  t  j t  j | ƒ ƒ j ƒ  7} | S(   s§   Expression of the dual gap convergence criterion

    The specific definition is given in Duchi "Projected Subgradient Methods
    for Learning Sparse Gaussians".
    i    (   R   R   R   R   R   (   t   emp_covR   R   t   gap(    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt	   _dual_gap-   s
    !c         C   sF   t  j |  ƒ } d | j d d | j d d … <t  j t  j | ƒ ƒ S(   s­  Find the maximum alpha for which there are some non-zeros off-diagonal.

    Parameters
    ----------
    emp_cov : 2D array, (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.

    i    Ni   (   R   t   copyt   flatR   t   maxR   (   R   t   A(    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt	   alpha_max:   s    !t   cdg-Cëâ6?id   c         C   s˜  |  j  \ } } | d k rÜ | rª t j |  ƒ } d t |  | ƒ } | | t j d t j ƒ 7} t j |  | ƒ | } |
 r” |  | | | f d f S|  | | | f f SqÜ |
 rÆ |  t j |  ƒ d f S|  t j |  ƒ f Sn  | d k r÷ |  j	 ƒ  } n | j	 ƒ  } | d 9} |  j
 d d | d … } | | j
 d d | d … <t j | ƒ } t j | ƒ } t ƒ  } | d k rŒt d d	 d
 d ƒ } n t d
 d	 ƒ } yut j } t j	 | d d … d d … f d d ƒ} x:t | ƒ D]} xFt | ƒ D]8} | d k rY| d } | | | | k | | <| d d … | f | | k | d d … | f <n | d d … d d … f | (|  | | | k f } t j |   Ç | d k r| | | k | f | | | f d |	 } t j | | d | | | | | t d ƒ t ƒ
 \ } } } } nJ t | | d | d | d | | d d t d |	 d d d t ƒ\ } } } Wd QXd | | | f t j | | | k | f | ƒ | | | f <| | | f | | | | k | f <| | | f | | | | | k f <t j | | ƒ } | | | | | k f <| | | | k | f <qòWt j | j ƒ  ƒ sRt d ƒ ‚ n  t |  | | ƒ } t |  | | ƒ } | r‘d | | | f GHn  | r­| j | | f ƒ n  t j | ƒ | k  rÆPn  t j | ƒ rß| d k rßt d ƒ ‚ qßqßWt j  d | | f t! ƒ Wn0 t k
 rB} | j" d d f | _" | ‚ n X| rs|
 rc| | | | d f S| | | f Sn! |
 rŠ| | | d f S| | f Sd S(   sº
  l1-penalized covariance estimator

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

    Parameters
    ----------
    emp_cov : 2D ndarray, shape (n_features, n_features)
        Empirical covariance from which to compute the covariance estimate.

    alpha : positive float
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.

    cov_init : 2D array (n_features, n_features), optional
        The initial guess for the covariance.

    mode : {'cd', 'lars'}
        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 : positive float, optional
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, optional
        The maximum number of iterations.

    verbose : boolean, optional
        If verbose is True, the objective function and dual gap are
        printed at each iteration.

    return_costs : boolean, optional
        If return_costs is True, the objective function and dual gap
        at each iteration are returned.

    eps : float, optional
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems.

    return_n_iter : bool, optional
        Whether or not to return the number of iterations.

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

    precision : 2D ndarray, 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, GraphicalLassoCV

    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.

    i    g       Ài   gffffffî?Ni   R$   t   overt   raiset   invalidt   ignoret   ordert   Ciè  t   Xyt   Gramt	   alpha_mint	   copy_Gramt   epst   methodt   larst   return_pathg      ð?s1   The system is too ill-conditioned for this solvers<   [graphical_lasso] Iteration % 3i, cost % 3.2e, dual gap %.3esA   Non SPD result: the system is too ill-conditioned for this solversD   graphical_lasso: did not converge after %i iteration: dual gap: %.3es3   . The system is too ill-conditioned for this solver(#   R   R    t   invR   R   R   R   R   t   NoneR   R    t   pinvht   aranget   listt   dictt   inft   ranget   errstateR
   t   enet_coordinate_descent_gramR   t   FalseR	   t   Truet   dott   isfinitet   FloatingPointErrorR   R   t   appendR   t   warningst   warnR   t   args(   R   R   t   cov_initt   modet   tolt   enet_tolt   max_itert   verboset   return_costsR/   t   return_n_itert   _t
   n_featuresR   R   t   d_gapt   covariance_t   diagonalt   indicest   costst   errorst   sub_covariancet   it   idxt   dit   rowt   coefst   e(    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   graphical_lassoQ   s¦    S
		+
3!$.	

t   GraphicalLassoc           B   s8   e  Z d  Z d d d d d e e d „ Z d d „ Z RS(   s;  Sparse inverse covariance estimation with an l1-penalized estimator.

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

    Parameters
    ----------
    alpha : positive float, default 0.01
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.

    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 : positive float, default 1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, default 100
        The maximum number of iterations.

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

    assume_centered : boolean, 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
    ----------
    covariance_ : array-like, shape (n_features, n_features)
        Estimated covariance matrix

    precision_ : array-like, shape (n_features, n_features)
        Estimated pseudo inverse matrix.

    n_iter_ : int
        Number of iterations run.

    See Also
    --------
    graphical_lasso, GraphicalLassoCV
    g{®Gáz„?R$   g-Cëâ6?id   c         C   sS   t  t |  ƒ j d | ƒ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   Nt   assume_centered(	   t   superR^   t   __init__R   RG   RH   RI   RJ   RK   (   t   selfR   RG   RH   RI   RJ   RK   R_   (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyRa   R  s    					c         C   sÈ   t  | d d d d d |  ƒ} |  j rC t j | j d ƒ |  _ n | j d ƒ |  _ t | d |  j ƒ} t | d |  j	 d	 |  j
 d
 |  j d |  j d |  j d |  j d t ƒ\ |  _ |  _ |  _ |  S(   sÛ   Fits the GraphicalLasso model to X.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Data from which to compute the covariance estimate
        y : (ignored)
        t   ensure_min_featuresi   t   ensure_min_samplest	   estimatori   i    R_   R   RG   RH   RI   RJ   RK   RM   (   R   R_   R   t   zerosR   t	   location_t   meanR   R]   R   RG   RH   RI   RJ   RK   R>   RQ   R   t   n_iter_(   Rb   t   Xt   yR   (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   fit\  s    
		!$N(   t   __name__t
   __module__t   __doc__R=   Ra   R4   Rl   (    (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyR^     s   5	c	         C   sí  t  d | d ƒ }	 t |  ƒ }
 | d k r: |
 j ƒ  } n | } t ƒ  } t ƒ  } t ƒ  } | d k	 rv t | ƒ } n  xQ| D]I} yx t |
 d | d | d | d | d | d | d	 |	 ƒ\ } } | j | ƒ | j | ƒ | d k	 rú t | | ƒ } n  Wn; t k
 r8t	 j
 } | j t	 j ƒ | j t	 j ƒ n X| d k	 rqt	 j | ƒ sat	 j
 } n  | j | ƒ n  | d k rt j j d
 ƒ q} | d k r} | d k	 rºd | | f GHqÆd | GHq} q} W| d k	 rã| | | f S| | f S(   ss  l1-penalized covariance estimator along a path of decreasing alphas

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

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

    alphas : list of positive floats
        The list of regularization parameters, decreasing order.

    cov_init : 2D array (n_features, n_features), optional
        The initial guess for the covariance.

    X_test : 2D array, shape (n_test_samples, n_features), optional
        Optional test matrix to measure generalisation error.

    mode : {'cd', 'lars'}
        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 : positive float, optional
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, optional
        The maximum number of iterations.

    verbose : integer, optional
        The higher the verbosity flag, the more information is printed
        during the fitting.

    Returns
    -------
    covariances_ : List of 2D ndarray, shape (n_features, n_features)
        The estimated covariance matrices.

    precisions_ : List of 2D ndarray, shape (n_features, n_features)
        The estimated (sparse) precision matrices.

    scores_ : List of float
        The generalisation error (log-likelihood) on the test data.
        Returned only if test data is passed.
    i    i   R   RF   RG   RH   RI   RJ   RK   t   .s/   [graphical_lasso_path] alpha: %.2e, score: %.2es"   [graphical_lasso_path] alpha: %.2eN(   R!   R   R4   R   R7   R]   RB   R   RA   R   R9   t   nanR@   t   syst   stderrt   write(   Rj   t   alphasRF   t   X_testRG   RH   RI   RJ   RK   t   inner_verboseR   RQ   t   covariances_t   precisions_t   scores_t   test_emp_covR   R   t
   this_score(    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   graphical_lasso_pathw  sJ    6			
t   GraphicalLassoCVc           B   s\   e  Z d  Z d d d d d d d d
 e e d „
 Z e e d ƒ d „  ƒ ƒ Z d
 d	 „ Z	 RS(   s†  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>`.

    Parameters
    ----------
    alphas : integer, or list positive float, optional
        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.

    n_refinements : strictly positive integer
        The number of times the grid is refined. Not used if explicit
        values of alphas are passed.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-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:`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 will change from 3-fold to 5-fold
            in v0.22.

    tol : positive float, optional
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, optional
        Maximum number of iterations.

    mode : {'cd', 'lars'}
        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 or None, optional (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.

    verbose : boolean, optional
        If verbose is True, the objective function and duality gap are
        printed at each iteration.

    assume_centered : boolean
        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
    ----------
    covariance_ : numpy.ndarray, shape (n_features, n_features)
        Estimated covariance matrix.

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

    alpha_ : float
        Penalization parameter selected.

    cv_alphas_ : list of float
        All penalization parameters explored.

    grid_scores_ : 2D numpy.ndarray (n_alphas, n_folds)
        Log-likelihood score on left-out data across folds.

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

    See Also
    --------
    graphical_lasso, GraphicalLasso

    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.
    i   RD   g-Cëâ6?id   R$   c         C   s_   t  t |  ƒ j d | d | d |	 d | d | d |
 ƒ | |  _ | |  _ | |  _ | |  _ d  S(   NRG   RH   RK   RI   RJ   R_   (   R`   R~   Ra   Ru   t   n_refinementst   cvt   n_jobs(   Rb   Ru   R   R€   RH   RI   RJ   RG   R   RK   R_   (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyRa   E  s    			sn   Attribute grid_scores was deprecated in version 0.19 and will be removed in 0.21. Use ``grid_scores_`` insteadc         C   s   |  j  S(   N(   t   grid_scores_(   Rb   (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   grid_scoresP  s    c            sñ  t  ˆ  d d d ˆ ƒ‰  ˆ j r= t j ˆ  j d ƒ ˆ _ n ˆ  j d ƒ ˆ _ t ˆ  d ˆ j ƒ} t ˆ j	 | d t
 ƒ} t ƒ  } ˆ j } t d ˆ j d ƒ ‰ t | t ƒ rÅ ˆ j ‰ d } nS ˆ j } t | ƒ } d | }	 t j t j |	 ƒ t j | ƒ | ƒ d	 d	 d
 … ‰ t j ƒ  }
 x×t | ƒ D]É} t j ƒ  [ t j d t ƒ t d ˆ j d ˆ j ƒ ‡  ‡ ‡ ‡ f d †  | j ˆ  | ƒ Dƒ ƒ } Wd	 QXt | Œ  \ } } } t | Œ  } t | Œ  } | j t ˆ | | ƒ ƒ t  | d t! j" d ƒ d t# ƒ} t j$ } d } x t% | ƒ D]‚ \ } \ } } } t j | ƒ } | d t j& t j' ƒ j( k rst j) } n  t j* | ƒ r‹| } n  | | k r$| } | } q$q$W| d k rÕ| d d } | d d }	 n£ | | k r| t+ | ƒ d k r| | d } | | d d }	 n] | t+ | ƒ d k rT| | d } d | | d }	 n$ | | d d } | | d d }	 t | t ƒ sÂt j t j | ƒ t j |	 ƒ | d ƒ ‰ ˆ d d
 !‰ n  ˆ j r1| d k r1d | d | t j ƒ  |
 f GHq1q1Wt t | Œ  ƒ } t | d ƒ } t | d ƒ ‰ ˆ j, d ƒ | j, t- t. ƒ  ˆ  d | d ˆ j d ˆ ƒƒ t j/ | ƒ ˆ _0 ˆ | } | ˆ _1 ˆ ˆ _2 t3 | d | d ˆ j4 d ˆ j5 d ˆ j6 d ˆ j7 d ˆ d t# ƒ\ ˆ _8 ˆ _9 ˆ _: ˆ S(   sæ   Fits the GraphicalLasso covariance model to X.

        Parameters
        ----------
        X : ndarray, shape (n_samples, n_features)
            Data from which to compute the covariance estimate
        y : (ignored)
        Rc   i   Re   i   i    R_   t
   classifierg{®Gáz„?NiÿÿÿÿR(   R   RK   c         3   so   |  ]e \ } } t  t ƒ ˆ  | d  ˆ d ˆ  | d ˆ j d ˆ j d ˆ j d t d ˆ j ƒ d ˆ ƒVq d S(	   Ru   Rv   RG   RH   RI   RJ   gš™™™™™¹?RK   N(   R   R}   RG   RH   RI   t   intRJ   (   t   .0t   traint   test(   Rj   Ru   Rw   Rb   (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pys	   <genexpr>ˆ  s   t   keyt   reversegš™™™™™¹?s8   [GraphicalLassoCV] Done refinement % 2i out of %i: % 3isR€   R   RG   RH   RI   RJ   RM   (;   R   R_   R   Rf   R   Rg   Rh   R   R   R€   R=   R7   Ru   R!   RK   t
   isinstancet   SequenceR   R#   t   logspacet   log10t   timeR:   RC   t   catch_warningst   simplefilterR   R   R   t   splitt   zipt   extendt   sortedt   operatort
   itemgetterR>   R9   t	   enumeratet   finfot   float64R/   Rq   R@   t   lenRB   R   R   t   arrayR‚   t   alpha_t
   cv_alphas_R]   RG   RH   RI   RJ   RQ   R   Ri   (   Rb   Rj   Rk   R   R€   t   patht   n_alphasR   t   alpha_1t   alpha_0t   t0RW   t	   this_patht   covsRN   t   scorest
   best_scoret   last_finite_idxt   indexR   R|   t
   best_indexRƒ   t
   best_alpha(    (   Rj   Ru   Rw   Rb   s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyRl   V  sœ    
						
		!
"	$

		!N(
   Rm   Rn   Ro   R4   R=   Ra   t   propertyR   Rƒ   Rl   (    (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyR~   Ø  s   k	s_   The 'graph_lasso' was renamed to 'graphical_lasso' in version 0.20 and will be removed in 0.22.c         C   s(   t  |  | | | | | | | | |	 |
 ƒ S(   s²
  l1-penalized covariance estimator

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

    Parameters
    ----------
    emp_cov : 2D ndarray, shape (n_features, n_features)
        Empirical covariance from which to compute the covariance estimate.

    alpha : positive float
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.

    cov_init : 2D array (n_features, n_features), optional
        The initial guess for the covariance.

    mode : {'cd', 'lars'}
        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 : positive float, optional
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, optional
        The maximum number of iterations.

    verbose : boolean, optional
        If verbose is True, the objective function and dual gap are
        printed at each iteration.

    return_costs : boolean, optional
        If return_costs is True, the objective function and dual gap
        at each iteration are returned.

    eps : float, optional
        The machine-precision regularization in the computation of the
        Cholesky diagonal factors. Increase this for very ill-conditioned
        systems.

    return_n_iter : bool, optional
        Whether or not to return the number of iterations.

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

    precision : 2D ndarray, 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
    --------
    GraphLasso, GraphLassoCV

    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.

    (   R]   (   R   R   RF   RG   RH   RI   RJ   RK   RL   R/   RM   (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   graph_lassoÚ  s    Us]   The 'GraphLasso' was renamed to 'GraphicalLasso' in version 0.20 and will be removed in 0.22.t
   GraphLassoc           B   s   e  Z d  Z RS(   sm  Sparse inverse covariance estimation with an l1-penalized estimator.

    This class implements the Graphical Lasso algorithm.

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

    Parameters
    ----------
    alpha : positive float, default 0.01
        The regularization parameter: the higher alpha, the more
        regularization, the sparser the inverse covariance.

    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 : positive float, default 1e-4
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, default 100
        The maximum number of iterations.

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

    assume_centered : boolean, 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
    ----------
    covariance_ : array-like, shape (n_features, n_features)
        Estimated covariance matrix

    precision_ : array-like, shape (n_features, n_features)
        Estimated pseudo inverse matrix.

    n_iter_ : int
        Number of iterations run.

    See Also
    --------
    graph_lasso, GraphLassoCV
    (   Rm   Rn   Ro   (    (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyR®   4  s   9sa   The 'GraphLassoCV' was renamed to 'GraphicalLassoCV' in version 0.20 and will be removed in 0.22.t   GraphLassoCVc           B   s   e  Z d  Z RS(   s¸  Sparse inverse covariance w/ cross-validated choice of the l1 penalty.

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

    This class implements the Graphical Lasso algorithm.

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

    Parameters
    ----------
    alphas : integer, or list positive float, optional
        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.

    n_refinements : strictly positive integer
        The number of times the grid is refined. Not used if explicit
        values of alphas are passed.

    cv : int, cross-validation generator or an iterable, optional
        Determines the cross-validation splitting strategy.
        Possible inputs for cv are:

        - None, to use the default 3-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:`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 will change from 3-fold to 5-fold
            in v0.22.

    tol : positive float, optional
        The tolerance to declare convergence: if the dual gap goes below
        this value, iterations are stopped.

    enet_tol : positive float, optional
        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'.

    max_iter : integer, optional
        Maximum number of iterations.

    mode : {'cd', 'lars'}
        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 or None, optional (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.

    verbose : boolean, optional
        If verbose is True, the objective function and duality gap are
        printed at each iteration.

    assume_centered : Boolean
        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
    ----------
    covariance_ : numpy.ndarray, shape (n_features, n_features)
        Estimated covariance matrix.

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

    alpha_ : float
        Penalization parameter selected.

    cv_alphas_ : list of float
        All penalization parameters explored.

    grid_scores_ : 2D numpy.ndarray (n_alphas, n_folds)
        Log-likelihood score on left-out data across folds.

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

    See Also
    --------
    graph_lasso, GraphLasso

    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.
    (   Rm   Rn   Ro   (    (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyR¯   p  s   o(/   Ro   RC   R–   Rr   R   t   numpyR   t   scipyR    t   empirical_covariance_R   R   R   t
   exceptionsR   t   utils.validationR   R   t   utilsR   t   utils.fixesR   RŒ   t   linear_modelR	   R
   t   model_selectionR   R   t   utils._joblibR   R   R   R   R#   R4   R=   R™   Rš   R/   R]   R^   R}   R~   R­   R®   R¯   (    (    (    s>   lib/python2.7/site-packages/sklearn/covariance/graph_lasso_.pyt   <module>   sH   					Ç\	`ÿ 			U: