Ejemplo n.º 1
0
def fista(A,
          W,
          y,
          mu=1.,
          nu=None,
          threshold=thresholding.hard,
          x0=None,
          maxiter=100,
          callback=None):
    """ Fista algorithm
    
    """
    if callback is None:
        callback = lo.CallbackFactory(verbose=True)
    if x0 is None:
        x = A.T * y
    else:
        x = copy(x0)
    x_old = np.zeros(x.shape)
    t_old = 1.
    for iter_ in xrange(maxiter):
        t = (1 + np.sqrt(1 + 4 * t_old**2)) / 2
        a = (t_old - 1) / t
        t_old = copy(t)
        z = x + a * (x - x_old)
        g = A.T * (A * z - y)
        x = z - .5 * mu * g
        x = W.T * threshold(W * x, nu)
        x_old = copy(x)
        resid = lo.norm2(A * x - y) + 1 / (2 * nu) * lo.normp(p=1)(x)
        callback(x)
    return x
Ejemplo n.º 2
0
def landweber(A,
              W,
              y,
              mu=1.,
              nu=None,
              threshold=thresholding.hard,
              x0=None,
              maxiter=100,
              callback=None):
    """Landweber algorithm
    
    Input
    -----
    A : measurement matrix
    W : wavelet transform
    y : data
    mu : step of the gradient update
    nu : thresholding coefficient
    threshold : thresholding function
    maxiter : number of iterations
    callback : callback function
    
    Output
    ------
    
    x : solution
    
    """
    if callback is None:
        callback = lo.CallbackFactory(verbose=True)
    if x0 is None:
        x = A.T * y
    else:
        x = copy(x0)
    for iter_ in xrange(maxiter):
        r = A * x - y
        x += .5 * mu * A.T * (r)
        x = W.T * threshold(W * x, nu)
        resid = lo.norm2(r) + 1 / (2 * nu) * lo.normp(p=1)(x)
        callback(x)
    return x
Ejemplo n.º 3
0
import lo.pywt_lo as pywt_lo

# data
pacs = PacsObservation(filename=tamasis_dir + 'tests/frames_blue.fits',
                       fine_sampling_factor=1,
                       keep_bad_detectors=False)
tod = pacs.get_tod()
# projector
projection = Projection(pacs,
                        resolution=3.2,
                        oversampling=False,
                        npixels_per_sample=6)
model = projection
# naive map
backmap = model.transpose(tod)
# mask
M = lo.mask(backmap < 0).T
#M = lo.identity(2 * (backmap.size,))
# transform to lo
P = lo.aslinearoperator(model.aslinearoperator()) * M
# prior
Dx = lo.diff(backmap.shape, axis=0, dtype=np.float64) * M
Dy = lo.diff(backmap.shape, axis=1, dtype=np.float64) * M
Dw = pywt_lo.wavelet2(backmap.shape, "haar") * M
# inversion
y = tod.flatten()
callback = lo.CallbackFactory(verbose=True)
x = it.rirls(P, (Dx, Dy, Dw), y, p=1.5, maxiter=100, callback=callback)
sol = backmap.zeros(backmap.shape)
sol[:] = (M * x).reshape(sol.shape)