예제 #1
0
def main():
    """Solve standard/generalized Riccati equation."""

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

    #create opt instance
    opt1 = Options()
    opt1.nm.output = 1
    opt1.adi.output = 0
    opt1.nm.res2_tol = 1e-4
    opt2 = Options()
    opt2.nm.output = 1
    opt2.adi.output = 0
    opt2.nm.res2_tol = 1e-4

    # create standard and generalized equation
    eqn1 = EquationGRiccati(opt1, a, None, b, c)
    eqn2 = EquationGRiccati(opt2, a, e, b, c)

    # solve both equations
    z1, stat1 = lrnm(eqn1, opt1)
    z2, stat2 = lrnm(eqn2, opt2)

    print("Standard Riccati Equation \n")
    print("Size of Low Rank Solution Factor Z1: %d x %d \n"%(z1.shape))
    print(stat1.lrnm_stat())
    print(stat1)
    print("Generalized Riccati Equation \n")
    print("Size of Low Rank Solution Factor Z2: %d x %d \n"%(z2.shape))
    print(stat2.lrnm_stat())
    print(stat2)
예제 #2
0
def main():
    """Solve standard/generalized Lyapunov equation."""

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

    # create opt instances
    opt1 = Options()
    opt1.adi.output = 0
    opt1.adi.res2_tol = 1e-6
    print(opt1)
    opt2 = Options()
    opt2.adi.output = 0
    opt2.adi.res2_tol = 1e-6
    print(opt2)

    # create standard and generalized equation
    eqn1 = EquationGLyap(opt1, a, None, b)
    eqn2 = EquationGLyap(opt2, a, e, b)

    # solve both equations
    z1, stat1 = lradi(eqn1, opt1)
    z2, stat2 = lradi(eqn2, opt2)

    print("Standard Lyapunov Equation \n")
    print("Size of Low Rank Solution Factor Z1: %d x %d \n" % (z1.shape))
    print(stat1)
    print("Generalized Lyapunov Equation \n")
    print("Size of Low Rank Solution Factor Z2: %d x %d \n" % (z2.shape))
    print(stat2)
예제 #3
0
def main():
    """Solve Lyapunov Equation SO1 System."""

    # read data
    m = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/M_301.mtx").tocsr()
    d = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/D_301.mtx").tocsr()
    k = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/K_301.mtx").tocsr()

    # generate rhs
    b = np.ones((2 * m.shape[0], 1), dtype=np.double)

    # bounds for shift parameters
    lowerbound = 1e-8
    upperbound = 1e+8

    # create options instance
    opt = Options()
    opt.adi.output = 0
    opt.adi.res2_tol = 1e-7
    opt.type = MESS_OP_NONE

    # create equation
    eqn = EquationGLyapSO1(opt, m, d, k, b, lowerbound, upperbound)

    # solve equation
    z, status = lradi(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" % (it, res2 / res2_0, res2))
    print("Size of Low Rank Solution Factor Z: %d x %d \n"%(z.shape))
    print(status)
예제 #4
0
def main():
    """Solve Lyapunov Equation DAE1 System."""

    # read data
    e11 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/E11.mtx").tocsr()
    a11 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A11.mtx").tocsr()
    a12 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A12.mtx").tocsr()
    a21 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A21.mtx").tocsr()
    a22 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A22.mtx").tocsr()
    b = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/B.mtx").todense()
    b = b / norm(b)

    #create opt instance
    opt = Options()
    opt.adi.output = 0
    opt.nm.output = 0
    opt.adi.res2_tol = 1e-10
    print(opt)

    # create equation
    eqn = EquationGLyapDAE1(opt, e11, a11, a12, a21, a22, b)

    # solve equation
    z, status = lradi(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("Size of Low Rank Solution Factor Z: %d x %d \n" % (z.shape))
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" %
          (it, res2 / res2_0, res2))
    print(status)
예제 #5
0
def main():
    """Solve Lyapunov Equation for DAE2 System."""

    # read data
    m = mmread(
        "@CMAKE_SOURCE_DIR@/tests/data/NSE/NSE_RE_100_lvl1_M.mtx").tocsr()
    a = mmread(
        "@CMAKE_SOURCE_DIR@/tests/data/NSE/NSE_RE_100_lvl1_A.mtx").tocsr()
    g = mmread(
        "@CMAKE_SOURCE_DIR@/tests/data/NSE/NSE_RE_100_lvl1_G.mtx").tocsr()
    b = mmread("@CMAKE_SOURCE_DIR@/tests/data/NSE/NSE_RE_100_lvl1_B.mtx")
    delta = -0.02

    #create opt instance
    opt = Options()
    opt.adi.output = 0
    opt.nm.output = 0
    opt.adi.res2_tol = 1e-5
    opt.adi.paratype = MESS_LRCFADI_PARA_ADAPTIVE_V
    print(opt)

    # create equation
    eqn = EquationGLyapDAE2(opt, m, a, g, b, delta, None)

    # solve equation
    z, status = lradi(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("Size of Low Rank Solution Factor Z: %d x %d \n" % (z.shape))
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" %
          (it, res2 / res2_0, res2))
    print(status)
예제 #6
0
파일: ww_dae1.py 프로젝트: mpimd-csc/cmess
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.res2_tol = 1e-10
     self.opt.adi.maxit = 1000
     self.opt.adi.output = 0
     self.opt.nm.output = 0
예제 #7
0
파일: riccati.py 프로젝트: mpimd-csc/cmess
 def setUp(self):
     """is called before every test function"""
     self.a = mmread(self.amtx).tocsr()
     self.b = mmread(self.bmtx)
     self.c = mmread(self.cmtx)
     self.e = mmread(self.emtx).tocsr()
     self.opt = Options()
     self.opt.type = MESS_OP_TRANSPOSE
예제 #8
0
파일: nse_dae2.py 프로젝트: mpimd-csc/cmess
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.res2_tol = 5e-8
     self.opt.adi.output = 0
     self.opt.nm.output = 0
     self.opt.adi.shifts.paratype = MESS_LRCFADI_PARA_ADAPTIVE_V
     self.delta = -0.02
예제 #9
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))
예제 #10
0
파일: filter.py 프로젝트: mpimd-csc/cmess
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.output = 0
     self.opt.nm.output = 0
     self.opt.adi.res2_tol = 1e-10
     self.a = mmread(self.amtx).tocsr()
     self.b = mmread(self.bmtx).todense()
     self.e = mmread(self.emtx).tocsr()
