ó
‡ˆ\c           @   sj  d  Z  d d l Z d d l m Z d d l 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 d d l m Z m Z d Z d e e d „ Z d d e e e d „ Z d d e e e e d „ Z d d d e e e e d „ Z d e e f d „  ƒ  YZ e e e d d „ Z  d e e f d „  ƒ  YZ! d S(   s'   Orthogonal matching pursuit algorithms
iÿÿÿÿN(   t   sqrt(   t   linalg(   t   get_lapack_funcsi   (   t   LinearModelt   _pre_fiti   (   t   RegressorMixin(   t   as_float_arrayt   check_arrayt	   check_X_y(   t   check_cv(   t   Parallelt   delayedsŒ    Orthogonal matching pursuit ended prematurely due to linear
dependence in the dictionary. The requested precision might not have been met.
c         C   s=  | r |  j  d ƒ }  n t j |  ƒ }  t j |  j ƒ j } t j d |  f ƒ \ } } t d |  f ƒ \ }	 t j	 |  j
 | ƒ }
 | } t j d ƒ } d } t j |  j d ƒ } | d
 k	 rË |  j d n | } t j | | f d |  j ƒ} | rt j | ƒ } n  xît r÷t j t j t j	 |  j
 | ƒ ƒ ƒ } | | k  sW|
 | d | k  rqt j t t d	 d ƒPn  | d k rœt j	 |  d
 d
 … d
 | … f j
 |  d
 d
 … | f ƒ | | d
 | … f <t j | d
 | … d
 | … f | | d
 | … f d d d d d t d t ƒ| | | d
 | … f ƒ d } t j |  d
 d
 … | f ƒ d | } | | k rƒt j t t d	 d ƒPn  t | ƒ | | | f <n# t j |  d
 d
 … | f ƒ | d <| |  j
 | |  j
 | ƒ \ |  j
 | <|  j
 | <|
 | |
 | |
 | <|
 | <| | | | | | <| | <| d 7} |	 | d
 | … d
 | … f |
 |  d t d t ƒ\ } } | r’| | d
 | … | d f <n  | t j	 |  d
 d
 … d
 | … f | ƒ } | d
 k	 rä| | ƒ d | k räPq
