Orthogonal Matching Pursuit
make_sparse_coded_signal
from
sklearn.linear_model
import
,
n_components
,
n_features
=
512
,
100
n_nonzero_coefs
=
17
y
,
X
,
w
=
(
n_samples
=
1
,
n_components
=
n_components
,
n_features
=
n_features
,
n_nonzero_coefs
=
n_nonzero_coefs
,
random_state
=
0
,
)
X
=
X
.
T
(
idx
,)
=
w
.
nonzero
()
y_noisy
=
y
+
0.05
*
(
len
(
y
))
(
figsize
=
(
7
,
7
))
(
4
,
1
,
1
)
(
0
,
512
)
(
"Sparse signal"
)
(
idx
,
w
[
idx
])
omp
=
(
n_nonzero_coefs
=
n_nonzero_coefs
)
omp
.
fit
(
X
,
y
)
coef
=
omp
.
coef_
(
idx_r
,)
=
coef
.
nonzero
()
(
4
,
1
,
2
)
(
0
,
512
)
(
"Recovered signal from noise-free measurements"
)
(
idx_r
,
coef
[
idx_r
])
omp
.
fit
(
X
,
y_noisy
)
coef
=
omp
.
coef_
(
idx_r
,)
=
coef
.
nonzero
()
(
4
,
1
,
3
)
(
0
,
512
)
(
"Recovered signal from noisy measurements"
)
(
idx_r
,
coef
[
idx_r
])
omp_cv
=
()
omp_cv
.
fit
(
X
,
y_noisy
)
coef
=
omp_cv
.
coef_
(
idx_r
,)
=
coef
.
nonzero
()
(
4
,
1
,
4
)
(
0
,
512
)
(
"Recovered signal from noisy measurements with CV"
)
(
idx_r
,
coef
[
idx_r
])
(
0.06
,
0.04
,
0.94
,
0.90
,
0.20
,
0.38
)
(
"Sparse signal recovery with Orthogonal Matching Pursuit"
,
fontsize
=
16
)
()
Total running time of the script: (0 minutes 0.228 seconds)
Related examples