8.正交匹配跟踪 Orthogonal Matching Pursuit (OMP)s
生活随笔
收集整理的這篇文章主要介紹了
8.正交匹配跟踪 Orthogonal Matching Pursuit (OMP)s
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
OrthogonalMatchingPursuit and orthogonal_mp 實現了一個用來逼近在非零系數的個數上加約束的線性模型的擬合的OMP算法(比如L 0?pseudo-norm)
和 Least Angle Regression最小角回歸 一樣,作為一個前向特征選擇方法,OMP可以用一個固定非零的數來逼近最優的解向量:
或者說正交匹配算法可以針對一個特殊的誤差而不是一個特殊的非零系數的個數,這一過程可以表達為:
OMP是基于貪婪算法,包括在每一步原子(歸一化的向量)與當前殘差高度相關。它類似于簡單 匹配追蹤(MP)方法,但更好的,在每一次迭代中,通過使用的在前一個選擇的字典元素的空間的正交投影重新計算殘差。
import matplotlib.pyplot as plt import numpy as np from sklearn.linear_model import OrthogonalMatchingPursuit from sklearn.linear_model import OrthogonalMatchingPursuitCV from sklearn.datasets import make_sparse_coded_signaln_components, n_features = 512, 100 n_nonzero_coefs = 17# generate the data #################### y = Xw # |x|_0 = n_nonzero_coefsy, X, w = make_sparse_coded_signal(n_samples=1,n_components=n_components,n_features=n_features,n_nonzero_coefs=n_nonzero_coefs,random_state=0)idx, = w.nonzero()# distort the clean signal ########################## y_noisy = y + 0.05 * np.random.randn(len(y))# plot the sparse signal ######################## plt.figure(figsize=(7, 7)) plt.subplot(4, 1, 1) plt.xlim(0, 512) plt.title("Sparse signal") plt.stem(idx, w[idx])# plot the noise-free reconstruction ####################################omp = OrthogonalMatchingPursuit(n_nonzero_coefs=n_nonzero_coefs) omp.fit(X, y) coef = omp.coef_ idx_r, = coef.nonzero() plt.subplot(4, 1, 2) plt.xlim(0, 512) plt.title("Recovered signal from noise-free measurements") plt.stem(idx_r, coef[idx_r])# plot the noisy reconstruction ############################### omp.fit(X, y_noisy) coef = omp.coef_ idx_r, = coef.nonzero() plt.subplot(4, 1, 3) plt.xlim(0, 512) plt.title("Recovered signal from noisy measurements") plt.stem(idx_r, coef[idx_r])# plot the noisy reconstruction with number of non-zeros set by CV ################################################################## omp_cv = OrthogonalMatchingPursuitCV() omp_cv.fit(X, y_noisy) coef = omp_cv.coef_ idx_r, = coef.nonzero() plt.subplot(4, 1, 4) plt.xlim(0, 512) plt.title("Recovered signal from noisy measurements with CV") plt.stem(idx_r, coef[idx_r])plt.subplots_adjust(0.06, 0.04, 0.94, 0.90, 0.20, 0.38) plt.suptitle('Sparse signal recovery with Orthogonal Matching Pursuit',fontsize=16) plt.show()
總結
以上是生活随笔為你收集整理的8.正交匹配跟踪 Orthogonal Matching Pursuit (OMP)s的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 7.LARS lasso 模型
- 下一篇: 10.1引用数据类型的转换