
     h                     L   d Z ddlZddlm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mZ d	dlmZmZ d	dlmZmZ d	dlmZmZmZ d	dlmZ dZ ddZ!	 	 	 	 	 ddZ"ddddddddZ#dddddddddZ$ G d deee          Z%	 	 	 	 d dZ& G d dee          Z'dS )!z'Orthogonal matching pursuit algorithms
    N)sqrt)IntegralReal)linalg)get_lapack_funcs   )LinearModel_pre_fit_deprecate_normalize   )RegressorMixinMultiOutputMixin)as_float_arraycheck_array)delayedParallel)HiddenInterval
StrOptions)check_cvzOrthogonal matching pursuit ended prematurely due to linear dependence in the dictionary. The requested precision might not have been met.TFc                 $   |r|                      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                   }|| j        d         n|}t          j        ||f| j                  }|rt          j        |          }	 t          j        t          j        t          j	        | j
        |                              }||k     s|
|         d	z  |k     r#t#          j        t&          t(          d	
           n|dk    rt          j	        | ddd|f         j
        | dd|f                   ||d|f<   t          j        |d|d|f         ||d|f         dddd            |||d|f                   d	z  }t          j        | dd|f                   d	z  |z
  }||k    r#t#          j        t&          t(          d	
           nt/          |          |||f<   n!t          j        | dd|f                   |d<    || j
        |         | j
        |                   \  | j
        |<   | j
        |<   |
|         |
|         c|
|<   |
|<   ||         ||         c||<   ||<   |dz  } |	|d|d|f         |
d|         dd          \  }}|r||d||dz
  f<   |t          j	        | ddd|f         |          z
  }| ||          d	z  |k    rn	||k    rn\|r||d|         |ddd|f         |fS ||d|         |fS )a  Orthogonal Matching Pursuit step using the Cholesky decomposition.

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

    y : ndarray of shape (n_samples,)
        Input targets.

    n_nonzero_coefs : int
        Targeted number of non-zero elements.

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

    copy_X : bool, default=True
        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, default=False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

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

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

    coef : ndarray of 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.
    Fnrm2swappotrsr   r   NdtypeTr   
stacklevelFtransloweroverwrite_bcheck_finiter   r   r$   r%   )copynpasfortranarrayfinfor   epsr   get_blas_funcsr   dotTemptyarangeshape
empty_likeargmaxabswarningswarn	prematureRuntimeWarningsolve_triangularnormr   )Xyn_nonzero_coefstolcopy_Xreturn_path	min_floatr   r   r   alpharesidualgamman_activeindicesmax_featuresLcoefslamvLkk_s                         U/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/sklearn/linear_model/_omp.py_cholesky_omprQ      s   V  !FF3KKa  !!%I&'7!>>JD$
QD11HUF13NNEHHQKKEHi
##G!$171::oL
,-QW===A !a  +irvac8445566>>U3Z1_y88M)^BBBBa<<%'VAaaa(lO,=qCy%I%IAh		!"#)8)YhY&'(IXI%& "    Qx(*+,,1A+a3i((A-1CiiAFFFF$(IIAh !!k!AAAsF),,AdG"&$qs8}ac#h"?"?Hqs3x&+Cj%/#hs*1#,8I'73<A 5ixi("#U9H9%5Tu
 
 
q  	3-2E)8)X\)*rva9H9ou555?ttH~~2c99%%W+Z  3gixi(%9H9*=xGGgixi((22    c                 0   |r|                      d          nt          j        |           } |s|j        j        s|                                 }t          j        | j                  j        }t          j	        d| f          \  }	}
t          d| f          \  }t          j        t          |                     }|}|}d}t          j        d          }d}|t          |           n|}t          j        ||f| j                  }d|d<   |rt          j        |          }	 t          j        t          j        |                    }||k     s||         d
z  |k     r#t#          j        t&          t(          d           n|dk    r| |d|f         ||d|f<   t          j        |d|d|f         ||d|f         ddd	d            |	||d|f                   d
z  }| ||f         |z
  }||k    r#t#          j        t&          t(          d           nYt-          |          |||f<   nt-          | ||f                   |d<    |
