Esempio n. 1
0
def test_are_we_saveobjective_agnostic():
    """Test whether the reconstruction is the same unrespective to the 
    'saveobjective flag'
    """
    
    ## Generate data
    np.random.seed(42)
    A = np.genfromtxt('./demodata/fourierbasis.csv') # Measurement matrix
    f = cstools.generate_1D(512, .95) # Signal
    y = cstools.measure(f,A)

    rec_save = pySPIRALTAP.SPIRALTAP(y,A,1e-6,
                                     maxiter=100,
                                     miniter=5,
                                     penalty='canonical',
                                     noisetype='gaussian',
                                     stopcriterion=3,
                                     tolerance=1e-8,
                                     alphainit=1,
                                     alphamin=1e-30,
                                     alphamax=1e30,
                                     alphaaccept=1e30,
                                     logepsilon=1e-10,
                                     saveobjective=True,
                                     savereconerror=False,
                                     savesolutionpath=False,
                                     truth=f,
                                     verbose=0, savecputime=False)[0]

    rec_nosave = pySPIRALTAP.SPIRALTAP(y,A,1e-6,
                                       maxiter=100,
                                       miniter=5,
                                       penalty='canonical',
                                       noisetype='gaussian',
                                       stopcriterion=3,
                                       tolerance=1e-8,
                                       alphainit=1,
                                       alphamin=1e-30,
                                       alphamax=1e30,
                                       alphaaccept=1e30,
                                       logepsilon=1e-10,
                                       saveobjective=False,
                                       savereconerror=False,
                                       savesolutionpath=False,
                                       truth=f,
                                       verbose=0,savecputime=False)[0]

    er = ((rec_save- rec_nosave)**2).sum()/(rec_save**2).sum()
    print("L2 error between the two reconstructions : ", er)
    assert er == 0 
Esempio n. 2
0
def reconstruct_1Dspiral(measure,
                         basis,
                         maxiter=500,
                         verbose=0,
                         W=[],
                         penalty='canonical',
                         noisetype='gaussian'):
    """Reconstruct using pySPIRALTAP and default parameters"""

    ## ==== Parameters
    tau = 1e-6
    tolerance = 1e-8

    ## ==== Create function handles
    y = measure  #.reshape((measure.size,1))
    AT = lambda x: basis.transpose().dot(x)
    A = lambda x: basis.dot(x)
    finit = y.sum() * AT(y).size / AT(y).sum() / AT(
        np.ones_like(y)).sum() * AT(y)

    rec_l1 = pySPIRALTAP.SPIRALTAP(
        y,
        A,
        tau,
        AT=AT,
        W=W,
        maxiter=maxiter,
        miniter=5,
        penalty=penalty,
        noisetype=noisetype,
        #initialization=finit,
        stopcriterion=3,
        tolerance=tolerance,
        alphainit=1,
        alphamin=1e-30,
        alphamax=1e30,
        alphaaccept=1e30,
        logepsilon=1e-10,
        verbose=verbose)[0]
    return rec_l1
Esempio n. 3
0
def run_spiral(y,Ao,f,finit=None, penalty='canonical', W=[], WT=[]):
    """Simple wrapper for SPIRAL function. All the parameters are preset."""
    ## Set regularization parameters and iteration limit:
    tau   = 1e-6
    maxiter = 100
    tolerance = 1e-8
    verbose = 0

    ## Setup function handles for computing A and A^T:
    AT = lambda x: Ao.transpose().dot(x)
    A = lambda x: Ao.dot(x)

    if finit==None: ## rescaled least-square to initialize finit
        finit = y.sum()*AT(y).size/AT(y).sum()/AT(np.ones_like(y)).sum() * AT(y)
    
    return pySPIRALTAP.SPIRALTAP(y,A,tau,
                                 AT=AT,
                                 W=W,
                                 WT=WT,
                                 maxiter=maxiter,
                                 miniter=5,
                                 penalty=penalty,
                                 noisetype='gaussian',
                                 initialization=finit,
                                 stopcriterion=3,
                                 tolerance=tolerance,
                                 alphainit=1,
                                 alphamin=1e-30,
                                 alphamax=1e30,
                                 alphaaccept=1e30,
                                 logepsilon=1e-10,
                                 saveobjective=True,
                                 savereconerror=False,
                                 savesolutionpath=False,
                                 truth=f,
                                 verbose=verbose, savecputime=False)[0]
Esempio n. 4
0
    finit = y.sum() * AT(y).size / AT(y).sum() / AT(
        np.ones_like(y)).sum() * AT(y)

    # ==== Run the algorithm:
    ## Demonstrating all the options for our algorithm:
    resSPIRAL = pySPIRALTAP.SPIRALTAP(y,
                                      A,
                                      tau,
                                      AT=AT,
                                      maxiter=maxiter,
                                      miniter=5,
                                      penalty='canonical',
                                      noisetype='gaussian',
                                      initialization=finit,
                                      stopcriterion=3,
                                      tolerance=tolerance,
                                      alphainit=1,
                                      alphamin=1e-30,
                                      alphamax=1e30,
                                      alphaaccept=1e30,
                                      logepsilon=1e-10,
                                      saveobjective=True,
                                      savereconerror=True,
                                      savesolutionpath=False,
                                      truth=f,
                                      verbose=verbose,
                                      savecputime=True)
    ## Deparse outputs
    fhatSPIRAL = resSPIRAL[0]
    parSPIRAL = resSPIRAL[1]
    iterationsSPIRAL = parSPIRAL['iterations']
    objectiveSPIRAL = parSPIRAL['objective']