examples/utils.py
def analysis_primal_dual_iter_algo(x_train, x_test, A, D, L, lbda,
                                   all_n_layers, type_, max_iter=300,
                                   device=None, net_kwargs=None, verbose=1):
    """ Condat-Vu solver for analysis TV problem. """
    net_kwargs = dict() if net_kwargs is None else net_kwargs
    max_iter = all_n_layers[-1]
    rho = 1.0
    sigma = 0.5
    L_A = np.linalg.norm(A, ord=2) ** 2
    L_D = np.linalg.norm(D, ord=2) ** 2
    tau = 1.0 / (L_A / 2.0 + sigma * L_D)

    v0_test, u0_test, _ = init_vuz(A, D, x_test, force_numpy=True)
    v0_train, u0_train, _ = init_vuz(A, D, x_train, force_numpy=True)

    if verbose > 0:
        print("[Condat-Vu iterative] training loss")
    params = dict(
        grad=lambda u: analysis_primal_grad(u, A, x_train),
        obj=lambda u: analysis_primal_obj(u, A, D, x_train, lbda),
        prox=lambda t: _soft_th_numpy(t, lbda / sigma),
        psi=lambda u: u.dot(D), adj_psi=lambda v: v.dot(D.T),
        v0=v0_train, z0=u0_train, lbda=lbda, sigma=sigma, tau=tau, rho=rho,
        max_iter=max_iter, early_stopping=False, debug=True, verbose=verbose,
    )
    _, _, train_loss = condatvu(**params)

    if verbose > 0:
        print("[Condat-Vu iterative] testing loss")
    params = dict(
        grad=lambda u: analysis_primal_grad(u, A, x_test),
        obj=lambda u: analysis_primal_obj(u, A, D, x_test, lbda),
        prox=lambda t: _soft_th_numpy(t, lbda / sigma),
        psi=lambda u: u.dot(D), adj_psi=lambda v: v.dot(D.T),
        v0=v0_test, z0=u0_test, lbda=lbda, sigma=sigma, tau=tau, rho=rho,
        max_iter=max_iter, early_stopping=False, debug=True, verbose=verbose,
    )
    _, _, test_loss = condatvu(**params)

    train_loss = train_loss[[0] + all_n_layers]
    test_loss = test_loss[[0] + all_n_layers]

    if verbose > 0:
        print(f"\r[Condat-Vu] iterations finished "
              f"train-loss={train_loss[-1]:.4e} test-loss={test_loss[-1]:.4e}")

    return train_loss, test_loss
 Condat-Vu solver for analysis TV problem. 
Condat-Vu solver for analysis TV problem.
Condat - Vu solver for analysis TV problem .
def analysis_primal_dual_iter_algo(x_train, x_test, A, D, L, lbda,
                                   all_n_layers, type_, max_iter=300,
                                   device=None, net_kwargs=None, verbose=1):
    net_kwargs = dict() if net_kwargs is None else net_kwargs
    max_iter = all_n_layers[-1]
    rho = 1.0
    sigma = 0.5
    L_A = np.linalg.norm(A, ord=2) ** 2
    L_D = np.linalg.norm(D, ord=2) ** 2
    tau = 1.0 / (L_A / 2.0 + sigma * L_D)
    v0_test, u0_test, _ = init_vuz(A, D, x_test, force_numpy=True)
    v0_train, u0_train, _ = init_vuz(A, D, x_train, force_numpy=True)
    if verbose > 0:
        print("[Condat-Vu iterative] training loss")
    params = dict(
        grad=lambda u: analysis_primal_grad(u, A, x_train),
        obj=lambda u: analysis_primal_obj(u, A, D, x_train, lbda),
        prox=lambda t: _soft_th_numpy(t, lbda / sigma),
        psi=lambda u: u.dot(D), adj_psi=lambda v: v.dot(D.T),
        v0=v0_train, z0=u0_train, lbda=lbda, sigma=sigma, tau=tau, rho=rho,
        max_iter=max_iter, early_stopping=False, debug=True, verbose=verbose,
    )
    _, _, train_loss = condatvu(**params)
    if verbose > 0:
        print("[Condat-Vu iterative] testing loss")
    params = dict(
        grad=lambda u: analysis_primal_grad(u, A, x_test),
        obj=lambda u: analysis_primal_obj(u, A, D, x_test, lbda),
        prox=lambda t: _soft_th_numpy(t, lbda / sigma),
        psi=lambda u: u.dot(D), adj_psi=lambda v: v.dot(D.T),
        v0=v0_test, z0=u0_test, lbda=lbda, sigma=sigma, tau=tau, rho=rho,
        max_iter=max_iter, early_stopping=False, debug=True, verbose=verbose,
    )
    _, _, test_loss = condatvu(**params)
    train_loss = train_loss[[0] + all_n_layers]
    test_loss = test_loss[[0] + all_n_layers]
    if verbose > 0:
        print(f"\r[Condat-Vu] iterations finished "
              f"train-loss={train_loss[-1]:.4e} test-loss={test_loss[-1]:.4e}")
    return train_loss, test_loss
