def _mixed_norm_solver_cd(M, G, alpha, maxit=10000, tol=1e-8, verbose=None, init=None, n_orient=1): """Solves L21 inverse problem with coordinate descent""" from sklearn.linear_model.coordinate_descent import MultiTaskLasso n_sensors, n_times = M.shape n_sensors, n_sources = G.shape if init is not None: init = init.T clf = MultiTaskLasso( alpha=alpha / len(M), tol=tol, normalize=False, fit_intercept=False, max_iter=maxit, warm_start=True ) clf.coef_ = init clf.fit(G, M) X = clf.coef_.T active_set = np.any(X, axis=1) X = X[active_set] gap, pobj, dobj, _ = dgap_l21(M, G, X, active_set, alpha, n_orient) return X, active_set, pobj
def _mixed_norm_solver_cd(M, G, alpha, maxit=10000, tol=1e-8, verbose=None, init=None, n_orient=1): """Solves L21 inverse problem with coordinate descent""" from sklearn.linear_model.coordinate_descent import MultiTaskLasso n_sensors, n_times = M.shape n_sensors, n_sources = G.shape if init is not None: init = init.T clf = MultiTaskLasso(alpha=alpha / len(M), tol=tol, normalize=False, fit_intercept=False, max_iter=maxit, warm_start=True) clf.coef_ = init clf.fit(G, M) X = clf.coef_.T active_set = np.any(X, axis=1) X = X[active_set] gap, pobj, dobj, _ = dgap_l21(M, G, X, active_set, alpha, n_orient) return X, active_set, pobj
def test_multi_task_lasso_and_enet(): X, y, X_test, y_test = build_dataset() Y = np.c_[y, y] # Y_test = np.c_[y_test, y_test] clf = MultiTaskLasso(alpha=1, tol=1e-8).fit(X, Y) assert_true(0 < clf.dual_gap_ < 1e-5) assert_array_almost_equal(clf.coef_[0], clf.coef_[1]) clf = MultiTaskElasticNet(alpha=1, tol=1e-8).fit(X, Y) assert_true(0 < clf.dual_gap_ < 1e-5) assert_array_almost_equal(clf.coef_[0], clf.coef_[1]) clf = MultiTaskElasticNet(alpha=1.0, tol=1e-8, max_iter=1) assert_warns_message(ConvergenceWarning, 'did not converge', clf.fit, X, Y)
class MultiTaskLassoImpl(): def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'): self._hyperparams = { 'alpha': alpha, 'fit_intercept': fit_intercept, 'normalize': normalize, 'copy_X': copy_X, 'max_iter': max_iter, 'tol': tol, 'warm_start': warm_start, 'random_state': random_state, 'selection': selection} def fit(self, X, y=None): self._sklearn_model = SKLModel(**self._hyperparams) if (y is not None): self._sklearn_model.fit(X, y) else: self._sklearn_model.fit(X) return self def predict(self, X): return self._sklearn_model.predict(X)
def __init__(self, alpha=1.0, fit_intercept=True, normalize=False, copy_X=True, max_iter=1000, tol=0.0001, warm_start=False, random_state=None, selection='cyclic'): self._hyperparams = { 'alpha': alpha, 'fit_intercept': fit_intercept, 'normalize': normalize, 'copy_X': copy_X, 'max_iter': max_iter, 'tol': tol, 'warm_start': warm_start, 'random_state': random_state, 'selection': selection } self._wrapped_model = SKLModel(**self._hyperparams)
def _mixed_norm_solver_cd(M, G, alpha, lipschitz_constant, maxit=10000, tol=1e-8, verbose=None, init=None, n_orient=1, dgap_freq=10): """Solve L21 inverse problem with coordinate descent.""" from sklearn.linear_model.coordinate_descent import MultiTaskLasso assert M.ndim == G.ndim and M.shape[0] == G.shape[0] clf = MultiTaskLasso(alpha=alpha / len(M), tol=tol / sum_squared(M), normalize=False, fit_intercept=False, max_iter=maxit, warm_start=True) if init is not None: clf.coef_ = init.T else: clf.coef_ = np.zeros((G.shape[1], M.shape[1])).T clf.fit(G, M) X = clf.coef_.T active_set = np.any(X, axis=1) X = X[active_set] gap, p_obj, d_obj, _ = dgap_l21(M, G, X, active_set, alpha, n_orient) return X, active_set, p_obj
'LocallyLinearEmbedding':LocallyLinearEmbedding(), 'LogisticRegression':LogisticRegression(), 'LogisticRegressionCV':LogisticRegressionCV(), 'MDS':MDS(), 'MLPClassifier':MLPClassifier(), 'MLPRegressor':MLPRegressor(), 'MaxAbsScaler':MaxAbsScaler(), 'MeanShift':MeanShift(), 'MinCovDet':MinCovDet(), 'MinMaxScaler':MinMaxScaler(), 'MiniBatchDictionaryLearning':MiniBatchDictionaryLearning(), 'MiniBatchKMeans':MiniBatchKMeans(), 'MiniBatchSparsePCA':MiniBatchSparsePCA(), 'MultiTaskElasticNet':MultiTaskElasticNet(), 'MultiTaskElasticNetCV':MultiTaskElasticNetCV(), 'MultiTaskLasso':MultiTaskLasso(), 'MultiTaskLassoCV':MultiTaskLassoCV(), 'MultinomialNB':MultinomialNB(), 'NMF':NMF(), 'NearestCentroid':NearestCentroid(), 'NearestNeighbors':NearestNeighbors(), 'Normalizer':Normalizer(), 'NuSVC':NuSVC(), 'NuSVR':NuSVR(), 'Nystroem':Nystroem(), 'OAS':OAS(), 'OneClassSVM':OneClassSVM(), 'OrthogonalMatchingPursuit':OrthogonalMatchingPursuit(), 'OrthogonalMatchingPursuitCV':OrthogonalMatchingPursuitCV(), 'PCA':PCA(), 'PLSCanonical':PLSCanonical(),