| | k r
Pq
q
W| r(| | |  | d
 d
 … d
 | … f | f S| | |  | f Sd
 S(   sv  Orthogonal Matching Pursuit step using the Cholesky decomposition.

    Parameters
    ----------
    X : array, shape (n_samples, n_features)
        Input dictionary. Columns are assumed to have unit norm.

    y : array, shape (n_samples,)
        Input targets

    n_nonzero_coefs : int
        Targeted number of non-zero elements

    tol : float
        Targeted squared error, if not None overrides n_nonzero_coefs.

    copy_X : bool, optional
        Whether the design matrix X must be copied by the algorithm. A false
        value is only helpful if X is already Fortran-ordered, otherwise a
        copy is made anyway.

    return_path : bool, optional. Default: False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

    Returns
    -------
    gamma : array, shape (n_nonzero_coefs,)
        Non-zero elements of the solution

    idx : array, shape (n_nonzero_coefs,)
        Indices of the positions of the elements in gamma within the solution
        vector

    coef : array, shape (n_features, n_nonzero_coefs)
        The first k values of column k correspond to the coefficient value
        for the active features at that step. The lower left triangle contains
        garbage. Only returned if ``return_path=True``.

    n_active : int
        Number of active features at convergence.
    t   Ft   nrm2t   swapt   potrsi    i   t   dtypei   t
   stacklevelNt   transt   lowert   overwrite_bt   check_finite(   R   R   (   R   (   i    i    (   t   copyt   npt   asfortranarrayt   finfoR   t   epsR   t   get_blas_funcsR   t   dott   Tt   emptyt   aranget   shapet   Nonet
   empty_liket   Truet   argmaxt   abst   warningst   warnt	   prematuret   RuntimeWarningt   solve_triangulart   Falset   normR    (   t   Xt   yt   n_nonzero_coefst   tolt   copy_Xt   return_patht	   min_floatR   R   R   t   alphat   residualt   gammat   n_activet   indicest   max_featurest   Lt   coefst   lamt   vt   Lkkt   _(    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   _cholesky_omp   sd    ,	' K '#1
,,"*c         C   s_  | r |  j  d ƒ n t j |  ƒ }  | s7 | j j rF | j  ƒ  } n  t j |  j ƒ j } t j	 d |  f ƒ \ }	 }
 t
 d |  f ƒ \ } t j t |  ƒ ƒ } | } | } d } t j d ƒ } d } | d k	 rß t |  ƒ n | } t j | | f d |  j ƒ} d | d <| r%t j | ƒ } n  xòt rt j t j | ƒ ƒ } | | k  sf| | d | k  r€t j t t d	 d
 ƒPn  | d k rs|  | d | … f | | d | … f <t j | d | … d | … f | | d | … f d d d d d t d t ƒ|	 | | d | … f ƒ d } |  | | f | } | | k rZt j t t d	 d
 ƒPn  t | ƒ | | | f <n t |  | | f ƒ | d <|
 |  | |  | ƒ \ |  | <|  | <|
 |  j | |  j | ƒ \ |  j | <|  j | <| | | | | | <| | <| | | | | | <| | <| d 7} | | d | … d | … f | |  d t d t ƒ\ } } | r…| | d | … | d f <n  t j |  d d … d | … f | ƒ } | | } | d k	 r| | 7} t j | | |  ƒ } | | 8} t | ƒ | k rPqq(| | k r(Pq(q(W| rJ| | |  | d d … d | … f | f S| | |  | f Sd S(   s|  Orthogonal Matching Pursuit step on a precomputed Gram matrix.

    This function uses the Cholesky decomposition method.

    Parameters
    ----------
    Gram : array, shape (n_features, n_features)
        Gram matrix of the input data matrix

    Xy : array, shape (n_features,)
        Input targets

    n_nonzero_coefs : int
        Targeted number of non-zero elements

    tol_0 : float
        Squared norm of y, required if tol is not None.

    tol : float
        Targeted squared error, if not None overrides n_nonzero_coefs.

    copy_Gram : bool, optional
        Whether the gram matrix must be copied by the algorithm. A false
        value is only helpful if it is already Fortran-ordered, otherwise a
        copy is made anyway.

    copy_Xy : bool, optional
        Whether the covariance vector Xy must be copied by the algorithm.
        If False, it may be overwritten.

    return_path : bool, optional. Default: False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

    Returns
    -------
    gamma : array, shape (n_nonzero_coefs,)
        Non-zero elements of the solution

    idx : array, shape (n_nonzero_coefs,)
        Indices of the positions of the elements in gamma within the solution
        vector

    coefs : array, shape (n_features, n_nonzero_coefs)
        The first k values of column k correspond to the coefficient value
        for the active features at that step. The lower left triangle contains
        garbage. Only returned if ``return_path=True``.

    n_active : int
        Number of active features at convergence.
    R   R   R   R   i    R   g      ð?i   R   i   NR   R   i   R   R   (   R   R   (   R   (   i    i    (   i    i    (   R   R   R   t   flagst	   writeableR   R   R   R   R   R   R   t   lenR   R!   R"   R#   R$   R%   R&   R'   R(   R)   R*   R+   R    R   R   t   inner(   t   Gramt   XyR/   t   tol_0R0   t	   copy_Gramt   copy_XyR2   R3   R   R   R   R8   R4   t   tol_currt   deltaR6   R7   R9   R:   R;   R<   R=   R>   R?   t   beta(    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt	   _gram_omp‹   st    5$
	 & %1
,(


*c         C   sŒ  t  |  d d d | ƒ}  t } | j d k rB | j d d ƒ } n  t  | ƒ } | j d d k rj t } n  | d k r¥ | d k r¥ t t d |  j d ƒ d ƒ } n  | d k	 rÌ | d k  rÌ t	 d ƒ ‚ n  | d k ró | d k ró t	 d	 ƒ ‚ n  | d k r!| |  j d k r!t	 d
 ƒ ‚ n  | d k rJ|  j d |  j d k } n  | rßt
 j |  j |  ƒ } t
 j | ƒ } t
 j |  j | ƒ }	 | d k	 r±t
 j | d d d ƒ}
 n d }
 t | |	 | | |
 d | d t d | ƒS| rt
 j |  j d | j d |  j d f ƒ } n# t
 j |  j d | j d f ƒ } g  } xt | j d ƒ D]ì } t |  | d d … | f | | d | d | ƒ} | r| \ } } } } | d d … d d … d t | ƒ … f } xb t | j ƒ D]/ \ } } | | d  | | | d  | | f <qÜWn | \ } } } | | | | f <| j | ƒ qRW| j d d k rb| d } n  | r{t
 j | ƒ | f St
 j | ƒ Sd S(   sI  Orthogonal Matching Pursuit (OMP)

    Solves n_targets Orthogonal Matching Pursuit problems.
    An instance of the problem has the form:

    When parametrized by the number of non-zero coefficients using
    `n_nonzero_coefs`:
    argmin ||y - X\gamma||^2 subject to ||\gamma||_0 <= n_{nonzero coefs}

    When parametrized by error using the parameter `tol`:
    argmin ||\gamma||_0 subject to ||y - X\gamma||^2 <= tol

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

    Parameters
    ----------
    X : array, shape (n_samples, n_features)
        Input data. Columns are assumed to have unit norm.

    y : array, shape (n_samples,) or (n_samples, n_targets)
        Input targets

    n_nonzero_coefs : int
        Desired number of non-zero entries in the solution. If None (by
        default) this value is set to 10% of n_features.

    tol : float
        Maximum norm of the residual. If not None, overrides n_nonzero_coefs.

    precompute : {True, False, 'auto'},
        Whether to perform precomputations. Improves performance when n_targets
        or n_samples is very large.

    copy_X : bool, optional
        Whether the design matrix X must be copied by the algorithm. A false
        value is only helpful if X is already Fortran-ordered, otherwise a
        copy is made anyway.

    return_path : bool, optional. Default: False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

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

    Returns
    -------
    coef : array, shape (n_features,) or (n_features, n_targets)
        Coefficients of the OMP solution. If `return_path=True`, this contains
        the whole coefficient path. In this case its shape is
        (n_features, n_features) or (n_features, n_targets, n_features) and
        iterating over the last axis yields coefficients in increasing order
        of active features.

    n_iters : array-like or int
        Number of active features across every target. Returned only if
        `return_n_iter` is set to True.

    See also
    --------
    OrthogonalMatchingPursuit
    orthogonal_mp_gram
    lars_path
    decomposition.sparse_encode

    Notes
    -----
    Orthogonal matching pursuit was introduced in S. Mallat, Z. Zhang,
    Matching pursuits with time-frequency dictionaries, IEEE Transactions on
    Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.
    (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)

    This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,
    M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal
    Matching Pursuit Technical Report - CS Technion, April 2008.
    http://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf

    t   orderR   R   i   iÿÿÿÿgš™™™™™¹?i    s   Epsilon cannot be negatives$   The number of atoms must be positives>   The number of atoms cannot be more than the number of featurest   autoi   t   axisRH   RI   R2   NR1   (   R   R+   t   ndimt   reshapeR    R#   R!   t   maxt   intt
   ValueErrorR   R   R   R   t   sumt   orthogonal_mp_gramt   zerost   rangeR@   RC   t	   enumeratet   appendt   squeeze(   R-   R.   R/   R0   t
   precomputeR1   R2   t   return_n_itert   GRF   t   norms_squaredt   coeft   n_iterst   kt   outR?   t   idxR;   t   n_iterR7   t   x(    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   orthogonal_mp	  s`    Q	#0#+*c	         C   sS  t  |  d d d | ƒ}  t j | ƒ } | j d k rR | j d d k rR t } n  | j d k r• | d d … t j f } | d k	 r• | g } q• n  | s¨ | j j	 r· | j
 ƒ  } n  | d k rè | d k rè t d t |  ƒ ƒ } n  | d k	 r| d k rt d ƒ ‚ n  | d k	 r6| d k  r6t d	 ƒ ‚ n  | d k r]| d k r]t d
 ƒ ‚ n  | d k rŠ| t |  ƒ k rŠt d ƒ ‚ n  | r¾t j t |  ƒ | j d t |  ƒ f ƒ }	 n" t j t |  ƒ | j d f ƒ }	 g  }
 x t | j d ƒ D]} t |  | d d … | f | | d k	 r2| | n d | d | d t d | ƒ} | rÙ| \ } } } } |	 d d … d d … d t | ƒ … f }	 xb t | j ƒ D]/ \ } } | | d  |	 | | d  | | f <q£Wn | \ } } } | |	 | | f <|
 j | ƒ qúW| j d d k r)|
 d }
 n  | rBt j |	 ƒ |
 f St j |	 ƒ Sd S(   sÄ
  Gram Orthogonal Matching Pursuit (OMP)

    Solves n_targets Orthogonal Matching Pursuit problems using only
    the Gram matrix X.T * X and the product X.T * y.

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

    Parameters
    ----------
    Gram : array, shape (n_features, n_features)
        Gram matrix of the input data: X.T * X

    Xy : array, shape (n_features,) or (n_features, n_targets)
        Input targets multiplied by X: X.T * y

    n_nonzero_coefs : int
        Desired number of non-zero entries in the solution. If None (by
        default) this value is set to 10% of n_features.

    tol : float
        Maximum norm of the residual. If not None, overrides n_nonzero_coefs.

    norms_squared : array-like, shape (n_targets,)
        Squared L2 norms of the lines of y. Required if tol is not None.

    copy_Gram : bool, optional
        Whether the gram matrix must be copied by the algorithm. A false
        value is only helpful if it is already Fortran-ordered, otherwise a
        copy is made anyway.

    copy_Xy : bool, optional
        Whether the covariance vector Xy must be copied by the algorithm.
        If False, it may be overwritten.

    return_path : bool, optional. Default: False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

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

    Returns
    -------
    coef : array, shape (n_features,) or (n_features, n_targets)
        Coefficients of the OMP solution. If `return_path=True`, this contains
        the whole coefficient path. In this case its shape is
        (n_features, n_features) or (n_features, n_targets, n_features) and
        iterating over the last axis yields coefficients in increasing order
        of active features.

    n_iters : array-like or int
        Number of active features across every target. Returned only if
        `return_n_iter` is set to True.

    See also
    --------
    OrthogonalMatchingPursuit
    orthogonal_mp
    lars_path
    decomposition.sparse_encode

    Notes
    -----
    Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,
    Matching pursuits with time-frequency dictionaries, IEEE Transactions on
    Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.
    (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)

    This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,
    M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal
    Matching Pursuit Technical Report - CS Technion, April 2008.
    http://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf

    RN   R   R   i   Ngš™™™™™¹?sS   Gram OMP needs the precomputed norms in order to evaluate the error sum of squares.i    s   Epsilon cannot be negatives$   The number of atoms must be positives>   The number of atoms cannot be more than the number of featuresRH   RI   R2   (   R   R   t   asarrayRQ   R    R#   t   newaxisR!   RA   RB   R   RT   RC   RU   RX   RY   RM   R+   RZ   R   R[   R\   (   RE   RF   R/   R0   R`   RH   RI   R2   R^   Ra   Rb   Rc   Rd   R?   Re   R;   Rf   R7   Rg   (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyRW   —  sV    N"	."	+*t   OrthogonalMatchingPursuitc           B   s/   e  Z d  Z d d e e d d „ Z d „  Z RS(   s  Orthogonal Matching Pursuit model (OMP)

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

    Parameters
    ----------
    n_nonzero_coefs : int, optional
        Desired number of non-zero entries in the solution. If None (by
        default) this value is set to 10% of n_features.

    tol : float, optional
        Maximum norm of the residual. If not None, overrides n_nonzero_coefs.

    fit_intercept : boolean, optional
        whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (e.g. data is expected to be already centered).

    normalize : boolean, optional, default True
        This parameter is ignored when ``fit_intercept`` is set to False.
        If True, the regressors X will be normalized before regression by
        subtracting the mean and dividing by the l2-norm.
        If you wish to standardize, please use
        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``
        on an estimator with ``normalize=False``.

    precompute : {True, False, 'auto'}, default 'auto'
        Whether to use a precomputed Gram and Xy matrix to speed up
        calculations. Improves performance when `n_targets` or `n_samples` is
        very large. Note that if you already have such matrices, you can pass
        them directly to the fit method.

    Attributes
    ----------
    coef_ : array, shape (n_features,) or (n_targets, n_features)
        parameter vector (w in the formula)

    intercept_ : float or array, shape (n_targets,)
        independent term in decision function.

    n_iter_ : int or array-like
        Number of active features across every target.

    Examples
    --------
    >>> from sklearn.linear_model import OrthogonalMatchingPursuit
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(noise=4, random_state=0)
    >>> reg = OrthogonalMatchingPursuit().fit(X, y)
    >>> reg.score(X, y) # doctest: +ELLIPSIS
    0.9991...
    >>> reg.predict(X[:1,])
    array([-78.3854...])

    Notes
    -----
    Orthogonal matching pursuit was introduced in G. Mallat, Z. Zhang,
    Matching pursuits with time-frequency dictionaries, IEEE Transactions on
    Signal Processing, Vol. 41, No. 12. (December 1993), pp. 3397-3415.
    (http://blanche.polytechnique.fr/~mallat/papiers/MallatPursuit93.pdf)

    This implementation is based on Rubinstein, R., Zibulevsky, M. and Elad,
    M., Efficient Implementation of the K-SVD Algorithm using Batch Orthogonal
    Matching Pursuit Technical Report - CS Technion, April 2008.
    http://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf

    See also
    --------
    orthogonal_mp
    orthogonal_mp_gram
    lars_path
    Lars
    LassoLars
    decomposition.sparse_encode
    OrthogonalMatchingPursuitCV
    RO   c         C   s1   | |  _  | |  _ | |  _ | |  _ | |  _ d  S(   N(   R/   R0   t   fit_interceptt	   normalizeR]   (   t   selfR/   R0   Rl   Rm   R]   (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   __init__k  s
    				c         C   s¼  t  | | d t d t ƒ\ } } | j d } t | | d |  j |  j |  j d t ƒ\ } } } } } } } | j d k r˜ | d d … t	 j
 f } n  |  j d k rÕ |  j d k rÕ t t d | ƒ d ƒ |  _ n |  j |  _ | t k r&t | | |  j |  j d t d t d	 t ƒ\ }	 |  _ ns |  j d k	 rNt	 j | d
 d d ƒn d }
 t | d | d |  j d |  j d |
 d t d t d	 t ƒ\ }	 |  _ |	 j |  _ |  j | | | ƒ |  S(   s”  Fit the model using X, y as training data.

        Parameters
        ----------
        X : array-like, shape (n_samples, n_features)
            Training data.

        y : array-like, shape (n_samples,) or (n_samples, n_targets)
            Target values. Will be cast to X's dtype if necessary


        Returns
        -------
        self : object
            returns an instance of self.
        t   multi_outputt	   y_numerici   R   Ngš™™™™™¹?R]   R1   R^   i   RP   i    RF   R/   R0   R`   RH   RI   (   R   R#   R    R   R!   R]   Rm   Rl   RQ   R   Rj   R/   R0   RS   RT   t   n_nonzero_coefs_R+   Rh   t   n_iter_RV   RW   R   t   coef_t   _set_intercept(   Rn   R-   R.   t
   n_featurest   X_offsett   y_offsett   X_scaleRE   RF   Rt   t   norms_sq(    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   fits  s.    !'.N(   t   __name__t
   __module__t   __doc__R!   R#   Ro   R{   (    (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyRk     s   L	id   c         C   s®  | r9 |  j  ƒ  }  | j  ƒ  } | j  ƒ  } | j  ƒ  } n  | r² |  j d d ƒ } |  | 8}  | | 8} | j d d ƒ }	 t | d t ƒ} | |	 8} t | d t ƒ} | |	 8} n  | rt j t j |  d d d ƒƒ }
 t j |
 ƒ } |  d d … | f c |
 | :<n  t |  | d | d d d t d	 t d
 t
 ƒ} | j d k rd| d d … t j f } n  | r”| | c |
 | d d … t j f :<n  t j | j | j ƒ | S(   sì  Compute the residues on left-out data for a full LARS path

    Parameters
    -----------
    X_train : array, shape (n_samples, n_features)
        The data to fit the LARS on

    y_train : array, shape (n_samples)
        The target variable to fit LARS on

    X_test : array, shape (n_samples, n_features)
        The data to compute the residues on

    y_test : array, shape (n_samples)
        The target variable to compute the residues on

    copy : boolean, optional
        Whether X_train, X_test, y_train and y_test should be copied.  If
        False, they may be overwritten.

    fit_intercept : boolean
        whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (e.g. data is expected to be already centered).

    normalize : boolean, optional, default True
        This parameter is ignored when ``fit_intercept`` is set to False.
        If True, the regressors X will be normalized before regression by
        subtracting the mean and dividing by the l2-norm.
        If you wish to standardize, please use
        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``
        on an estimator with ``normalize=False``.

    max_iter : integer, optional
        Maximum numbers of iterations to perform, therefore maximum features
        to include. 100 by default.

    Returns
    -------
    residues : array, shape (n_samples, max_features)
        Residues of the prediction on the test data
    RP   i    R   i   NR/   R0   R]   R1   R2   i   (   R   t   meanR   R+   R   R    RV   t   flatnonzeroRh   R!   R#   RQ   Rj   R   R   (   t   X_traint   y_traint   X_testt   y_testR   Rl   Rm   t   max_itert   X_meant   y_meant   normst   nonzerosR;   (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   _omp_path_residues§  s4    -


"#	*t   OrthogonalMatchingPursuitCVc           B   s5   e  Z d  Z e e e d d d e d „ Z d „  Z RS(   sð  Cross-validated Orthogonal Matching Pursuit model (OMP).

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

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

    Parameters
    ----------
    copy : bool, optional
        Whether the design matrix X must be copied by the algorithm. A false
        value is only helpful if X is already Fortran-ordered, otherwise a
        copy is made anyway.

    fit_intercept : boolean, optional
        whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (e.g. data is expected to be already centered).

    normalize : boolean, optional, default True
        This parameter is ignored when ``fit_intercept`` is set to False.
        If True, the regressors X will be normalized before regression by
        subtracting the mean and dividing by the l2-norm.
        If you wish to standardize, please use
        :class:`sklearn.preprocessing.StandardScaler` before calling ``fit``
        on an estimator with ``normalize=False``.

    max_iter : integer, optional
        Maximum numbers of iterations to perform, therefore maximum features
        to include. 10% of ``n_features`` but at least 5 if available.

    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.

    n_jobs : int or None, optional (default=None)
        Number of CPUs to use during the cross validation.
        ``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 or integer, optional
        Sets the verbosity amount

    Attributes
    ----------
    intercept_ : float or array, shape (n_targets,)
        Independent term in decision function.

    coef_ : array, shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the problem formulation).

    n_nonzero_coefs_ : int
        Estimated number of non-zero coefficients giving the best mean squared
        error over the cross-validation folds.

    n_iter_ : int or array-like
        Number of active features across every target for the model refit with
        the best hyperparameters got by cross-validating across all folds.

    Examples
    --------
    >>> from sklearn.linear_model import OrthogonalMatchingPursuitCV
    >>> from sklearn.datasets import make_regression
    >>> X, y = make_regression(n_features=100, n_informative=10,
    ...                        noise=4, random_state=0)
    >>> reg = OrthogonalMatchingPursuitCV(cv=5).fit(X, y)
    >>> reg.score(X, y) # doctest: +ELLIPSIS
    0.9991...
    >>> reg.n_nonzero_coefs_
    10
    >>> reg.predict(X[:1,])
    array([-78.3854...])

    See also
    --------
    orthogonal_mp
    orthogonal_mp_gram
    lars_path
    Lars
    LassoLars
    OrthogonalMatchingPursuit
    LarsCV
    LassoLarsCV
    decomposition.sparse_encode

    R'   c         C   sC   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   Rl   Rm   R…   t   cvt   n_jobst   verbose(   Rn   R   Rl   Rm   R…   RŒ   R   RŽ   (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyRo   Y  s    						c   
   	      s¦  t  ˆ  ˆ d t d d d ˆ ƒ\ ‰  ‰ t ˆ  d t d t ƒ‰  t ˆ j d t ƒ} ˆ j s t t t	 d ˆ  j
 d	 ƒ d
 ƒ ˆ  j
 d	 ƒ n ˆ j ‰ t d ˆ j d ˆ j ƒ ‡  ‡ ‡ ‡ f d †  | j ˆ  ƒ Dƒ ƒ } t d „  | Dƒ ƒ } t j g  | D]  } | |  d j d d	 ƒ ^ qü ƒ } t j | j d d ƒ ƒ d	 } | ˆ _ t d | d ˆ j d ˆ j ƒ }	 |	 j ˆ  ˆ ƒ |	 j ˆ _ |	 j ˆ _ |	 j ˆ _ ˆ S(   sx  Fit the model using X, y as training data.

        Parameters
        ----------
        X : array-like, shape [n_samples, n_features]
            Training data.

        y : array-like, shape [n_samples]
            Target values. Will be cast to X's dtype if necessary

        Returns
        -------
        self : object
            returns an instance of self.
        Rq   t   ensure_min_featuresi   t	   estimatorR   t   force_all_finitet
   classifiergš™™™™™¹?i   i   R   RŽ   c      
   3   sU   |  ]K \ } } t  t ƒ ˆ  | ˆ | ˆ  | ˆ | ˆ j ˆ j ˆ j ˆ ƒ Vq d  S(   N(   R   RŠ   R   Rl   Rm   (   t   .0t   traint   test(   R-   R…   Rn   R.   (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pys	   <genexpr>{  s   c         s   s   |  ] } | j  d  Vq d S(   i    N(   R    (   R“   t   fold(    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pys	   <genexpr>€  s    RP   i    R/   Rl   Rm   (   R   R#   R   R+   R	   RŒ   R…   t   minRS   RT   R    R
   R   RŽ   t   splitR   t   arrayR   t   argminRr   Rk   Rl   Rm   R{   Rt   t
   intercept_Rs   (
   Rn   R-   R.   RŒ   t   cv_pathst   min_early_stopR–   t	   mse_foldst   best_n_nonzero_coefst   omp(    (   R-   R…   Rn   R.   s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyR{   c  s,    9		-		N(   R|   R}   R~   R#   R!   R+   Ro   R{   (    (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyR‹   ô  s   d		("   R~   R&   t   mathR    t   numpyR   t   scipyR   t   scipy.linalg.lapackR   t   baseR   R   R   t   utilsR   R   R   t   model_selectionR	   t   utils._joblibR
   R   R(   R!   R#   R+   R@   RM   Rh   RW   Rk   RŠ   R‹   (    (    (    s7   lib/python2.7/site-packages/sklearn/linear_model/omp.pyt   <module>   s4   p}	Œ„‰L