示例#1
0
    def test_asaga_solver(self):
        """...Check ASAGA solver for a Logistic Regression with Elastic net
        penalization
        """
        seed = 1398
        np.random.seed(seed)
        n_samples = 4000
        n_features = 30
        weights = weights_sparse_gauss(n_features, nnz=3).astype(self.dtype)
        intercept = 0.2
        penalty_strength = 1e-3
        sparsity = 1e-4
        features = sparse.rand(n_samples, n_features, density=sparsity,
                               format='csr', random_state=8).astype(self.dtype)

        simulator = SimuLogReg(weights, n_samples=n_samples, features=features,
                               verbose=False, intercept=intercept,
                               dtype=self.dtype)
        features, labels = simulator.simulate()

        model = ModelLogReg(fit_intercept=True)
        model.fit(features, labels)
        prox = ProxElasticNet(penalty_strength, ratio=0.1, range=(0,
                                                                  n_features))
        solver_step = 1. / model.get_lip_max()
        saga = SAGA(step=solver_step, max_iter=100, tol=1e-10, verbose=False,
                    n_threads=1, record_every=10, seed=seed)
        saga.set_model(model).set_prox(prox)
        saga.solve()

        asaga = SAGA(step=solver_step, max_iter=100, tol=1e-10, verbose=False,
                     n_threads=2, record_every=10, seed=seed)
        asaga.set_model(model).set_prox(prox)
        asaga.solve()

        np.testing.assert_array_almost_equal(saga.solution, asaga.solution,
                                             decimal=4)
        self.assertGreater(np.linalg.norm(saga.solution[:-1]), 0)
示例#2
0
#!/usr/bin/python3
# expect tick first on PYTHONPATH

from tick.array.build.array import tick_double_sparse2d_from_file, tick_double_array_from_file
from tick.prox import ProxL2Sq; from tick.solver import SAGA; from tick.linear_model import ModelLogReg

X = tick_double_sparse2d_from_file("url.features.cereal")
n_samples = X.shape[0]; n_features = X.shape[1]
y = tick_double_array_from_file   ("url.labels.cereal")

model = ModelLogReg(fit_intercept=False).fit(X, y)
prox = ProxL2Sq((1. / n_samples) + 1e-10, range=(0, n_features))
asaga = SAGA(step=0.00257480411965, max_iter=200, tol=1e-10, verbose=False,
            n_threads=8, log_every_n_epochs=10)
asaga.set_model(model).set_prox(prox)
asaga.solve()
asaga.print_history()