| |         | |                   \  | |<   | |<    |
| j        |         | j        |                   \  | j        |<   | j        |<   ||         ||         c||<   ||<   ||         ||         c||<   ||<   |dz  } ||d|d|f         |d|         d	d          \  }}|r||d||dz
  f<   t          j        | ddd|f         |          }||z
  }|<||z  }t          j        ||d|                   }||z  }t!          |          |k    rn
n||k    rnN|r||d|         |ddd|f         |fS ||d|         |fS )a  Orthogonal Matching Pursuit step on a precomputed Gram matrix.

    This function uses the Cholesky decomposition method.

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

    Xy : ndarray of shape (n_features,)
        Input targets.

    n_nonzero_coefs : int
        Targeted number of non-zero elements.

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

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

    copy_Gram : bool, default=True
        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, default=True
        Whether the covariance vector Xy must be copied by the algorithm.
        If False, it may be overwritten.

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

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

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

    coefs : ndarray of 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   Nr   g      ?r'   Tr      r    r   Fr"   r(   )r)   r*   r+   flags	writeabler,   r   r-   r   r.   r   r2   lenr1   r4   r5   r6   r7   r8   r9   r:   r;   r   r0   r/   inner)GramXyr?   tol_0r@   	copy_Gramcopy_XyrB   rC   r   r   r   rH   rD   tol_currdeltarF   rG   rI   rJ   rK   rL   rM   rN   rO   betas                             rP   	_gram_ompra      s*   z 'C499S>>>B,=d,C,CD bh( WWYY$$(I&'7$AAJD$
TG44HUiD		""GEHEHQKKEH #3t999_L
,-TZ@@@AAdG !a  -iu&&>>U3Z1_y88M)^BBBBa<<%)#yy.%9Ah		!"#)8)YhY&'(IXI%& "    Qx(*+,,1AsCx.1$CiiAFFFF$(IIAh !!4S>**AdG$(Dhc$C$C!XS	(,TVH-=tvc{(K(K%x$&+*1#,8I'73< "3H8bgA5ixi("#R		]$E
 
 
q  	3-2E)8)X\)*vd111ixi<(%00T	?HHUD(O44EH8}}## $%%[-^  3gixi(%9H9*=xGGgixi((22rR   )r?   r@   
precomputerA   rB   return_n_iterc          
         t          | d|          } d}|j        dk    r|                    dd          }t          |          }|j        d         dk    rd}|-|+t	          t          d| j        d         z            d          }||d	k     rt          d
          ||d	k    rt          d          | || j        d         k    rt          d          |dk    r| j        d	         | j        d         k    }|r}t          j        | j	        |           }t          j
        |          }t          j        | j	        |          }	|t          j        |dz  d	          }
nd}
t          ||	|||
|d|          S |r9t          j        | j        d         |j        d         | j        d         f          }n,t          j        | j        d         |j        d         f          }g }t          |j        d                   D ]}t          | |dd|f         ||||          }|r^|\  }}}}|dddddt!          |          f         }t#          |j	                  D ]#\  }}|d|dz            ||d|dz            ||f<   $n|\  }}}||||f<   |                    |           |j        d         dk    r|d	         }|rt          j        |          |fS t          j        |          S )a&  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 : ndarray of shape (n_samples, n_features)
        Input data. Columns are assumed to have unit norm.

    y : ndarray of shape (n_samples,) or (n_samples, n_targets)
        Input targets.

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

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

    precompute : 'auto' or bool, default=False
        Whether to perform precomputations. Improves performance when n_targets
        or n_samples is very large.

    copy_X : bool, default=True
        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, default=False
        Whether to return every value of the nonzero coefficients along the
        forward path. Useful for cross-validation.

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

    Returns
    -------
    coef : ndarray of 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 generates 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 Matching Pursuit model.
    orthogonal_mp_gram : Solve OMP problems using Gram matrix and the product X.T * y.
    lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.
    sklearn.decomposition.sparse_encode : Sparse coding.

    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.
    (https://www.di.ens.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.
    https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf
    r   orderr)   Fr   TN皙?r   Epsilon cannot be negative$The number of atoms must be positive>The number of atoms cannot be more than the number of featuresautor   axis)r?   r@   norms_squaredr\   r]   rB   )rA   rB   )r   ndimreshaper3   maxint
