Ë
    êÿæiÖ•  ã                   óf  — 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 dd
lmZmZmZ ddlmZmZmZ ddlmZm Z m!Z!m"Z"m#Z# ddl$m%Z%m&Z& ddl'm(Z(m)Z) dZ*d'd„Z+	 	 	 	 	 d(d„Z, edgejZ                  g eeddd¬«      dg eeddd¬«      dgd edh«      gdgdgdgdœd¬«      dddddddœd„«       Z. edgdg eeddd¬«      dg eeddd¬«      dgddgdgdgdgdgdœ	d¬«      dddddddd œd!„«       Z/ G d"„ d#eee«      Z0	 	 	 d)d$„Z1 G d%„ d&ee«      Z2y)*z&Orthogonal matching pursuit algorithmsé    N)Úsqrt)ÚIntegralÚReal)Úlinalg)Úget_lapack_funcs)ÚMultiOutputMixinÚRegressorMixinÚ_fit_context)ÚLinearModelÚ_pre_fit)Úcheck_cv)ÚBunchÚas_float_arrayÚcheck_array)ÚIntervalÚ
StrOptionsÚvalidate_params)ÚMetadataRouterÚMethodMappingÚ_raise_for_paramsÚ_routing_enabledÚprocess_routing)ÚParallelÚdelayed)ÚFLOAT_DTYPESÚvalidate_datazŠOrthogonal matching pursuit ended prematurely due to linear dependence in the dictionary. The requested precision might not have been met.TFc                 óê  — |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   «      }|�| 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kD  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|…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�Œ4|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   é   N©ÚdtypeTé   ©Ú
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                         ún/Volumes/fast/ai/experiments/voice-extract-mac/.venv/lib/python3.12/site-packages/sklearn/linear_model/_omp.pyÚ_cholesky_omprY   $   s„  € ñV Ø�F‰F�3‹K‰ä×Ñ˜aÓ ˆä—‘˜Ÿ™Ó!×%Ñ%€IÜ×&Ñ&Ð'7¸!¸Ó>�J€Dˆ$Ü 
¨Q¨DÓ1�H€Uä�F‰F�1—3‘3˜‹N€EØ€HÜ�H‰H�Q‹K€EØ€HÜ�i‰i˜Ÿ™ ™
Ó#€Gà!$ �1—7‘7˜1’:°o€Lä
�‰�, Ð-°Q·W±WÔ=€AáÜ—‘˜aÓ ˆà
Ü�i‰iœŸ™œrŸv™v a§c¡c¨8Ó4Ó5Ó6ˆØ�Š>˜U 3™Z¨1™_¨yÒ8ä�M‰Mœ)¤^ÀÕBÙà�aŠ<ä%'§V¡V¨Aªa°°(°¨l©O×,=Ñ,=¸qÂÀCÀ¹yÓ%IˆAˆh˜	˜˜	Ð!Ñ"Ü×#Ñ#Ø�)�8�)˜Y˜h˜YÐ&Ñ'Ø�(˜I˜X˜IÐ%Ñ&ØØØ Ø"õñ �Q�x  ( Ð*Ñ+Ó,°Ñ1ˆAÜ—+‘+˜a¢ 3 ™iÓ(¨AÑ-°Ñ1ˆCØ�iÒÜ—‘œi¬ÀAÕFØÜ$(¨£IˆAˆh˜Ð Ò!ä—k‘k !¢A s F¡)Ó,ˆAˆd‰Gá"& q§s¡s¨8¡}°a·c±c¸#±hÓ"?Ñˆ�‰ˆH‰�q—s‘s˜3‘xØ&+¨C¡j°%¸±/Ð#ˆˆh‰˜˜s™Ø*1°#©,¸ÀÑ8IÐ'ˆ�Ñ˜7 3™<Ø�A‰ˆñ Øˆiˆxˆi˜˜(˜Ð"Ñ# U¨9¨HÐ%5¸TÈuô
‰ˆˆqñ Ø-2ˆE�)�8�)˜X¨™\Ð)Ñ*Ø”r—v‘v˜a¢ 9 H 9 ™o¨uÓ5Ñ5ˆØˆ?™t H›~°Ñ2°cÒ9ØØ˜Ò%ØñW ñZ Ø�g˜i˜xÐ(¨%²°9°H°9°Ñ*=¸xÐGÐGà�g˜i˜xÐ(¨(Ð2Ð2ó    c                 ó¤  — |r| j                  d«      nt        j                  | «      } |s|j                  j                  s|j                  «       }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kD  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¬«       �n,t-        |«      |||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        j0                  | dd…d|…f   |«      }||z
  }|�2||z  }t        j2                  ||d| «      }||z  }t!        |«      |k  rn||k(  r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*   r0   )r1   r2   r3   ÚflagsÚ	writeabler4   r&   r5   r   r6   r   r:   Úlenr9   r<   r=   r>   r?   r@   rA   rB   rC   r   r8   r7   Úinner)ÚGramÚXyrG   Útol_0rH   Ú	copy_GramÚcopy_XyrJ   rK   r    r!   r#   rP   rL   Útol_currÚdeltarN   rO   rQ   rR   rS   rT   rU   rV   rW   Úbetas                             rX   Ú	_gram_ompri   ˜   s£  € ñz 'ˆ4�9‰9�SŒ>¬B×,=Ñ,=¸dÓ,C€Dá�b—h‘h×(Ò(Ø�W‰W‹Yˆä—‘˜Ÿ™Ó$×(Ñ(€IÜ×&Ñ&Ð'7¸$¸ÓA�J€Dˆ$Ü 
