Esempio n. 1
0
def test_monitor():
    model = Lasso(estimator=estimator)
    criterion = HeldOutMSE(idx_train, idx_val)
    algo = ImplicitForward()
    monitor = Monitor(callback=callback)
    optimizer = LineSearch(n_outer=10, tol=tol)
    grad_search(algo, criterion, model, optimizer, X, y, alpha0, monitor)

    np.testing.assert_allclose(np.array(monitor.objs), np.array(objs))
Esempio n. 2
0
def test_monitor():
    model = Lasso(estimator=estimator)
    criterion = HeldOutMSE(idx_train, idx_val)
    algo = ImplicitForward()
    monitor = Monitor(callback=callback)

    grad_search(algo,
                criterion,
                model,
                X,
                y,
                np.log(alpha_max / 10),
                monitor,
                n_outer=10,
                tol=tol)

    np.testing.assert_allclose(np.array(monitor.objs), np.array(objs))
Esempio n. 3
0
 criterion = CrossVal(sub_criterion, cv=kf)
 algo = ImplicitForward(tol_jac=1e-3)
 # optimizer = LineSearch(n_outer=10, tol=tol)
 if algo_name.startswith('implicit_forward'):
     if algo_name == "implicit_forward_approx":
         optimizer = GradientDescent(n_outer=30,
                                     p_grad_norm=1.,
                                     verbose=True,
                                     tol=tol,
                                     tol_decrease="geom")
     else:
         optimizer = GradientDescent(n_outer=30,
                                     p_grad_norm=1.,
                                     verbose=True,
                                     tol=tol)
     grad_search(algo, criterion, model, optimizer, X, y, alpha0, monitor)
 elif algo_name == 'grid_search':
     grid_search(algo,
                 criterion,
                 model,
                 X,
                 y,
                 None,
                 None,
                 monitor,
                 max_evals=20,
                 tol=tol,
                 alphas=alphas)
 elif algo_name == 'random_search' or algo_name == 'bayesian':
     hyperopt_wrapper(algo,
                      criterion,
Esempio n. 4
0
estimator = sklearn.linear_model.Lasso(fit_intercept=False,
                                       max_iter=1000,
                                       warm_start=True,
                                       tol=tol)

print('sparse-ho started')

t0 = time.time()
model = Lasso()
criterion = HeldOutMSE(None, None)
alpha0 = alpha_max / 10
monitor_grad = Monitor()
cross_val_criterion = CrossVal(criterion, cv=kf)
algo = ImplicitForward()
optimizer = LineSearch(n_outer=10, tol=tol)
grad_search(algo, cross_val_criterion, model, optimizer, X, y, alpha0,
            monitor_grad)

t_grad_search = time.time() - t0

print('sparse-ho finished')

##############################################################################
# Plot results
# ------------
objs = reg.mse_path_.mean(axis=1)

p_alphas_grad = np.array(monitor_grad.alphas) / alpha_max
objs_grad = np.array(monitor_grad.objs)

print(f"Time for grid search: {t_sk:.2f} s")
print(f"Time for grad search (sparse-ho): {t_grad_search:.2f} s")