ValueErrorr*   r/   r0   r+   sumorthogonal_mp_gramzerosrangerQ   rW   	enumerateappendsqueeze)r=   r>   r?   r@   rb   rA   rB   rc   GrZ   ro   coefn_iterskoutrO   idxrK   n_iterrG   xs                        rP   orthogonal_mpr     sB   p 	ASv...AFv{{IIb!AAwqzA~~3; c#
"233Q77
3775666
{!++?@@@
{33L
 
 	
 VWQZ!'!*,
 
F13NNa  VAC^^?FAqD222MM M!+'#	
 	
 	
 		
  2xQWQZ<==xQWQZ011G171:  qAwV
 
 
  	$'!AsE6111jCj()D(11 K K!9:>X\>9JS8a<(!X566K !NAsFDaLvwqzQ!*  z$((z$rR   )r?   r@   ro   r\   r]   rB   rc   c                B   t          | d|          } t          j        |          }|j        dk    r|j        d         dk    rd}|j        dk    r|ddt          j        f         }||g}|s|j        j        s|                                }|!|t          dt          |           z            }||t          d          ||dk     rt          d	          ||dk    rt          d
          |"|t          |           k    rt          d          |rDt          j        t          |           |j        d         t          |           f| j                  }	n5t          j        t          |           |j        d         f| j                  }	g }
t          |j        d                   D ]}t          | |dd|f         ||||         nd||d|          }|r^|\  }}}}|	dddddt          |          f         }	t!          |j                  D ]#\  }}|d|dz            |	|d|dz            ||f<   $n|\  }}}||	||f<   |
                    |           |j        d         dk    r|