def analysis_primal_dual_iter_algo ( x_train , x_test , A , D , L , lbda , all_n_layers , type_ , max_iter = 300 , device = None , net_kwargs = None , verbose = 1 ) : net_kwargs = dict ( ) if net_kwargs is None else net_kwargs max_iter = all_n_layers [ - 1 ] rho = 1.0 sigma = 0.5 L_A = np . linalg . norm ( A , ord = 2 ) ** 2 L_D = np . linalg . norm ( D , ord = 2 ) ** 2 tau = 1.0 / ( L_A / 2.0 + sigma * L_D ) v0_test , u0_test , _ = init_vuz ( A , D , x_test , force_numpy = True ) v0_train , u0_train , _ = init_vuz ( A , D , x_train , force_numpy = True ) if verbose > 0 : print ( "[Condat-Vu iterative] training loss" ) params = dict ( grad = lambda u : analysis_primal_grad ( u , A , x_train ) , obj = lambda u : analysis_primal_obj ( u , A , D , x_train , lbda ) , prox = lambda t : _soft_th_numpy ( t , lbda / sigma ) , psi = lambda u : u . dot ( D ) , adj_psi = lambda v : v . dot ( D . T ) , v0 = v0_train , z0 = u0_train , lbda = lbda , sigma = sigma , tau = tau , rho = rho , max_iter = max_iter , early_stopping = False , debug = True , verbose = verbose , ) _ , _ , train_loss = condatvu ( ** params ) if verbose > 0 : print ( "[Condat-Vu iterative] testing loss" ) params = dict ( grad = lambda u : analysis_primal_grad ( u , A , x_test ) , obj = lambda u : analysis_primal_obj ( u , A , D , x_test , lbda ) , prox = lambda t : _soft_th_numpy ( t , lbda / sigma ) , psi = lambda u : u . dot ( D ) , adj_psi = lambda v : v . dot ( D . T ) , v0 = v0_test , z0 = u0_test , lbda = lbda , sigma = sigma , tau = tau , rho = rho , max_iter = max_iter , early_stopping = False , debug = True , verbose = verbose , ) _ , _ , test_loss = condatvu ( ** params ) train_loss = train_loss [ [ 0 ] + all_n_layers ] test_loss = test_loss [ [ 0 ] + all_n_layers ] if verbose > 0 : print ( f"\r[Condat-Vu] iterations finished " f"train-loss={train_loss[-1]:.4e} test-loss={test_loss[-1]:.4e}" ) return train_loss , test_loss
Condat-Vu solver for analysis TV problem.
Condat - Vu solver for analysis TV problem .
""" Condat-Vu solver for analysis TV problem. """
x_train
x_test
A
D
L
lbda
all_n_layers
type_
max_iter
device
net_kwargs
verbose