Esempio n. 1
0
    def template_riccati(self, rhs, para):
        """template to reduce code in the test cases"""
        #set some options
        self.opt.adi.output = 0
        self.opt.adi.res2_tol = 1e-10
        self.opt.nm.output = 0
        self.opt.nm.res2_tol = 1e-3

        # setup equation
        if para < 0:
            eqn = MyEquation2(self.opt, self.a, self.e, rhs, self.b, self.c)
            z, status = lrnm(eqn, self.opt)
        else:
            eqn2 = MyEquation(self.opt, self.a, self.e, rhs, self.b, self.c)
            self.opt.adi.shifts.paratype = para
            z, status = lrnm(eqn2, self.opt)

        #get res2 from lrnm
        res2 = status.res2_norm
        res2_0 = status.res2_0
        it = status.it
        print("it=%d\t rel_res2=%e\t res2=%e\t tol=%e\n" %
              (it, res2 / res2_0, res2, self.opt.nm.res2_tol))
        self.assertLessEqual(res2 / res2_0, self.opt.nm.res2_tol)

        #check norm
        nrmr, nrmrhs, relnrm = res2_ric(self.a, self.e, self.b, self.c, z,
                                        self.opt.type)
        print("check:\t rel_res2=%e\t res2=%e\t nrmrhs=%e\n" %
              (relnrm, nrmr, nrmrhs))
        # compare residual, should be roughly the same magnitude
        self.assertLessEqual(abs(log10(relnrm) - log10(res2 / res2_0)), 1)
Esempio n. 2
0
def main():
    """Demonstrate Callback functionality"""

    # read data
    a = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/A.mtx')
    b = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/B.mtx')
    c = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/C.mtx')
    e = mmread('@CMAKE_SOURCE_DIR@/tests/data/Rail/E.mtx')

    # create options
    opt = Options()
    opt.nm.output = 0
    opt.adi.output = 0

    # create instance of MyEquation and solve
    opt.type = MESS_OP_NONE
    eqn1 = MyEquation(opt, a, e, b, c)
    z1, stat1 = lrnm(eqn1, opt)

    # create instance of MyEquation and solve
    opt.type = MESS_OP_TRANSPOSE
    eqn2 = MyEquation(opt, a, e, b, c)
    z2, stat2 = lrnm(eqn2, opt)

    # print information and compute residual again to make sure that we have everything correct
    print("\n")
    print("MyEquation: eqn1")
    print("Size of Low Rank Solution Factor Z1: %d x %d \n" % (z1.shape))
    print(stat1.lrnm_stat())
    nrmr1, nrmrhs1, relnrm1 = res2_ric(a, e, b, c, z1, MESS_OP_NONE)
    print("check for eqn1:\t rel_res2=%e\t res2=%e\t nrmrhs=%e\n" %
          (relnrm1, nrmr1, nrmrhs1))

    print("\n")
    print(
        "--------------------------------------------------------------------------------------"
    )
    print("\n")

    # print information and compute residual again to make sure that we have everything correct
    print("MyEquation: eqn2")
    print("Size of Low Rank Solution Factor Z2: %d x %d \n" % (z2.shape))
    print(stat2.lrnm_stat())
    nrmr2, nrmrhs2, relnrm2 = res2_ric(a, e, b, c, z2, MESS_OP_TRANSPOSE)
    print("check for eqn1:\t rel_res2=%e\t res2=%e\t nrmrhs=%e\n" %
          (relnrm2, nrmr2, nrmrhs2))
Esempio n. 3
0
 def template_iss(self):
     """template to reduce code in the test cases"""
     a = mmread(self.amtx_iss).todense()
     b = mmread(self.bmtx_iss).todense()
     e = mmread(self.emtx_iss).todense()
     c = mmread(self.cmtx_iss).todense()
     z = pymess.care(a, e, b, c)
     nrmr, nrmrhs, relnrm = res2_ric(a, e, b, c, z, MESS_OP_TRANSPOSE)
     print("res2 = {0:e}\t rel = {1:e}\t res2/rel = {2:e}".format(
         nrmr, nrmrhs, relnrm))
     self.assertLessEqual(relnrm, self.tol)
Esempio n. 4
0
def main():
    """Solve standard/generalized Riccati equation."""

    # read data
    a = mmread("@CMAKE_SOURCE_DIR@/tests/data/filter2D/filter2D.A")
    e = mmread("@CMAKE_SOURCE_DIR@/tests/data/filter2D/filter2D.E")
    b = mmread("@CMAKE_SOURCE_DIR@/tests/data/filter2D/filter2D.B").todense()
    c = mmread("@CMAKE_SOURCE_DIR@/tests/data/filter2D/filter2D.C").todense()

    # standard
    z = care(a, None, b, c)

    # compute residual
    _, _, rel = res2_ric(a, None, b, c, z, MESS_OP_TRANSPOSE)
    print("standard rel. resisudal=", rel)

    # generalized
    z = care(a, e, b, c)

    # compute residual
    _, _, rel = res2_ric(a, e, b, c, z, MESS_OP_TRANSPOSE)
    print("generalized rel. resisdual=", rel)
Esempio n. 5
0
    def template_care(self, hase, mf1, mf2):
        """template to reduce code in the test cases"""
        a = mf1(mmread(self.amtx_rail).tocsr())
        b = mmread(self.bmtx_rail).todense()
        e = mf2(mmread(self.emtx_rail).tocsr()) if hase else None
        c = mmread(self.cmtx_rail).todense()
        #if e is not None:
        #    print("a={0:s} e={1:s} b={2:s} c={3:s}".format(type(a), type(e), type(b), type(c)))
        #else:
        #    print("a={0:s} b={1:s} c={2:s}".format(type(a), type(b), type(c)))

        z = pymess.care(a, e, b, c)
        nrmr, nrmrhs, relnrm = res2_ric(a, e, b, c, z, MESS_OP_TRANSPOSE)
        print("res2 = {0:e}\t rel = {1:e}\t res2/rel = {2:e}".format(
            nrmr, nrmrhs, relnrm))
        self.assertLessEqual(relnrm, self.tol)