¨T¨GÓ4�H€Uä�i‰iœ˜D›	Ó"€GØ€EØ€HØ€EÜ�H‰H�Q‹K€EØ€Hà # ”3�t”9°_€Lä
�‰�, Ð-°T·Z±ZÔ@€Aà€A€d�GÙÜ—‘˜aÓ ˆà
Ü�i‰iœŸ™˜u›Ó&ˆØ�Š>˜U 3™Z¨1™_¨yÒ8ä�M‰Mœ)¤^ÀÕBÙØ�aŠ<Ø%)¨#¨y°¨y¨.Ñ%9ˆAˆh˜	˜˜	Ð!Ñ"Ü×#Ñ#Ø�)�8�)˜Y˜h˜YÐ&Ñ'Ø�(˜I˜X˜IÐ%Ñ&ØØØ Ø"õñ �Q�x  ( Ð*Ñ+Ó,°Ñ1ˆAØ�s˜C�x‘. 1Ñ$ˆCØ�iÒÜ—‘œi¬ÀAÕFÙÜ$(¨£IˆAˆh˜Ð Ò!ä˜4  S ™>Ó*ˆAˆd‰Gá$(¨¨h©¸¸c¹Ó$CÑ!ˆˆX‰˜˜S™	Ù(,¨T¯V©V°HÑ-=¸t¿v¹vÀc¹{Ó(KÑ%ˆ�‰ˆxÑ˜$Ÿ&™& ™+Ø*1°#©,¸ÀÑ8IÐ'ˆ�Ñ˜7 3™<Ø " 3¡¨¨H©Ðˆˆ8‰�b˜‘gØ�A‰ˆáØˆiˆxˆi˜˜(˜Ð"Ñ# R¨	¨ ]¸$ÈEô
‰ˆˆqñ Ø-2ˆE�)�8�)˜X¨™\Ð)Ñ*Ü�v‰v�dš1˜i˜x˜i˜<Ñ(¨%Ó0ˆØ�T‘	ˆØˆ?Ø˜ÑˆHÜ—H‘H˜U D¨¨( OÓ4ˆEØ˜ÑˆHÜ�8‹} Ò#ØØ˜Ò%Øñ[ ñ^ Ø�g˜i˜xÐ(¨%²°9°H°9°Ñ*=¸xÐGÐGà�g˜i˜xÐ(¨(Ð2Ð2rZ   z
array-liker$   Úleft©ÚclosedÚbooleanÚauto)rE   rF   rG   rH   Ú
precomputerI   rJ   Úreturn_n_iter©Úprefer_skip_nested_validation)rG   rH   ro   rI   rJ   rp   c          
      óJ  — t        | d|¬«      } d}|j                  dk(  r|j                  dd«      }t        |«      }|j                  d   dkD  rd}|€'|€%t	        t        d| j                  d   z  «      d«      }|€|| j                  d   kD  rt        d	«      ‚|d
