Esempio n. 1
0
 def test_SymmetrizedGradient2a(self):        
     ###########################################################################
     # 2D geometry with channels
     # ig2 = ImageGeometry(N, M, channels = C)
     Grad2 = Gradient(self.ig2, correlation = 'Space')
     
     E2 = SymmetrizedGradient(Grad2.range_geometry())
     numpy.testing.assert_almost_equal(E2.norm(iterations=self.iterations), 
        numpy.sqrt(8), decimal = self.decimal)
Esempio n. 2
0
 def test_SymmetrizedGradient1a(self):
     ###########################################################################  
     ## Symmetrized Gradient Tests
     print ("Test SymmetrizedGradient")
     ###########################################################################
     # 2D geometry no channels
     # ig = ImageGeometry(N, M)
     Grad = Gradient(self.ig)
     
     E1 = SymmetrizedGradient(Grad.range_geometry())
     numpy.testing.assert_almost_equal(E1.norm(iterations=self.iterations), numpy.sqrt(8), decimal = self.decimal)
Esempio n. 3
0
    def test_SymmetrizedGradient3a(self):
        ###########################################################################
        # 3D geometry no channels
        #ig3 = ImageGeometry(N, M, K)
        Grad3 = Gradient(self.ig3, correlation = 'Space')
        
        E3 = SymmetrizedGradient(Grad3.range_geometry())

        norm1 = E3.norm()
        norm2 = E3.calculate_norm(iterations=100)
        print (norm1,norm2)
        numpy.testing.assert_almost_equal(norm2, numpy.sqrt(12), decimal = self.decimal)
Esempio n. 4
0
    def stest_CompositionOperator_direct4(self):
        ig = self.ig
        data = self.data
        G = Gradient(domain_geometry=ig)
        

        sym = SymmetrizedGradient(domain_geometry=ig)
        Id2 = Identity(ig)
        
        d = CompositionOperator(sym, Id2)

        out1 = G.direct(data)
        out2 = d.direct(data)


        numpy.testing.assert_array_almost_equal(out2.get_item(0).as_array(),  out1.get_item(0).as_array())
        numpy.testing.assert_array_almost_equal(out2.get_item(1).as_array(),  out1.get_item(1).as_array())
Esempio n. 5
0
 def test_SymmetrizedGradient2(self):        
     ###########################################################################
     # 2D geometry with channels
     # ig2 = ImageGeometry(N, M, channels = C)
     Grad2 = Gradient(self.ig2, correlation = 'Space')
     
     E2 = SymmetrizedGradient(Grad2.range_geometry())
     
     u2 = E2.domain_geometry().allocate('random_int')
     w2 = E2.range_geometry().allocate('random_int', symmetry = True)
 #    
     lhs2 = E2.direct(u2).dot(w2)
     rhs2 = u2.dot(E2.adjoint(w2))
         
     numpy.testing.assert_almost_equal(lhs2, rhs2)
Esempio n. 6
0
 def test_SymmetrizedGradient3b(self):
     ###########################################################################
     # 3D geometry no channels
     #ig3 = ImageGeometry(N, M, K)
     Grad3 = Gradient(self.ig3, correlation = 'Space')
     
     E3 = SymmetrizedGradient(Grad3.range_geometry())
     
     u3 = E3.domain_geometry().allocate('random_int')
     w3 = E3.range_geometry().allocate('random_int', symmetry = True)
 #    
     lhs3 = E3.direct(u3).dot(w3)
     rhs3 = u3.dot(E3.adjoint(w3))
     numpy.testing.assert_almost_equal(lhs3, rhs3)  
     self.assertAlmostEqual(lhs3, rhs3)
     print (lhs3, rhs3, abs((rhs3-lhs3)/rhs3) , 1.5 * 10**(-4), abs((rhs3-lhs3)/rhs3) < 1.5 * 10**(-4))
     self.assertTrue( LinearOperator.dot_test(E3, range_init = w3, domain_init=u3) )
Esempio n. 7
0
 def test_SymmetrizedGradient1b(self):
     ###########################################################################  
     ## Symmetrized Gradient Tests
     print ("Test SymmetrizedGradient")
     ###########################################################################
     # 2D geometry no channels
     # ig = ImageGeometry(N, M)
     Grad = Gradient(self.ig)
     
     E1 = SymmetrizedGradient(Grad.range_geometry())
     u1 = E1.domain_geometry().allocate('random_int')
     w1 = E1.range_geometry().allocate('random_int', symmetry = True)
     
     
     lhs = E1.direct(u1).dot(w1)
     rhs = u1.dot(E1.adjoint(w1))
     # self.assertAlmostEqual(lhs, rhs)
     numpy.testing.assert_almost_equal(lhs, rhs)
# Fidelity
if noise == 's&p':
    f3 = L1Norm(b=noisy_data)
elif noise == 'poisson':
    f3 = KullbackLeibler(noisy_data)
elif noise == 'gaussian':
    f3 = 0.5 * L2NormSquared(b=noisy_data)

if method == '0':

    # Create operators
    op11 = Gradient(ig)
    op12 = Identity(op11.range_geometry())

    op22 = SymmetrizedGradient(op11.domain_geometry())
    op21 = ZeroOperator(ig, op22.range_geometry())

    op31 = Identity(ig, ag)
    op32 = ZeroOperator(op22.domain_geometry(), ag)

    operator = BlockOperator(op11,
                             -1 * op12,
                             op21,
                             op22,
                             op31,
                             op32,
                             shape=(3, 2))

    f1 = alpha * MixedL21Norm()
    f2 = beta * MixedL21Norm()