Example #1
0
    def test_FISTA_Norm2Sq(self):
        print("Test FISTA Norm2Sq")
        ig = ImageGeometry(127, 139, 149)
        b = ig.allocate(ImageGeometry.RANDOM)
        # fill with random numbers
        initial = ig.allocate(ImageGeometry.RANDOM)
        identity = IdentityOperator(ig)

        #### it seems FISTA does not work with Nowm2Sq
        norm2sq = LeastSquares(identity, b)
        #norm2sq.L = 2 * norm2sq.c * identity.norm()**2
        #norm2sq = OperatorCompositionFunction(L2NormSquared(b=b), identity)
        opt = {'tol': 1e-4, 'memopt': False}
        if debug_print:
            print("initial objective", norm2sq(initial))
        alg = FISTA(initial=initial, f=norm2sq, g=ZeroFunction())
        alg.max_iteration = 2
        alg.run(20, verbose=0)
        self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())

        alg = FISTA(initial=initial,
                    f=norm2sq,
                    g=ZeroFunction(),
                    max_iteration=2,
                    update_objective_interval=3)
        self.assertTrue(alg.max_iteration == 2)
        self.assertTrue(alg.update_objective_interval == 3)

        alg.run(20, verbose=0)
        self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())
Example #2
0
    def test_FISTA_catch_Lipschitz(self):
        if debug_print:
            print("Test FISTA catch Lipschitz")
        ig = ImageGeometry(127, 139, 149)
        initial = ImageData(geometry=ig)
        initial = ig.allocate()
        b = initial.copy()
        # fill with random numbers
        b.fill(numpy.random.random(initial.shape))
        initial = ig.allocate(ImageGeometry.RANDOM)
        identity = IdentityOperator(ig)

        #### it seems FISTA does not work with Nowm2Sq
        norm2sq = LeastSquares(identity, b)
        if debug_print:
            print('Lipschitz', norm2sq.L)
        # norm2sq.L = None
        #norm2sq.L = 2 * norm2sq.c * identity.norm()**2
        #norm2sq = OperatorCompositionFunction(L2NormSquared(b=b), identity)
        opt = {'tol': 1e-4, 'memopt': False}
        if debug_print:
            print("initial objective", norm2sq(initial))
        try:
            alg = FISTA(initial=initial, f=L1Norm(), g=ZeroFunction())
            self.assertTrue(False)
        except ValueError as ve:
            print(ve)
            self.assertTrue(True)
Example #3
0
    def test_FISTA_Denoising(self):
        if debug_print:
            print("FISTA Denoising Poisson Noise Tikhonov")
        # adapted from demo FISTA_Tikhonov_Poisson_Denoising.py in CIL-Demos repository
        data = dataexample.SHAPES.get()
        ig = data.geometry
        ag = ig
        N = 300
        # Create Noisy data with Poisson noise
        scale = 5
        noisy_data = applynoise.poisson(data / scale, seed=10) * scale

        # Regularisation Parameter
        alpha = 10

        # Setup and run the FISTA algorithm
        operator = GradientOperator(ig)
        fid = KullbackLeibler(b=noisy_data)
        reg = OperatorCompositionFunction(alpha * L2NormSquared(), operator)

        initial = ig.allocate()
        fista = FISTA(initial=initial, f=reg, g=fid)
        fista.max_iteration = 3000
        fista.update_objective_interval = 500
        fista.run(verbose=0)
        rmse = (fista.get_output() - data).norm() / data.as_array().size
        if debug_print:
            print("RMSE", rmse)
        self.assertLess(rmse, 4.2e-4)
 def test_exception_initial_FISTA(self):
     if debug_print:
         print ("Test FISTA")
     ig = ImageGeometry(127,139,149)
     initial = ig.allocate()
     b = initial.copy()
     # fill with random numbers
     b.fill(numpy.random.random(initial.shape))
     initial = ig.allocate(ImageGeometry.RANDOM)
     identity = IdentityOperator(ig)
     
     norm2sq = OperatorCompositionFunction(L2NormSquared(b=b), identity)
     opt = {'tol': 1e-4, 'memopt':False}
     if debug_print:
         print ("initial objective", norm2sq(initial))
     try:
         alg = FISTA(initial=initial, f=norm2sq, g=ZeroFunction(), x_init=initial)
         assert False
     except ValueError as ve:
         assert True
Example #5
0
fbp = FBP(ig, ag)
fbp.set_input(aq_data)
FBP_3D_gpu = fbp.get_output()

show2D(FBP_3D_gpu,
       slice_list=[('vertical', 204 // bins), ('horizontal_y', 570 // bins)],
       title="FBP reconstruction",
       fix_range=(-0.02, 0.07))
#%% Setup least sqaures and force pre-calculation of Lipschitz constant
Projector = ProjectionOperator(ig, ag)
LS = LeastSquares(A=Projector, b=aq_data)
print("Lipschitz constant =", LS.L)

#%% Setup FISTA to solve for least squares
fista = FISTA(x_init=ig.allocate(0),
              f=LS,
              g=ZeroFunction(),
              max_iteration=1000)
fista.update_objective_interval = 10

#%% Run FISTA
fista.run(300)
LS_reco = fista.get_output()
show2D(LS_reco,
       slice_list=[('vertical', 204 // bins), ('horizontal_y', 570 // bins)],
       title="LS reconstruction",
       fix_range=(-0.02, 0.07))

#%%
plt.figure()
plt.semilogy(fista.objective)
plt.title('FISTA LS criterion')
Example #6
0
    # the c parameter is used to remove scaling of L2NormSquared in PDHG
    #
    c = 2
    f = LeastSquares(K, ldata, c=0.5 * c)
    if sparse_beads:
        f.L = 1071.1967 * c
    else:
        f.L = 24.4184 * c
    alpha_rgl = 0.003
    alpha = alpha_rgl * ig_cs.voxel_size_x
    g = c * alpha * TotalVariation(lower=0.)
    g = FGP_TV(alpha, 100, 1e-5, 1, 1, 0, 'gpu')

    algo = FISTA(initial=K.domain.allocate(0),
                 f=f,
                 g=g,
                 max_iteration=10000,
                 update_objective_interval=2)
    #%%
    import cProfile
    algo.update_objective_interval = 10
    cProfile.run('algo.run(100, verbose=1)')
    #%%
    plotter2D(algo.solution, cmap='gist_earth')

    #%%

    cProfile.run('algo.run(1)')

    # %%
    from cil.optimisation.algorithms import PDHG