def derivativeFunction(x, N, N_im, sz, dims, dimOpt, dimLenOpt, lam1, lam2, data, k, strtag, ph, 
                       kern, dirWeight=0.1, dirs=None, dirInfo=[None,None,None,None], nmins=0, wavelet="db4", mode="per", a=10.):
    '''
    This is the function that we're going to be optimizing via the scipy optimization pack. This is the function that represents Compressed Sensing
    '''
    disp = 0
    gTV = 0
    gXFM = 0
    x.shape = N
    if len(N) > 2:
        x0 = np.zeros(N_im)
        for i in xrange(N[0]):
            x0[i,:,:] = tf.iwt(x[i,:,:],wavelet,mode,dims,dimOpt,dimLenOpt)
    else:
        x0 = tf.iwt(x,wavelet,mode,dims,dimOpt,dimLenOpt)
    
    gdc = grads.gDataCons(x0,N_im,ph,data,k,sz)
    #import pdb; pdb.set_trace()
    if lam1 > 1e-6:
        gtv = grads.gTV(x0,N_im,strtag,kern,dirWeight,dirs,nmins,dirInfo=dirInfo,a=a)
    
    gDataCons = np.zeros(N)
    gTV = np.zeros(N)
    gXFM = np.zeros(N)
    
    for i in xrange(N[0]):
        gDataCons[i,:,:] = tf.wt(gdc[i,:,:],wavelet,mode,dims,dimOpt,dimLenOpt)[0]
        if lam1 > 1e-6:
            gTV[i,:,:] = tf.wt(gtv[i,:,:],wavelet,mode,dims,dimOpt,dimLenOpt)[0] # Calculate the TV gradient
        if lam2 > 1e-6:
            gXFM[i,:,:] = grads.gXFM(x[i,:,:],a=a)
    
    x.shape = (x.size,)
    
    return (gDataCons + lam1*gTV + lam2*gXFM).flatten() # Export the flattened array
Ejemplo n.º 2
0
def derivativeFunction(x,
                       N,
                       N_im,
                       sz,
                       dims,
                       dimOpt,
                       dimLenOpt,
                       lam1,
                       lam2,
                       data,
                       k,
                       strtag,
                       ph,
                       kern,
                       dirWeight=0.1,
                       dirs=None,
                       dirInfo=[None, None, None, None],
                       nmins=0,
                       wavelet="db4",
                       mode="per",
                       a=10.):
    '''
    This is the function that we're going to be optimizing via the scipy optimization pack. This is the function that represents Compressed Sensing
    '''
    disp = 0
    gTV = 0
    gXFM = 0
    x.shape = N
    if len(N) > 2:
        x0 = np.zeros(N_im)
        for i in xrange(N[0]):
            x0[i, :, :] = tf.iwt(x[i, :, :], wavelet, mode, dims, dimOpt,
                                 dimLenOpt)
    else:
        x0 = tf.iwt(x, wavelet, mode, dims, dimOpt, dimLenOpt)

    gdc = grads.gDataCons(x0, N_im, ph, data, k, sz)
    #import pdb; pdb.set_trace()
    if lam1 > 1e-6:
        gtv = grads.gTV(x0,
                        N_im,
                        strtag,
                        kern,
                        dirWeight,
                        dirs,
                        nmins,
                        dirInfo=dirInfo,
                        a=a)

    gDataCons = np.zeros(N)
    gTV = np.zeros(N)
    gXFM = np.zeros(N)

    for i in xrange(N[0]):
        gDataCons[i, :, :] = tf.wt(gdc[i, :, :], wavelet, mode, dims, dimOpt,
                                   dimLenOpt)[0]
        if lam1 > 1e-6:
            gTV[i, :, :] = tf.wt(gtv[i, :, :], wavelet, mode, dims, dimOpt,
                                 dimLenOpt)[0]  # Calculate the TV gradient
        if lam2 > 1e-6:
            gXFM[i, :, :] = grads.gXFM(x[i, :, :], a=a)

    x.shape = (x.size, )

    return (gDataCons + lam1 * gTV +
            lam2 * gXFM).flatten()  # Export the flattened array