k(  r| j                  d   | j                  d   kD  }|r‡t        j                  | j                  | «      }t        j                  |«      }t        j                  | j                  |«      }	|�t        j                  |dz  d¬«      }
nd}
t        ||	|||
|d|¬«      S |r@t        j                  | j                  d   |j                  d   | j                  d   f«      }n1t        j                  | j                  d   |j                  d   f«      }g }t        |j                  d   «      D ]Š  }t        | |dd…|f   ||||¬«      }|rP|\  }}}}|dd…dd…dt!        |«      …f   }t#        |j                  «      D ]  \  }}|d|dz    ||d|dz    ||f<   Œ n|\  }}}||||f<   |j%                  |«       ŒŒ |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 : array-like 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 squared 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

    Examples
    --------
    >>> from sklearn.datasets import make_regression
    >>> from sklearn.linear_model import orthogonal_mp
    >>> X, y = make_regression(noise=4, random_state=0)
    >>> coef = orthogonal_mp(X, y)
    >>> coef.shape
    (100,)
    >>> X[:1,] @ coef
    array([-78.68])
    r   ©Úorderr1   Fr$   éÿÿÿÿTNçš™™™™™¹?ú>The number of atoms cannot be more than the number of featuresrn   r   r'   ©Úaxis)rG   rH   Únorms_squaredrd   re   rJ   )rI   rJ   )r   ÚndimÚreshaper;   ÚmaxÚintÚ
ValueErrorr2   r7   r8   r3   ÚsumÚorthogonal_mp_gramÚzerosÚrangerY   r_   Ú	enumerateÚappendÚsqueeze)rE   rF   rG   rH   ro   rI   rJ   rp   ÚGrb   r{   ÚcoefÚn_itersÚkÚoutrW   ÚidxrS   Ún_iterrO   Úxs                        rX   Úorthogonal_mpr�   "  sž  € ô` 	�A˜S vÔ.€AØ€FØ‡v�v�‚{Ø�I‰I�b˜!ÓˆÜ�A‹€AØ‡w�wˆq�z�A‚~ØˆØÐ 3 ;ô œc #¨¯©°©
Ñ"2Ó3°QÓ7ˆØ
€{�¨¯©°©Ò3ÜØLó
ð 	
ð �VÒØ—W‘W˜Q‘Z !§'¡'¨!¡*Ñ,ˆ
ÙÜ�F‰F�1—3‘3˜‹NˆÜ×Ñ˜aÓ ˆÜ�V‰V�A—C‘C˜‹^ˆØˆ?ÜŸF™F A q¡D°Ô2‰Mà ˆMÜ!ØØØ+ØØ'ØØØ#ô	
ð 		
ñ Ü�x‰x˜Ÿ™ ™ Q§W¡W¨Q¡Z°·±¸±Ð<Ó=‰ä�x‰x˜Ÿ™ ™ Q§W¡W¨Q¡ZÐ0Ó1ˆØ€Gä�1—7‘7˜1‘:ÖˆÜØˆq’�A�‰w˜¨°VÈô
ˆñ Ø$'Ñ!ˆAˆs�E˜6Øšš1˜j¤ C£˜jÐ(Ñ)ˆDÜ(¨¯©Ö1‘�˜!Ø9:¸>¸XÈ¹\Ð9J��S˜˜8 a™<Ð(¨!¨XÐ5Ò6ñ  2ð !‰NˆAˆs�FØˆD��a�‰LØ�‰�vÕð ð 	‡w�wˆq�z�Q‚Ø˜!‘*ˆáÜ�z‰z˜$Ó Ð(Ð(ä�z‰z˜$ÓÐrZ   Úneither)	ra   rb   rG   rH   r{   rd   re   rJ   rp   )rG   rH   r{   rd   re   rJ   rp   c                óî  — t        | d|¬«      } t        j                  |«      }|j                  dkD  r|j                  d   dkD  rd}|j                  dk(  r|dd…t        j
                  f   }|�|g}|s|j                  j                  s|j                  «       }|€|€t        dt        | «      z  «      }|�|€t        d«      ‚|�|dk  rt        d	«      ‚|€|dk  rt        d
