examples/utils.py
def synthesis_iter_algo(x_train, x_test, A, D, L, lbda, all_n_layers, type_,
                        max_iter=300, device=None, net_kwargs=None,
                        verbose=1):
    """ Iterative-algo solver for synthesis TV problem. """
    net_kwargs = dict() if net_kwargs is None else net_kwargs
    name = 'ISTA' if type_ == 'chambolle' else 'FISTA'
    max_iter = all_n_layers[-1]
    LA = L.dot(A)
    step_size = 1.0 / np.linalg.norm(LA, ord=2) ** 2

    _, _, z0_test = init_vuz(A, D, x_test)
    _, _, z0_train = init_vuz(A, D, x_train)

    momentum = None if type_ == 'ista' else type_

    if verbose > 0:
        print("[ISTA iterative] training loss")
    params = dict(
        grad=lambda z: synthesis_primal_grad(z, A, L, x_train),
        obj=lambda z: synthesis_primal_obj(z, A, L, x_train, lbda),
        prox=lambda z, s: pseudo_soft_th_numpy(z, lbda, s),
        x0=z0_train,  momentum=momentum, restarting=None,
        max_iter=max_iter, step_size=step_size, early_stopping=False,
        debug=True, verbose=verbose,
    )
    _, train_loss = fista(**params)

    if verbose > 0:
        print("[ISTA iterative] testing loss")
    params = dict(
        grad=lambda z: synthesis_primal_grad(z, A, L, x_test),
        obj=lambda z: synthesis_primal_obj(z, A, L, x_test, lbda),
        prox=lambda z, s: pseudo_soft_th_numpy(z, lbda, s),
        x0=z0_test,  momentum=momentum, restarting=None,
        max_iter=max_iter, step_size=step_size, early_stopping=False,
        debug=True, verbose=verbose,
    )
    _, test_loss = fista(**params)

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

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

    return train_loss, test_loss
 Iterative-algo solver for synthesis TV problem. 
Iterative-algo solver for synthesis TV problem.
Iterative - algo solver for synthesis TV problem .
def synthesis_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
    name = 'ISTA' if type_ == 'chambolle' else 'FISTA'
    max_iter = all_n_layers[-1]
    LA = L.dot(A)
    step_size = 1.0 / np.linalg.norm(LA, ord=2) ** 2
    _, _, z0_test = init_vuz(A, D, x_test)
    _, _, z0_train = init_vuz(A, D, x_train)
    momentum = None if type_ == 'ista' else type_
    if verbose > 0:
        print("[ISTA iterative] training loss")
    params = dict(
        grad=lambda z: synthesis_primal_grad(z, A, L, x_train),
        obj=lambda z: synthesis_primal_obj(z, A, L, x_train, lbda),
        prox=lambda z, s: pseudo_soft_th_numpy(z, lbda, s),
        x0=z0_train,  momentum=momentum, restarting=None,
        max_iter=max_iter, step_size=step_size, early_stopping=False,
        debug=True, verbose=verbose,
    )
    _, train_loss = fista(**params)
    if verbose > 0:
        print("[ISTA iterative] testing loss")
    params = dict(
        grad=lambda z: synthesis_primal_grad(z, A, L, x_test),
        obj=lambda z: synthesis_primal_obj(z, A, L, x_test, lbda),
        prox=lambda z, s: pseudo_soft_th_numpy(z, lbda, s),
        x0=z0_test,  momentum=momentum, restarting=None,
        max_iter=max_iter, step_size=step_size, early_stopping=False,
        debug=True, verbose=verbose,
    )
    _, test_loss = fista(**params)
    train_loss = train_loss[[0] + all_n_layers]
    test_loss = test_loss[[0] + all_n_layers]
    if verbose > 0:
        print(f"[{name}] iterations finished "
              f"train-loss={train_loss[-1]:.4e} test-loss={test_loss[-1]:.4e}")
    return train_loss, test_loss
def synthesis_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 name = 'ISTA' if type_ == 'chambolle' else 'FISTA' max_iter = all_n_layers [ - 1 ] LA = L . dot ( A ) step_size = 1.0 / np . linalg . norm ( LA , ord = 2 ) ** 2 _ , _ , z0_test = init_vuz ( A , D , x_test ) _ , _ , z0_train = init_vuz ( A , D , x_train ) momentum = None if type_ == 'ista' else type_ if verbose > 0 : print ( "[ISTA iterative] training loss" ) params = dict ( grad = lambda z : synthesis_primal_grad ( z , A , L , x_train ) , obj = lambda z : synthesis_primal_obj ( z , A , L , x_train , lbda ) , prox = lambda z , s : pseudo_soft_th_numpy ( z , lbda , s ) , x0 = z0_train , momentum = momentum , restarting = None , max_iter = max_iter , step_size = step_size , early_stopping = False , debug = True , verbose = verbose , ) _ , train_loss = fista ( ** params ) if verbose > 0 : print ( "[ISTA iterative] testing loss" ) params = dict ( grad = lambda z : synthesis_primal_grad ( z , A , L , x_test ) , obj = lambda z : synthesis_primal_obj ( z , A , L , x_test , lbda ) , prox = lambda z , s : pseudo_soft_th_numpy ( z , lbda , s ) , x0 = z0_test , momentum = momentum , restarting = None , max_iter = max_iter , step_size = step_size , early_stopping = False , debug = True , verbose = verbose , ) _ , test_loss = fista ( ** params ) train_loss = train_loss [ [ 0 ] + all_n_layers ] test_loss = test_loss [ [ 0 ] + all_n_layers ] if verbose > 0 : print ( f"[{name}] iterations finished " f"train-loss={train_loss[-1]:.4e} test-loss={test_loss[-1]:.4e}" ) return train_loss , test_loss
Iterative-algo solver for synthesis TV problem.
Iterative - algo solver for synthesis TV problem .
""" Iterative-algo solver for synthesis TV problem. """
x_train
x_test
A
D
L
lbda
all_n_layers
type_
max_iter
device
net_kwargs
verbose