我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用sklearn.linear_model.OrthogonalMatchingPursuit()。
def GetNeighborDims(data, paras): ndata, ndim=data.shape kND=paras["kND"] objOMP=OMP(n_nonzero_coefs=kND) idxDict=npy.ones(ndim, dtype=npy.bool) w=npy.zeros((ndim-1, ndim), dtype=npy.float32) for kk in range(ndim): idxDict.fill(True) idxDict[kk]=False objOMP.fit(data[:,idxDict], data[:,kk]) w[:,kk]=objOMP.coef_.astype(npy.float32) return w
def omp_estimator(hparams): """OMP estimator""" omp_est = OrthogonalMatchingPursuit(n_nonzero_coefs=hparams.omp_k) def estimator(A_val, y_batch_val, hparams): x_hat_batch = [] for i in range(hparams.batch_size): y_val = y_batch_val[i] omp_est.fit(A_val.T, y_val.reshape(hparams.num_measurements)) x_hat = omp_est.coef_ x_hat = np.reshape(x_hat, [-1]) x_hat = np.maximum(np.minimum(x_hat, 1), 0) x_hat_batch.append(x_hat) x_hat_batch = np.asarray(x_hat_batch) return x_hat_batch return estimator