«      ‚|€|t        | «      kD  rt        d«      ‚|rDt        j                  t        | «      |j                  d   t        | «      f| j                  ¬«      }	n9t        j                  t        | «      |j                  d   f| j                  ¬«      }	g }
t        |j                  d   «      D ]“  }t        | |dd…|f   ||�||   nd||d|¬«      }|rP|\  }}}}|	dd…dd…dt        |«      …f   }	t!        |j"                  «      D ]  \  }}|d|dz    |	|d|dz    ||f<   Œ n|\  }}}||	||f<   |
j%                  |«       Œ• |j                  d   dk(  r|
d   }
|rt        j&                  |	«      |
fS t        j&                  |	«      S )ak  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-like of shape (n_features, n_features)
        Gram matrix of the input data: `X.T * X`.

    Xy : array-like 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 squared 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 : list 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

    Examples
    --------
    >>> from sklearn.datasets import make_regression
    >>> from sklearn.linear_model import orthogonal_mp_gram
    >>> X, y = make_regression(noise=4, random_state=0)
    >>> coef = orthogonal_mp_gram(X.T @ X, X.T @ y)
    >>> coef.shape
    (100,)
    >>> X[:1,] @ coef
    array([-78.68])
    r   rt   r$   TNrw   zSGram OMP needs the precomputed norms in order to evaluate the error sum of squares.r   zEpsilon cannot be negativez$The number of atoms must be positiverx   r%   F)rd   re   rJ   )r   r2   Úasarrayr|   r;   Únewaxisr]   r^   r1   r   r_   r€   rƒ   r&   r„   ri   r…   r8   r†   r‡   )ra   rb   rG   rH   r{   rd   re   rJ   rp   r‰   rŠ   r‹   rŒ   rW   r�   rS   rŽ   rO   r�   s                      rX   r‚   r‚   Ó  s�  € ôb �t 3¨YÔ7€DÜ	�‰�B‹€BØ	‡w�w�‚{�r—x‘x ‘{ Q’àˆ	Ø	‡w�w�!‚|Ø’”2—:‘:�ÑˆØˆ?Ø*˜OˆMÙ�b—h‘h×(Ò(à�W‰W‹YˆàÐ 3 ;Ü˜c¤C¨£I™oÓ.ˆØ
€˜=Ð0Üð4ó
ð 	
ð €˜3 š7ÜÐ5Ó6Ð6Ø
€{�¨!Ò+ÜÐ?Ó@Ð@Ø
€{�¬¨T«Ò2ÜØLó
ð 	
ñ Ü�x‰xœ˜T› B§H¡H¨Q¡K´°T³Ð;À4Ç:Á:ÔN‰ä�x‰xœ˜T› B§H¡H¨Q¡KÐ0¸¿
¹
ÔCˆà€GÜ�2—8‘8˜A‘;ÖˆÜØØŠq�!ˆt‰HØØ # ˆM˜!Ò°TØØØØ#ô	
ˆñ Ø$'Ñ!ˆAˆs�E˜6Øšš1˜j¤ C£˜jÐ(Ñ)ˆDÜ(¨¯©Ö1‘�˜!Ø9:¸>¸XÈ¹\Ð9J��S˜˜8 a™<Ð(¨!¨XÐ5Ò6ñ  2ð !‰NˆAˆs�FØˆD��a�‰LØ�‰�vÕð'  ð* 
‡x�x��{�aÒØ˜!‘*ˆáÜ�z‰z˜$Ó Ð(Ð(ä�z‰z˜$ÓÐrZ   c                   óž   — e Zd ZU dZ eeddd¬«      dg eeddd¬«      dgdg edh«      dgd	œZe	e
d
<   ddddd	œd„Z ed¬«      d„ «       Zy)Ú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. Ignored if `tol` is set.
        When `None` and `tol` is also `None`, this value is either set to 10% of
        `n_features` or 1, whichever is greater.

    tol : float, default=None
        Maximum squared 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).

    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.

    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 or None
        The number of non-zero coefficients in the solution or `None` when `tol` is
        set. 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$   Nrj   rk   r   rm   rn   ©rG   rH   Úfit_interceptro   Ú_parameter_constraintsTc                ó<   — || _         || _        || _        || _        y ©Nr—   )ÚselfrG   rH   r˜   ro   s        rX   Ú__init__z"OrthogonalMatchingPursuit.__init__å  s"   € ð  /ˆÔØˆŒØ*ˆÔØ$ˆ�rZ   rq   c           
      ó  — t        | ||ddt        ¬«      \  }}|j                  d   }t        ||d| j                  | j
                  dd¬«      \  }}}}}}}|j                  dk(  r|dd…t        j                  f   }| j                  €*| j                  €t        t        d|z  «      d«      | _        n%| j                  �d| _        n| j                  | _        |du r/t        ||| j                  | j                  ddd¬«      \  }	| _        nW| j                  �t        j                   |d	z  d
