Given a dictionary D whose columns are candidate features (or atoms), and a target y, we want a coefficient vector with only a few nonzero entries. Orthogonal matching pursuit (OMP) builds that support one column at a time.
Implement omp(D, y, k). It returns a coefficient vector of length d with at most k nonzero entries.
r = y.|D^T r| among columns not yet selected. Ties go to the smallest index.y on the selected columns. Update the residual to y - D_S x_S.k times, then write the least-squares coefficients into their positions.D is 2-D with n rows, y has length n.0 <= k <= d, otherwise raise ValueError.k = 0 returns all zeros.Set the correlation of already-selected columns to negative infinity before the argmax, so they cannot be picked twice.
No results yet
Run your code to check it against the examples, or submit to run every test.