def test_SymmetrisedGradientOperator2a(self): ########################################################################### # 2D geometry with channels # ig2 = ImageGeometry(N, M, channels = C) Grad2 = GradientOperator(self.ig2, correlation='Space') E2 = SymmetrisedGradientOperator(Grad2.range_geometry()) numpy.testing.assert_almost_equal(E2.norm(iterations=self.iterations), numpy.sqrt(8), decimal=self.decimal)
def test_SymmetrisedGradientOperator1a(self): ########################################################################### ## Symmetrized Gradient Tests print("Test SymmetrisedGradientOperator") ########################################################################### # 2D geometry no channels # ig = ImageGeometry(N, M) Grad = GradientOperator(self.ig) E1 = SymmetrisedGradientOperator(Grad.range_geometry()) numpy.testing.assert_almost_equal(E1.norm(iterations=self.iterations), numpy.sqrt(8), decimal=self.decimal)
def test_SymmetrisedGradientOperator3a(self): ########################################################################### # 3D geometry no channels #ig3 = ImageGeometry(N, M, K) Grad3 = GradientOperator(self.ig3, correlation='Space') E3 = SymmetrisedGradientOperator(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)
def test_SymmetrisedGradientOperator3a(self): ########################################################################### # 3D geometry no channels #ig3 = ImageGeometry(N, M, K) Grad3 = GradientOperator(self.ig3, correlation='Space') E3 = SymmetrisedGradientOperator(Grad3.range_geometry()) norm = LinearOperator.PowerMethod(E3, max_iteration=100, tolerance=0) numpy.testing.assert_almost_equal(norm, numpy.sqrt(12), decimal=self.decimal)
def test_SymmetrisedGradientOperator3b(self): ########################################################################### # 3D geometry no channels #ig3 = ImageGeometry(N, M, K) Grad3 = GradientOperator(self.ig3, correlation='Space') E3 = SymmetrisedGradientOperator(Grad3.range_geometry()) numpy.random.seed(1) u3 = E3.domain_geometry().allocate('random') w3 = E3.range_geometry().allocate('random', symmetry=True) # lhs3 = E3.direct(u3).dot(w3) rhs3 = u3.dot(E3.adjoint(w3)) # with numpy 1.11 and py 3.5 decimal = 3 decimal = 4 npv = version.parse(numpy.version.version) if npv.major == 1 and npv.minor == 11: print("########## SETTING decimal to 3 ###########") decimal = 3 numpy.testing.assert_almost_equal(lhs3, rhs3, decimal=decimal) # 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, decimal=decimal))
def stest_CompositionOperator_direct4(self): ig = self.ig data = self.data G = GradientOperator(domain_geometry=ig) sym = SymmetrisedGradientOperator(domain_geometry=ig) Id2 = IdentityOperator(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())
def test_SymmetrisedGradientOperator2(self): ########################################################################### # 2D geometry with channels # ig2 = ImageGeometry(N, M, channels = C) Grad2 = GradientOperator(self.ig2, correlation='Space') E2 = SymmetrisedGradientOperator(Grad2.range_geometry()) numpy.random.seed(1) u2 = E2.domain_geometry().allocate('random') w2 = E2.range_geometry().allocate('random', symmetry=True) # lhs2 = E2.direct(u2).dot(w2) rhs2 = u2.dot(E2.adjoint(w2)) numpy.testing.assert_allclose(lhs2, rhs2, rtol=1e-3)
def test_SymmetrisedGradientOperator1b(self): ########################################################################### ## Symmetrized GradientOperator Tests print("Test SymmetrisedGradientOperator") ########################################################################### # 2D geometry no channels # ig = ImageGeometry(N, M) Grad = GradientOperator(self.ig) E1 = SymmetrisedGradientOperator(Grad.range_geometry()) numpy.random.seed(1) u1 = E1.domain_geometry().allocate('random') w1 = E1.range_geometry().allocate('random', symmetry=True) lhs = E1.direct(u1).dot(w1) rhs = u1.dot(E1.adjoint(w1)) print("lhs {} rhs {}".format(lhs, rhs)) # self.assertAlmostEqual(lhs, rhs) numpy.testing.assert_allclose(lhs, rhs, rtol=1e-3)
def test_SymmetrisedGradientOperator3b(self): ########################################################################### # 3D geometry no channels #ig3 = ImageGeometry(N, M, K) Grad3 = GradientOperator(self.ig3, correlation='Space') E3 = SymmetrisedGradientOperator(Grad3.range_geometry()) numpy.random.seed(1) u3 = E3.domain_geometry().allocate('random') w3 = E3.range_geometry().allocate('random', symmetry=True) # lhs3 = E3.direct(u3).dot(w3) rhs3 = u3.dot(E3.adjoint(w3)) numpy.testing.assert_almost_equal(lhs3, rhs3, decimal=3) 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, decimal=3))
z1 = B.direct(u) res = B.range_geometry().allocate() B.direct(u, out=res) ########################################################################### # Block Operator for TGV reconstruction M, N = 2, 3 ig = ImageGeometry(M, N) ag = ig op11 = GradientOperator(ig) op12 = IdentityOperator(op11.range_geometry()) op22 = SymmetrisedGradientOperator(op11.domain_geometry()) op21 = ZeroOperator(ig, op22.range_geometry()) op31 = IdentityOperator(ig, ag) op32 = ZeroOperator(op22.domain_geometry(), ag) operator = BlockOperator(op11, -1 * op12, op21, op22, op31, op32, shape=(3, 2)) z1 = operator.domain_geometry()