d         }
|rt          j        |	          |
fS t          j        |	          S )a  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 : ndarray of shape (n_features, n_features)
        Gram matrix of the input data: X.T * X.

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

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

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

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

    copy_Gram : bool, default=True
        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, default=True
        Whether the covariance vector Xy must be copied by the algorithm.
        If False, it may be overwritten.

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

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

    Returns
    -------
    coef : ndarray of 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 Matching Pursuit model (OMP).
    orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.
    lars_path : Compute Least Angle Regression or Lasso path using
        LARS algorithm.
    sklearn.decomposition.sparse_encode : Generic sparse coding.
        Each column of the result is the solution to a Lasso problem.

    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.
    (https://www.di.ens.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.
    https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf
    r   re   r   TNrh   zSGram OMP needs the precomputed norms in order to evaluate the error sum of squares.r   ri   rj   rk   r   F)r\   r]   rB   )r   r*   asarrayrp   r3   newaxisrU   rV   r)   rs   rW   rt   rw   r   rx   ra   ry   r0   rz   r{   )rY   rZ   r?   r@   ro   r\   r]   rB   rc   r}   r~   r   r   rO   r   rK   r   rG   r   s                      rP   rv   rv     s   n t3Y777D	BB	w{{rx{Q		w!||2:?*OM bh( WWYY3;cCIIo..
=04
 
 	
 3775666
{!++?@@@
{T22L
 
 	
  DxTBHQKT;4:NNNxTBHQK0
CCCG28A;  qqq!tH #M!T#	
 	
 	
  	$'!AsE6111jCj()D(11 K K!9:>X\>9JS8a<(!X566K !NAsFDaLv	x{a!*  z$((z$rR   c            	           e Zd ZU dZ eeddd          dg eeddd          dgdgd e edh                    g ed	h          dgd
Z	e
ed<   ddddd	d
dZd ZdS )OrthogonalMatchingPursuita  Orthogonal Matching Pursuit model (OMP).

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

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

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

    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    normalize : bool, default=False
        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``.

        .. versionchanged:: 1.2
           default changed from True to False in 1.2.

        .. deprecated:: 1.2
            ``normalize`` was deprecated in version 1.2 and will be removed in 1.4.

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

    Attributes
    ----------
    coef_ : ndarray of shape (n_features,) or (n_targets, n_features)
        Parameter vector (w in the formula).

    intercept_ : float or ndarray of shape (n_targets,)
        Independent term in decision function.

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

    n_nonzero_coefs_ : int
        The number of non-zero coefficients in the solution. If
        `n_nonzero_coefs` is None and `tol` is None this value is either set
        to 10% of `n_features` or 1, whichever is greater.

    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
    --------
    orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.
    orthogonal_mp_gram :  Solves n_targets Orthogonal Matching Pursuit
        problems using only the Gram matrix X.T * X and the product X.T * y.
    lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.
    Lars : Least Angle Regression model a.k.a. LAR.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    sklearn.decomposition.sparse_encode : Generic sparse coding.
        Each column of the result is the solution to a Lasso problem.
    OrthogonalMatchingPursuitCV : Cross-validated
        Orthogonal Matching Pursuit model (OMP).

    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.
    (https://www.di.ens.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.
    https://www.cs.technion.ac.il/~ronrubin/Publications/KSVD-OMP-v2.pdf

    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)
    0.9991...
    >>> reg.predict(X[:1,])
    array([-78.3854...])
    r   Nleftclosedr   boolean
deprecatedrl   r?   r@   fit_intercept	normalizerb   _parameter_constraintsTc                L    || _         || _        || _        || _        || _        d S Nr   )selfr?   r@   r   r   rb   s         rP   __init__z"OrthogonalMatchingPursuit.__init__  s-      /*"$rR   c           
         |                                   t          | j        | j        j                  }|                     ||dd          \  }}|j        d         }t          ||d| j        || j	        d          \  }}}}}}}	|j
        dk    r|ddt          j        f         }| j        -| j        &t          t!          d|z            d          | _        n| j        | _        |du r)t%          ||| j        | j        ddd	          \  }
| _        nK| j        t          j        |d
z  d          nd}t+          ||	| j        | j        |ddd          \  }
| _        |
j        | _        |                     |||           | S )a  Fit the model using X, y as training data.

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

        y : array-like of 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.
        estimator_nameT)multi_output	y_numericr   Nr)   rh   F)r?   r@   rb   rA   rc   r   r   rm   )rZ   r?   r@   ro   r\   r]   rc   )_validate_paramsr   r   	__class____name___validate_datar3   r
   rb   r   rp   r*   r   r?   r@   rr   rs   n_nonzero_coefs_r   n_iter_ru   rv   r0   coef__set_intercept)r   r=   r>   
_normalize
n_featuresX_offsety_offsetX_scalerY   rZ   r   norms_sqs               rP   fitzOrthogonalMatchingPursuit.fit  s     	)N4>+B
 
 

 ""1add"KK1WQZ
6>q$T5Gd7
 7
 7
31h'4 6Q;;!!!RZ- A'DH,< %(C*,<(=(=q$A$AD!!$($8D!5=="/ $ 5H "# # #E4<< 04x/Crvad++++H"4 $ 5H&"	# 	# 	#E4< W
Hh888rR   )r   
__module____qualname____doc__r   r   r   r   r   r   dict__annotations__r   r    rR   rP   r   r   Q  s         d dN %HXq$vFFFMq$v666=#

L>(B(B!C!CD!z6(++Y7$ $D    % % % % %@ @ @ @ @rR   r   d   c           	      .   |rP|                                  } |                                 }|                                 }|                                 }|rb|                     d          }| |z  } ||z  }|                    d          }	t          |d          }||	z  }t          |d          }||	z  }|rYt          j        t          j        | dz  d                    }
t          j        |
          }| dd|fxx         |