¬«      nd}
t#        ||| j                  | j                  |
ddd¬«      \  }	| _        |	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,) 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_outputÚ	y_numericr&   r$   NF)r1   Ú
check_gramrw   )rG   rH   ro   rI   rp   r'   r   ry   )rb   rG   rH   r{   rd   re   rp   )r   r   r;   r   ro   r˜   r|   r2   r”   rG   rH   r~   r   Ún_nonzero_coefs_r�   Ún_iter_r�   r‚   r8   Úcoef_Ú_set_intercept)rœ   rE   rF   Ú
n_featuresÚX_offsetÚy_offsetÚX_scalera   rb   r¤   Únorms_sqs              rX   ÚfitzOrthogonalMatchingPursuit.fitò  s„  € ô" Ø�!�Q T°TÄô
‰ˆˆ1ð —W‘W˜Q‘Zˆ
ä6>ØØØØ�O‰OØ×ÑØØô7
Ñ3ˆˆ1ˆh˜ '¨4°ð �6‰6�QŠ;Ø’!”R—Z‘Z�-Ñ ˆAà×ÑÐ'¨D¯H©HÐ,<ô %(¬¨C°*Ñ,<Ó(=¸qÓ$AˆDÕ!Ø�X‰XÐ!Ø$(ˆDÕ!à$(×$8Ñ$8ˆDÔ!à�5‰=Ü"/ØØØ $× 5Ñ 5Ø—H‘HØ ØØ"ô#ÑˆE�4•<ð 04¯x©xÐ/C”r—v‘v˜a ™d¨Õ+ÈˆHä"4ØØØ $× 5Ñ 5Ø—H‘HØ&ØØØ"ô	#ÑˆE�4”<ð —W‘WˆŒ
Ø×Ñ˜H h°Ô8ØˆrZ   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r™   ÚdictÚ__annotations__r�   r
   r«   © rZ   rX   r–   r–   …  s‚   … ñVñr % X¨q°$¸vÔFÈÐMÙ˜˜q $¨vÔ6¸Ð=Ø#˜Ù! 6 (Ó+¨YÐ7ñ	$Ð˜Dó ð ØØØô%ñ °Ô5ñDó 6ñDrZ   r–   c           	      óø  — |r@| j                  «       } |j                  «       }|j                  «       }|j                  «       }|rR| j                  d¬«      }| |z  } ||z  }|j                  d¬«      }t        |d¬«      }||z  }t        |d¬«      }||z  }t        | ||dddd¬«      }	|	j                  dk(  r|	dd…t
        j                  f   }	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).

    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   ry   F)r1   NT)rG   rH   ro   rI   rJ   r$   )	r1   Úmeanr   r�   r|   r2   r”   r7   r8   )
ÚX_trainÚy_trainÚX_testÚy_testr1   r˜   Úmax_iterÚX_meanÚy_meanrS   s
             rX   Ú_omp_path_residuesr¼   :  só   € ñX Ø—,‘,“.ˆØ—,‘,“.ˆØ—‘“ˆØ—‘“ˆáØ—‘ 1�Ó%ˆØ�6ÑˆØ�&ÑˆØ—‘ 1�Ó%ˆÜ  ¨uÔ5ˆØ�6ÑˆÜ ¨UÔ3ˆØ�&ÑˆäØØØ ØØØØô€Eð ‡z�z�Q‚Ø’aœŸ™�mÑ$ˆä�6‰6�%—'‘'˜6Ÿ8™8Ó$ vÑ-Ð-rZ   c                   óŒ   — e Zd ZU dZdgd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„Z	 e
