Skip to content

FIX Clip n_nonzero_coefs in OMP instead of raising#34193

Open
EdenRochmanSharabi wants to merge 1 commit into
scikit-learn:mainfrom
EdenRochmanSharabi:fix/dict-learning-omp-consistency
Open

FIX Clip n_nonzero_coefs in OMP instead of raising#34193
EdenRochmanSharabi wants to merge 1 commit into
scikit-learn:mainfrom
EdenRochmanSharabi:fix/dict-learning-omp-consistency

Conversation

@EdenRochmanSharabi
Copy link
Copy Markdown
Contributor

Closes #33454.

OrthogonalMatchingPursuit raises a ValueError when
n_nonzero_coefs > n_features, but LARS silently clips to n_features.
This means DictionaryLearning(transform_algorithm="omp") crashes while
transform_algorithm="lars" works fine for the same input.

This PR changes OMP to emit a UserWarning and clip n_nonzero_coefs
to n_features, matching the LARS behavior. The change applies to both
orthogonal_mp and orthogonal_mp_gram.

The clipping approach is consistent with how LARS handles this
internally (see max_features = min(max_iter, n_features) in
_lars_path_solver), where the cap was introduced as a memory
pre-allocation guard rather than parameter validation.

OrthogonalMatchingPursuit raises a ValueError when
n_nonzero_coefs > n_features, but LARS silently clips to
n_features. This changes OMP to emit a UserWarning and clip,
making the two algorithms consistent when used through
DictionaryLearning(transform_algorithm="omp").
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DictionaryLearner dies with 'omp' only

1 participant