|         z  cc<   t          | ||dddd          }|j        d	k    r|ddt          j	        f         }|r*||xx         |
|         ddt          j	        f         z  cc<   t          j
        |j        |j                  |z
  S )
a  Compute the residues on left-out data for a full LARS path.

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

    y_train : ndarray of shape (n_samples)
        The target variable to fit LARS on.

    X_test : ndarray of shape (n_samples, n_features)
        The data to compute the residues on.

    y_test : ndarray of shape (n_samples)
        The target variable to compute the residues on.

    copy : bool, default=True
        Whether X_train, X_test, y_train and y_test should be copied.  If
        False, they may be overwritten.

    fit_intercept : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    normalize : bool, default=False
        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``.

        .. versionchanged:: 1.2
           default changed from True to False in 1.2.

        .. deprecated:: 1.2
            ``normalize`` was deprecated in version 1.2 and will be removed in 1.4.

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

    Returns
    -------
    residues : ndarray of shape (n_samples, max_features)
        Residues of the prediction on the test data.
    r   rm   Fr   r   NT)r?   r@   rb   rA   rB   r   )r)   meanr   r*   r   ru   flatnonzeror   rp   r   r/   r0   )X_trainy_trainX_testy_testr)   r   r   max_iterX_meany_meannormsnonzerosrK   s                rP   _omp_path_residuesr     s   v  ,,..,,.. 1%%6&1%% u5556U333& 0wz22233>%((8h/   E zQaaam$ :h5?111bj=996%'68$$v--rR   c            	           e Zd ZU dZdgdgd e edh                    g eeddd          dgdgedgd	gd
Ze	e
d<   dddddddd
dZd ZdS )OrthogonalMatchingPursuitCVa  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, default=True
        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 : bool, default=True
        Whether to calculate the intercept for this model. If set
        to false, no intercept will be used in calculations
        (i.e. data is expected to be centered).

    normalize : bool, default=False
        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``.

        .. versionchanged:: 1.2
           default changed from True to False in 1.2.

        .. deprecated:: 1.2
            ``normalize`` was deprecated in version 1.2 and will be removed in 1.4.

    max_iter : int, default=None
        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 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:`KFold` is used.

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

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

    n_jobs : int, 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 : bool or int, default=False
        Sets the verbosity amount.

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

    coef_ : ndarray of 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.

    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
    --------
    orthogonal_mp : Solves n_targets Orthogonal Matching Pursuit problems.
    orthogonal_mp_gram : Solves n_targets Orthogonal Matching Pursuit
        problems using only the Gram matrix X.T * X and the product X.T * y.
    lars_path : Compute Least Angle Regression or Lasso path using LARS algorithm.
    Lars : Least Angle Regression model a.k.a. LAR.
    LassoLars : Lasso model fit with Least Angle Regression a.k.a. Lars.
    OrthogonalMatchingPursuit : Orthogonal Matching Pursuit model (OMP).
    LarsCV : Cross-validated Least Angle Regression model.
    LassoLarsCV : Cross-validated Lasso model fit with Least Angle Regression.
    sklearn.decomposition.sparse_encode : Generic sparse coding.
        Each column of the result is the solution to a Lasso problem.

    Notes
    -----
    In `fit`, once the optimal number of non-zero coefficients is found through
    cross-validation, the model is fit again using the entire training set.

    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)
    0.9991...
    >>> reg.n_nonzero_coefs_
    10
    >>> reg.predict(X[:1,])
    array([-78.3854...])
    r   r   r   Nr   r   	cv_objectverboser)   r   r   r   cvn_jobsr   r   TFc                h    || _         || _        || _        || _        || _        || _        || _        d S r   r   )r   r)   r   r   r   r   r   r   s           rP   r   z$OrthogonalMatchingPursuitCV.__init__  s:     	*" rR   c           	      8   	
                                    t           j         j        j                                       dd          \  t          dd          t           j        d          } j	        sDt          t          t          dj        d	         z            d
          j        d	                   n j	        	 t           j         j                  	 fd|                              D                       }t          d |D                       
