Пример #1
0
    def test_solve_proj_sadpnt_smw(self):
        """check the sadpnt as projection"""

        n = self.n

        # check whether it is a projection
        AuvInvZ = lau.solve_sadpnt_smw(amat=self.A,
                                       jmat=self.J,
                                       rhsv=self.Z,
                                       jmatT=self.Jt,
                                       umat=self.U,
                                       vmat=self.V)

        auvAUVinv = self.A * AuvInvZ[:n, :] - \
            lau.comp_uvz_spdns(self.U, self.V, AuvInvZ[:n, :])

        AuvInv2Z = lau.solve_sadpnt_smw(amat=self.A,
                                        jmat=self.J,
                                        rhsv=auvAUVinv,
                                        jmatT=self.Jt,
                                        umat=self.U,
                                        vmat=self.V)

        self.assertTrue(np.allclose(AuvInvZ[:n, :], AuvInv2Z[:n, :]),
                        msg='likely to fail because of ill cond')

        prjz = lau.app_prj_via_sadpnt(amat=self.A,
                                      jmat=self.J,
                                      rhsv=self.Z,
                                      jmatT=self.Jt)
        prprjz = lau.app_prj_via_sadpnt(amat=self.A,
                                        jmat=self.J,
                                        rhsv=self.Z,
                                        jmatT=self.Jt)

        # check projector
        self.assertTrue(np.allclose(prprjz, prjz))

        # onto kernel J
        self.assertTrue(np.linalg.norm(prjz) > 1e-8)
        self.assertTrue(
            np.linalg.norm(self.J * prjz) / np.linalg.norm(prjz) < 1e-6)

        # check transpose
        idmat = np.eye(n)
        prj = lau.app_prj_via_sadpnt(amat=self.A,
                                     jmat=self.J,
                                     rhsv=idmat,
                                     jmatT=self.Jt)

        prjT = lau.app_prj_via_sadpnt(amat=self.A,
                                      jmat=self.J,
                                      rhsv=idmat,
                                      jmatT=self.Jt,
                                      transposedprj=True)

        self.assertTrue(np.allclose(prj, prjT.T))
Пример #2
0
    def test_sadpnt_smw_krypy(self):
        """check the sadpnt solver with krypy"""

        umat, vmat, k, = self.U, self.V, self.k

        # self.Jt = self.J.T
        # check the formula
        AuvInvZ = lau.solve_sadpnt_smw(amat=self.A, jmat=self.J, rhsv=self.Z,
                                       jmatT=self.Jt, umat=self.U, vmat=self.V,
                                       krylov=True, krpslvprms=self.krpslvprms)

        sysm1 = sps.hstack([self.A, self.Jt], format='csr')
        sysm2 = sps.hstack([self.J, sps.csr_matrix((k, k))], format='csr')
        mata = sps.vstack([sysm1, sysm2], format='csr')

        umate = np.vstack([umat, np.zeros((k, umat.shape[1]))])
        vmate = np.hstack([vmat, np.zeros((vmat.shape[0], k))])
        ze = np.vstack([self.Z, np.zeros((k, self.Z.shape[1]))])

        AAinvZ = mata * AuvInvZ - np.dot(umate, np.dot(vmate, AuvInvZ))

        # likely to fail because of ill conditioned rand mats
        print np.linalg.norm(AAinvZ - ze)
        self.assertTrue(np.allclose(AAinvZ, ze),
                        msg='likely to fail because of ill cond')
Пример #3
0
    def test_sadpnt_smw(self):
        """check the sadpnt solver"""

        umat, vmat, k, = self.U, self.V, self.k

        # self.Jt = self.J.T
        # check the formula
        AuvInvZ = lau.solve_sadpnt_smw(amat=self.A,
                                       jmat=self.J,
                                       rhsv=self.Z,
                                       jmatT=self.Jt,
                                       umat=self.U,
                                       vmat=self.V)

        sysm1 = sps.hstack([self.A, self.Jt], format='csr')
        sysm2 = sps.hstack([self.J, sps.csr_matrix((k, k))], format='csr')
        mata = sps.vstack([sysm1, sysm2], format='csr')

        umate = np.vstack([umat, np.zeros((k, umat.shape[1]))])
        vmate = np.hstack([vmat, np.zeros((vmat.shape[0], k))])
        ze = np.vstack([self.Z, np.zeros((k, self.Z.shape[1]))])

        AAinvZ = mata * AuvInvZ - np.dot(umate, np.dot(vmate, AuvInvZ))

        # likely to fail because of ill conditioned rand mats
        self.assertTrue(np.allclose(AAinvZ, ze),
                        msg='likely to fail because of ill cond')
Пример #4
0
    def test_solve_proj_sadpnt_smw(self):
        """check the sadpnt as projection"""

        n = self.n

        # check whether it is a projection
        AuvInvZ = lau.solve_sadpnt_smw(amat=self.A, jmat=self.J, rhsv=self.Z,
                                       jmatT=self.Jt, umat=self.U, vmat=self.V)

        auvAUVinv = self.A * AuvInvZ[:n, :] - \
            lau.comp_uvz_spdns(self.U, self.V, AuvInvZ[:n, :])

        AuvInv2Z = lau.solve_sadpnt_smw(amat=self.A, jmat=self.J,
                                        rhsv=auvAUVinv,
                                        jmatT=self.Jt,
                                        umat=self.U, vmat=self.V)

        self.assertTrue(np.allclose(AuvInvZ[:n, :], AuvInv2Z[:n, :]),
                        msg='likely to fail because of ill cond')

        prjz = lau.app_prj_via_sadpnt(amat=self.A, jmat=self.J,
                                      rhsv=self.Z, jmatT=self.Jt)
        prprjz = lau.app_prj_via_sadpnt(amat=self.A, jmat=self.J,
                                        rhsv=self.Z, jmatT=self.Jt)

        # check projector
        self.assertTrue(np.allclose(prprjz, prjz))

        # onto kernel J
        self.assertTrue(np.linalg.norm(prjz) > 1e-8)
        self.assertTrue(np.linalg.norm(self.J*prjz)/np.linalg.norm(prjz)
                        < 1e-6)

        # check transpose
        idmat = np.eye(n)
        prj = lau.app_prj_via_sadpnt(amat=self.A, jmat=self.J,
                                     rhsv=idmat, jmatT=self.Jt)

        prjT = lau.app_prj_via_sadpnt(amat=self.A, jmat=self.J,
                                      rhsv=idmat, jmatT=self.Jt,
                                      transposedprj=True)

        self.assertTrue(np.allclose(prj, prjT.T))
Пример #5
0
def solve_stst_feedbacknthrough(amat=None, mmat=None, jmat=None,
                                bmat=None, cmat=None,
                                fv=None, fl=None, fg=None, fl2=None,
                                nwtn_adi_dict=dict(adi_max_steps=150,
                                                   adi_newZ_reltol=1e-5,
                                                   nwtn_max_steps=14,
                                                   nwtn_upd_reltol=1e-8)):
    """solve for the stabilizing feedback gain and the feedthrough

    for the linear time invariant case"""

    Z = proj_alg_ric_newtonadi(mmat=mmat, amat=amat, jmat=jmat,
                               bmat=bmat, wmat=cmat,
                               nwtn_adi_dict=nwtn_adi_dict)

    mtxb = get_mTzzTtb(mmat.T, Z, bmat)
    mtxfv = get_mTzzTtb(mmat.T, Z, fv)

    wft = lau.solve_sadpnt_smw(amat=-amat.T, jmat=jmat, rhsv=fl-mtxfv,
                               umat=-mtxb, vmat=bmat.T)

    return Z, wft