examples/utils.py
def analysis_primal_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_ == 'ista' else 'FISTA'
    max_iter = all_n_layers[-1]
    step_size = 1.0 / np.linalg.norm(A, ord=2) ** 2

    _, u0_test, _ = init_vuz(A, D, x_test)
    _, u0_train, _ = init_vuz(A, D, x_train)

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

    if verbose > 0:
        print(f"[analysis {name} iterative] training loss")
    params = dict(
        grad=lambda z: analysis_primal_grad(z, A, x_train),
        obj=lambda z: analysis_primal_obj(z, A, D, x_train, lbda),
        prox=lambda z, s: np.array([tv1_1d(z_, lbda * s) for z_ in z]),
        x0=u0_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(f"[analysis {name} iterative] testing loss")
    params = dict(
        grad=lambda z: analysis_primal_grad(z, A, x_test),
        obj=lambda z: analysis_primal_obj(z, A, D, x_test, lbda),
        prox=lambda z, s: np.array([tv1_1d(z_, lbda * s) for z_ in z]),
        x0=u0_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"\r[{name}] iterations finished "
              f"train-loss={train_loss[-1]:.6e} test-loss={test_loss[-1]:.6e}")

    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 analysis_primal_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_ == 'ista' else 'FISTA'
    max_iter = all_n_layers[-1]
    step_size = 1.0 / np.linalg.norm(A, ord=2) ** 2
    _, u0_test, _ = init_vuz(A, D, x_test)
    _, u0_train, _ = init_vuz(A, D, x_train)
    momentum = None if type_ == 'ista' else type_
    if verbose > 0:
        print(f"[analysis {name} iterative] training loss")
    params = dict(
        grad=lambda z: analysis_primal_grad(z, A, x_train),
        obj=lambda z: analysis_primal_obj(z, A, D, x_train, lbda),
        prox=lambda z, s: np.array([tv1_1d(z_, lbda * s) for z_ in z]),
        x0=u0_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(f"[analysis {name} iterative] testing loss")
    params = dict(
        grad=lambda z: analysis_primal_grad(z, A, x_test),
        obj=lambda z: analysis_primal_obj(z, A, D, x_test, lbda),
        prox=lambda z, s: np.array([tv1_1d(z_, lbda * s) for z_ in z]),
        x0=u0_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"\r[{name}] iterations finished "
              f"train-loss={train_loss[-1]:.6e} test-loss={test_loss[-1]:.6e}")
    return train_loss, test_loss
def analysis_primal_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_ == 'ista' else 'FISTA' max_iter = all_n_layers [ - 1 ] step_size = 1.0 / np . linalg . norm ( A , ord = 2 ) ** 2 _ , u0_test , _ = init_vuz ( A , D , x_test ) _ , u0_train , _ = init_vuz ( A , D , x_train ) momentum = None if type_ == 'ista' else type_ if verbose > 0 : print ( f"[analysis {name} iterative] training loss" ) params = dict ( grad = lambda z : analysis_primal_grad ( z , A , x_train ) , obj = lambda z : analysis_primal_obj ( z , A , D , x_train , lbda ) , prox = lambda z , s : np . array ( [ tv1_1d ( z_ , lbda * s ) for z_ in z ] ) , x0 = u0_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 ( f"[analysis {name} iterative] testing loss" ) params = dict ( grad = lambda z : analysis_primal_grad ( z , A , x_test ) , obj = lambda z : analysis_primal_obj ( z , A , D , x_test , lbda ) , prox = lambda z , s : np . array ( [ tv1_1d ( z_ , lbda * s ) for z_ in z ] ) , x0 = u0_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"\r[{name}] iterations finished " f"train-loss={train_loss[-1]:.6e} test-loss={test_loss[-1]:.6e}" ) 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