Exemplo n.º 1
0
    def test_compress_algric_Z(self):
        Z = pru.proj_alg_ric_newtonadi(mmat=self.M, amat=self.F,
                                       jmat=self.J, bmat=self.bmat,
                                       wmat=self.W, z0=self.bmat,
                                       nwtn_adi_dict=
                                       self.nwtn_adi_dict)['zfac']

        Zred = pru.compress_Zsvd(Z, thresh=self.comprthresh)

        print '\ncompressing Z from {0} to {1} columns:'.\
            format(Z.shape[1], Zred.shape[1])

        difn, zzn, zzrn = \
            lau.comp_sqfnrm_factrd_diff(Z, Zred, ret_sing_norms=True)

        print '\n || ZZ - ZZred||_F || / ||ZZ|| = {0}\n'.\
            format(np.sqrt(difn/zzn))

        vec = np.random.randn(Z.shape[0], 1)

        print '||(ZZ_red - ZZ )*testvec|| / ||ZZ*testvec|| = {0}'.\
            format(np.linalg.norm(np.dot(Z, np.dot(Z.T, vec)) -
                   np.dot(Zred, np.dot(Zred.T, vec))) /
                   np.linalg.norm(np.dot(Zred, np.dot(Zred.T, vec))))

        self.assertTrue(True)
Exemplo n.º 2
0
    def test_compress_algric_Z(self):
        Z = pru.proj_alg_ric_newtonadi(
            mmat=self.M,
            amat=self.F,
            jmat=self.J,
            bmat=self.bmat,
            wmat=self.W,
            z0=self.bmat,
            nwtn_adi_dict=self.nwtn_adi_dict)['zfac']

        Zred = pru.compress_Zsvd(Z, thresh=self.comprthresh)

        print '\ncompressing Z from {0} to {1} columns:'.\
            format(Z.shape[1], Zred.shape[1])

        difn, zzn, zzrn = \
            lau.comp_sqfnrm_factrd_diff(Z, Zred, ret_sing_norms=True)

        print '\n || ZZ - ZZred||_F || / ||ZZ|| = {0}\n'.\
            format(np.sqrt(difn/zzn))

        vec = np.random.randn(Z.shape[0], 1)

        print '||(ZZ_red - ZZ )*testvec|| / ||ZZ*testvec|| = {0}'.\
            format(np.linalg.norm(np.dot(Z, np.dot(Z.T, vec)) -
                   np.dot(Zred, np.dot(Zred.T, vec))) /
                   np.linalg.norm(np.dot(Zred, np.dot(Zred.T, vec))))

        self.assertTrue(True)
Exemplo n.º 3
0
    def test_proj_alg_ric_sol(self):
        """check the sol of the projected alg. Riccati Eqn

        via Newton ADI"""
        Z = pru.proj_alg_ric_newtonadi(
            mmat=self.M,
            amat=self.F,
            jmat=self.J,
            bmat=self.bmat,
            wmat=self.W,
            z0=self.bmat,
            nwtn_adi_dict=self.nwtn_adi_dict)['zfac']

        # for '0' initial value --> z0 = None
        Z0 = pru.proj_alg_ric_newtonadi(
            mmat=self.M,
            amat=self.F,
            jmat=self.J,
            bmat=self.bmat,
            wmat=self.W,
            nwtn_adi_dict=self.nwtn_adi_dict)['zfac']

        MtXM = self.M.T * np.dot(Z, Z.T) * self.M
        MtX0M = self.M.T * np.dot(Z0, Z0.T) * self.M

        self.assertTrue(np.allclose(MtXM, MtX0M))

        MtXb = self.M.T * np.dot(np.dot(Z, Z.T), self.bmat)

        FtXM = self.F.T * np.dot(Z, Z.T) * self.M
        PtW = np.dot(self.P.T, self.W)

        ProjRes = np.dot(self.P.T, np.dot(FtXM, self.P)) + \
            np.dot(np.dot(self.P.T, FtXM.T), self.P) -\
            np.dot(MtXb, MtXb.T) + \
            np.dot(PtW, PtW.T)

        # TEST: result is 'projected' - riccati sol
        self.assertTrue(
            np.allclose(MtXM, np.dot(self.P.T, np.dot(MtXM, self.P))))

        # TEST: check projected residual - riccati sol
        print np.linalg.norm(ProjRes) / np.linalg.norm(MtXM)

        self.assertTrue(np.linalg.norm(ProjRes) / np.linalg.norm(MtXM) < 1e-7)
Exemplo n.º 4
0
    def test_proj_alg_ric_sol(self):
        """check the sol of the projected alg. Riccati Eqn

        via Newton ADI"""
        Z = pru.proj_alg_ric_newtonadi(mmat=self.M, amat=self.F,
                                       jmat=self.J, bmat=self.bmat,
                                       wmat=self.W, z0=self.bmat,
                                       nwtn_adi_dict=
                                       self.nwtn_adi_dict)['zfac']

        # for '0' initial value --> z0 = None
        Z0 = pru.proj_alg_ric_newtonadi(mmat=self.M, amat=self.F,
                                        jmat=self.J, bmat=self.bmat,
                                        wmat=self.W,
                                        nwtn_adi_dict=
                                        self.nwtn_adi_dict)['zfac']

        MtXM = self.M.T * np.dot(Z, Z.T) * self.M
        MtX0M = self.M.T * np.dot(Z0, Z0.T) * self.M

        self.assertTrue(np.allclose(MtXM, MtX0M))

        MtXb = self.M.T * np.dot(np.dot(Z, Z.T), self.bmat)

        FtXM = self.F.T * np.dot(Z, Z.T) * self.M
        PtW = np.dot(self.P.T, self.W)

        ProjRes = np.dot(self.P.T, np.dot(FtXM, self.P)) + \
            np.dot(np.dot(self.P.T, FtXM.T), self.P) -\
            np.dot(MtXb, MtXb.T) + \
            np.dot(PtW, PtW.T)

# TEST: result is 'projected' - riccati sol
        self.assertTrue(np.allclose(MtXM,
                                    np.dot(self.P.T, np.dot(MtXM, self.P))))

# TEST: check projected residual - riccati sol
        print np.linalg.norm(ProjRes) / np.linalg.norm(MtXM)

        self.assertTrue(np.linalg.norm(ProjRes) / np.linalg.norm(MtXM)
                        < 1e-7)