예제 #11
0
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.res2_tol = 1e-6
     self.opt.nm.res2_tol = 5e-1
     self.opt.nm.maxit = 30
     self.opt.adi.output = 0
     self.opt.nm.output = 0
     self.delta = -0.02
예제 #12
0
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.res2_tol = 1e-7
     self.opt.nm.res2_tol = 1e-2
     self.opt.adi.output = 0
     self.opt.nm.output = 0
     self.lowerbound = 1e-8
     self.upperbound = 1e+8
     self.m = mmread(self.mmtx).tocsr()
     self.d = mmread(self.dmtx).tocsr()
     self.k = mmread(self.kmtx).tocsr()
예제 #13
0
 def setUp(self):
     """is called before every test function"""
     self.opt = Options()
     self.opt.adi.res2_tol = 1e-8
     self.opt.adi.output = 0
     self.opt.nm.output = 0
     self.opt.adi.shifts.paratype = MESS_LRCFADI_PARA_MINMAX
     self.lowerbound = 1e-8
     self.upperbound = 1e+8
     self.m = mmread(self.mmtx).tocsr()
     self.d = mmread(self.dmtx).tocsr()
     self.k = mmread(self.kmtx).tocsr()
예제 #14
0
def main():
    """Solve Riccati Equation SO1 System equation."""

    # read data
    m = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/M_301.mtx").tocsr()
    d = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/D_301.mtx").tocsr()
    k = mmread("@CMAKE_SOURCE_DIR@/tests/data/TripleChain/K_301.mtx").tocsr()

    # generate rhs
    b = np.ones((2 * m.shape[0], 1), dtype=np.double)
    c = np.ones((1, m.shape[0]), dtype=np.double)

    # bounds for shift parameters
    lowerbound = 1e-8
    upperbound = 1e+8

    # create options instance
    opt = Options()
    opt.adi.output = 0
    opt.nm.output = 0
    opt.nm.res2_tol = 1e-6
    opt.adi.res2_tol = 1e-10
    opt.adi.maxit = 1000
    opt.type = MESS_OP_NONE
    opt.adi.shifts.paratype = MESS_LRCFADI_PARA_MINMAX

    # create equation
    eqn = EquationGRiccatiSO1(opt, m, d, k, b, c, lowerbound, upperbound)

    # solve equation
    z, status = lrnm(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" %
          (it, res2 / res2_0, res2))
    print("Size of Low Rank Solution Factor Z: %d x %d \n" % (z.shape))
    print(status.lrnm_stat())
예제 #15
0
def main():
    """Solve Riccati Equation DAE1 System."""

    # read data
    e11 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/E11.mtx").tocsr()
    a11 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A11.mtx").tocsr()
    a12 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A12.mtx").tocsr()
    a21 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A21.mtx").tocsr()
    a22 = mmread("@CMAKE_SOURCE_DIR@/tests/data/bips98_606/A22.mtx").tocsr()

    #create opt instance
    opt = Options()
    opt.adi.output = 0
    opt.nm.output = 0
    opt.nm.res2_tol = 1e-10

    # generate some matrices b and c
    seed(1111)
    if opt.type == MESS_OP_TRANSPOSE:
        b = rand(e11.shape[0], 2)
        c = rand(2, e11.shape[1] + a22.shape[1])
    else:
        b = rand(e11.shape[0] + a22.shape[0], 2)
        c = rand(2, e11.shape[1])

    b = b / norm(b, 'fro')
    c = c / norm(c, 'fro')

    # create equation
    eqn = EquationGRiccatiDAE1(opt, e11, a11, a12, a21, a22, b, c)

    # solve equation
    z, status = lrnm(eqn, opt)

    # get residual
    res2 = status.res2_norm
    res2_0 = status.res2_0
    it = status.it
    print("Size of Low Rank Solution Factor Z: %d x %d \n" % (z.shape))
    print("it = %d \t rel_res2 = %e\t res2 = %e \n" %
          (it, res2 / res2_0, res2))
    print(status.lrnm_stat())