Пример #1
0
    def test_FISTA_catch_Lipschitz(self):
        print ("Test FISTA catch Lipschitz")
        ig = ImageGeometry(127,139,149)
        x_init = ImageData(geometry=ig)
        x_init = ig.allocate()
        b = x_init.copy()
        # fill with random numbers
        b.fill(numpy.random.random(x_init.shape))
        x_init = ig.allocate(ImageGeometry.RANDOM)
        identity = Identity(ig)
        
	    #### it seems FISTA does not work with Nowm2Sq
        norm2sq = LeastSquares(identity, b)
        print ('Lipschitz', norm2sq.L)
        norm2sq.L = None
        #norm2sq.L = 2 * norm2sq.c * identity.norm()**2
        #norm2sq = FunctionOperatorComposition(L2NormSquared(b=b), identity)
        opt = {'tol': 1e-4, 'memopt':False}
        print ("initial objective", norm2sq(x_init))
        try:
            alg = FISTA(x_init=x_init, f=norm2sq, g=ZeroFunction())
            self.assertTrue(False)
        except ValueError as ve:
            print (ve)
            self.assertTrue(True)
Пример #2
0
 def test_CGLS(self):
     print ("Test CGLS")
     ig = ImageGeometry(124,153,154)
     x_init = ImageData(geometry=ig)
     b = x_init.copy()
     # fill with random numbers
     b.fill(numpy.random.random(x_init.shape))
     
     identity = TomoIdentity(geometry=ig)
     
     alg = CGLS(x_init=x_init, operator=identity, data=b)
     alg.max_iteration = 1
     alg.run(20, verbose=True)
     self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())
Пример #3
0
 def test_GradientDescent(self):
     print ("Test GradientDescent")
     ig = ImageGeometry(12,13,14)
     x_init = ImageData(geometry=ig)
     b = x_init.copy()
     # fill with random numbers
     b.fill(numpy.random.random(x_init.shape))
     
     identity = TomoIdentity(geometry=ig)
     
     norm2sq = Norm2sq(identity, b)
     
     alg = GradientDescent(x_init=x_init, 
                           objective_function=norm2sq, 
                           rate=0.3)
     alg.max_iteration = 20
     alg.run(20, verbose=True)
     self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())
Пример #4
0
 def test_FISTA(self):
     print ("Test FISTA")
     ig = ImageGeometry(127,139,149)
     x_init = ImageData(geometry=ig)
     b = x_init.copy()
     # fill with random numbers
     b.fill(numpy.random.random(x_init.shape))
     x_init = ImageData(geometry=ig)
     x_init.fill(numpy.random.random(x_init.shape))
     
     identity = TomoIdentity(geometry=ig)
     
     norm2sq = Norm2sq(identity, b)
     opt = {'tol': 1e-4, 'memopt':False}
     alg = FISTA(x_init=x_init, f=norm2sq, g=None, opt=opt)
     alg.max_iteration = 2
     alg.run(20, verbose=True)
     self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())
     alg.run(20, verbose=True)
     self.assertNumpyArrayAlmostEqual(alg.x.as_array(), b.as_array())