d¬«      d„ «       Zd„ Zy)ÚOrthogonalMatchingPursuitCVay  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).

    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:`~sklearn.model_selection.KFold` is used.

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

        .. versionchanged:: 0.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_
    np.int64(10)
    >>> reg.predict(X[:1,])
    array([-78.3854])
    rm   r   Nrj   rk   Ú	cv_objectÚverbose©r1   r˜   r¹   ÚcvÚn_jobsrÀ   r™   TFc                óX   — || _         || _        || _        || _        || _        || _        y r›   rÁ   )rœ   r1   r˜   r¹   rÂ   rÃ   rÀ   s          rX   r�   z$OrthogonalMatchingPursuitCV.__init__ü  s/   € ð ˆŒ	Ø*ˆÔØ ˆŒØˆŒØˆŒØˆ�rZ   rq   c           	      ó  ‡ ‡‡‡— t        |‰ d«       t        ‰ ‰‰dd¬«      \  ŠŠt        ‰dd¬«      Št        ‰ j                  d¬«      }t        «       rt        ‰ dfi |¤Ž}nt        «       }t        i ¬«      |_        ‰ j                  s<t        t        t        d	‰j                  d
   z  «      d«      ‰j                  d
   «      n‰ j                  Š t        ‰ j                  ‰ j                   ¬«      ˆˆˆ ˆfd„ |j"                  ‰fi |j                  j"                  ¤ŽD «       «      }t        d„ |D «       «      }t%        j&                  |D �cg c]  }|d| dz  j)                  d
¬«      ‘Œ c}«      }	t%        j*                  |	j)                  d¬«      «      d
z   }
|
‰ _        t/        |
‰ j0                  ¬«      j3                  ‰‰«      }|j4                  ‰ _        |j6                  ‰ _        |j8                  ‰ _        ‰ S c c}w )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.

        **fit_params : dict
            Parameters to pass to the underlying splitter.

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

        Returns
        -------
        self : object
            Returns an instance of self.
        r«   Tr'   )r    Úensure_min_featuresF)r1   Úensure_all_finite)Ú
classifier)Úsplitrw   r$   é   )rÃ   rÀ   c           
   3   óš   •K  — | ]B  \  }} t        t        «      ‰|   ‰|   ‰|   ‰|   ‰j                  ‰j                  ‰«      –— ŒD y ­wr›   )r   r¼   r1   r˜   )Ú.0ÚtrainÚtestrE   r¹   rœ   rF   s      €€€€rX   Ú	<genexpr>z2OrthogonalMatchingPursuitCV.fit.<locals>.<genexpr>8  s`   øè ø€ ð F
ñ  K‘��tð (ŒGÔ&Ó'Ø�%‘Ø�%‘Ø�$‘Ø�$‘Ø—	‘	Ø×"Ñ"Ø÷ñ  Kùs   ƒAAc              3   ó:   K  — | ]  }|j                   d    –— Œ y­w)r   N)r;   )rÌ   Úfolds     rX   rÏ   z2OrthogonalMatchingPursuitCV.fit.<locals>.<genexpr>E  s   è ø€ Ð@±x¨t˜TŸZ™Z¨�]±xùs   ‚Nry   r   )rG   r˜   )r   r   r   r   rÂ   r   r   r   Úsplitterr¹   Úminr~   r   r;   r   rÃ   rÀ   rÉ   r2   Úarrayr´   Úargminr¢   r–   r˜   r«   r¤   Ú
intercept_r£   )rœ   rE   rF   Ú
fit_paramsrÂ   Úrouted_paramsÚcv_pathsÚmin_early_stoprÑ   Ú	mse_foldsÚbest_n_nonzero_coefsÚompr¹   s   ```         @rX   r«   zOrthogonalMatchingPursuitCV.fit  sÇ  û€ ô6 	˜* d¨EÔ2ä˜T 1 a°4ÈQÔO‰ˆˆ1Ü˜1 5¸EÔBˆÜ�d—g‘g¨%Ô0ˆÜÔÜ+¨D°%ÑF¸:ÑF‰Mô "›GˆMÜ%*°¤_ˆMÔ"ð —=’=ô ””C˜˜aŸg™g a™jÑ(Ó)¨1Ó-¨q¯w©w°q©zÔ:à—‘ð 	ð
 F”8 4§;¡;¸¿¹ÔEö F