t%          j        
fd|D                       }t%          j        |                    d                    d	z   }| _        t/          | j                  }t3          j                    5  t3          j        dt8                     |                               ddd           n# 1 swxY w Y   |j         _        |j         _        |j          _          S )a~  Fit the model using X, y as training data.

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

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

        Returns
        -------
        self : object
            Returns an instance of self.
        r   Tr   )r   ensure_min_featuresF)r)   force_all_finite)
classifierrh   r      )r   r   c              3      K   | ]M\  }} t          t                    |         |         |         |         j        j                  V  Nd S r   )r   r   r)   r   ).0traintestr=   r   r   r   r>   s      rP   	<genexpr>z2OrthogonalMatchingPursuitCV.fit.<locals>.<genexpr>*  s       F
 F
 t (G&''%%$$	"	 	F
 F
 F
 F
 F
 F
rR   c              3   0   K   | ]}|j         d          V  dS )r   N)r3   )r   folds     rP   r   z2OrthogonalMatchingPursuitCV.fit.<locals>.<genexpr>8  s(      @@tTZ]@@@@@@rR   c                 R    g | ]#}|d          dz                       d          $S )Nr   r   rm   )r   )r   r   min_early_stops     rP   
<listcomp>z3OrthogonalMatchingPursuitCV.fit.<locals>.<listcomp>:  s8    LLL4d?N?#q(..A.66LLLrR   r   rm   )r?   r   r   ignore)categoryN)!r   r   r   r   r   r   r   r   r   r   minrr   rs   r3   r   r   r   splitr*   arrayargminr   r   r   r   r7   catch_warningsfilterwarningsFutureWarningr   r   
intercept_r   )r   r=   r>   r   cv_paths	mse_foldsbest_n_nonzero_coefsompr   r   r   s   ```     @@@rP   r   zOrthogonalMatchingPursuitCV.fit  s     	)N4>+B
 
 

 ""1a4Q"OO1155AAAdg%000 =CCagaj())1--qwqz::: 	
 F84;EEE F
 F
 F
 F
 F
 F
 F
 F
  "xx{{F
 F
 F
 
 
 @@x@@@@@HLLLL8LLL
 
	  "yQ)?)?@@1D 4'0, 
 
 
 $&& 	 	#H}EEEEGGAqMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 Y
.{s   -2G++G/2G/)r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   rP   r   r   s  s         y yx #

L>(B(B!C!CDXh4???FmT";$ $D        &@ @ @ @ @rR   r   )NTF)NNTTF)TTFr   )(r   r7   mathr   numbersr   r   numpyr*   scipyr   scipy.linalg.lapackr   _baser	   r
   r   baser   r   utilsr   r   utils.parallelr   r   utils._param_validationr   r   r   model_selectionr   r9   rQ   ra   r   rv   r   r   r   r   rR   rP   <module>r      s_           " " " " " " " "           0 0 0 0 0 0 > > > > > > > > > > 3 3 3 3 3 3 3 3 / / / / / / / / . . . . . . . . B B B B B B B B B B & & & & & & 
q3 q3 q3 q3p G3 G3 G3 G3\ Z  Z  Z  Z  Z B U  U  U  U  U p~ ~ ~ ~ ~ 0.+ ~ ~ ~L 
^. ^. ^. ^.BY Y Y Y Y.+ Y Y Y Y YrR   