ð  (˜rŸx™x¨ÑJ¨]×-CÑ-C×-IÑ-IÒJóF
ó 
ˆô Ñ@±xÓ@Ó@ˆÜ—H‘HÙCKÓLÁ8¸4ˆd�?�NÐ# qÑ(×.Ñ.°AÐ.Õ6À8ÑLó
ˆ	ô  "Ÿy™y¨¯©¸Q¨Ó)?Ó@À1ÑDÐØ 4ˆÔÜ'Ø0Ø×,Ñ,ô
÷ ‰#ˆa�‹)ð 	ð
 —Y‘YˆŒ
ØŸ.™.ˆŒØ—{‘{ˆŒØˆùò Ms   ÅG?c                 ó†   — t        | ¬«      j                  | j                  t        «       j                  dd¬«      ¬«      }|S )aj  Get metadata routing of this object.

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

        .. versionadded:: 1.4

        Returns
        -------
        routing : MetadataRouter
            A :class:`~sklearn.utils.metadata_routing.MetadataRouter` encapsulating
            routing information.
        )Úownerr«   rÉ   )ÚcallerÚcallee)rÒ   Úmethod_mapping)r   ÚaddrÂ   r   )rœ   Úrouters     rX   Úget_metadata_routingz0OrthogonalMatchingPursuitCV.get_metadata_routingU  sA   € ô   dÔ+×/Ñ/Ø—W‘WÜ(›?×.Ñ.°eÀGÐ.ÓLð 0ó 
ˆð ˆrZ   )r¬   r­   r®   r¯   r   r   r™   r°   r±   r�   r
   r«   rå   r²   rZ   rX   r¾   r¾   …  sƒ   … ñkð\ �Ø#˜Ù˜h¨¨4¸Ô?ÀÐFØˆmØ˜TÐ"Ø�;ñ$Ð˜Dó ð ØØØØØôñ" °Ô5ñEó 6ðEóNrZ   r¾   )NTF)NNTTF)TTéd   )3r¯   r?   Úmathr   Únumbersr   r   Únumpyr2   Úscipyr   Úscipy.linalg.lapackr   Úsklearn.baser   r	   r
   Úsklearn.linear_model._baser   r   Úsklearn.model_selectionr   Úsklearn.utilsr   r   r   Úsklearn.utils._param_validationr   r   r   Úsklearn.utils.metadata_routingr   r   r   r   r   Úsklearn.utils.parallelr   r   Úsklearn.utils.validationr   r   rA   rY   ri   Úndarrayr�   r‚   r–   r¼   r¾   r²   rZ   rX   Ú<module>rõ      sº  ðÙ ,ó
 Ý ß "ã Ý Ý 0ç GÑ Gß <Ý ,ß <Ñ <ß QÑ Q÷õ ÷ 5ß @ðð 
óq3ðp ØØØØóG3ñT àˆ^Ø�j‰jˆ\Ù$ X¨q°$¸vÔFÈÐMÙ˜˜q $¨vÔ6¸Ð=Ø ¡*¨f¨XÓ"6Ð7Ø�+Ø!�{Ø#˜ñ	ð #'ôð" ØØØØØóa óða ñH à�ØˆnÙ$ X¨q°$¸yÔIÈ4ÐPÙ˜˜q $¨vÔ6¸Ð=Ø&¨Ð-Ø�[Ø�;Ø!�{Ø#˜ñ
ð #'ôð$ ØØØØØØóa óða ôHrÐ 0°.À+ô rðt 
ØØóH.ôVc .°+õ crZ   