qr.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:mathpy 作者: aschleg 项目源码 文件源码
def householder(self):
        r"""
        Implementation of Householder reflections method to performing QR
        decomposition.

        Returns
        -------
        qr : tuple
            Returns a tuple containing the orthogonal matrix Q and the upper-triangular
            matrix R resulting from QR decomposition.

        Notes
        -----
        The Householder reflection approach to QR decomposition is the more common approach
        due to its numerical stability compared to Gram-Schmidt and its relative speed to
        Givens rotations. The orthogonal matrix :math:`Q` is defined as successive Householder
        matrices :math:`H_1 \cdots H_n` while :math:`R` is upper triangular, defined as
        :math:`R = Q^T A`.

        Householder matrices :math:`H` are defined as:

        .. math::

            H = I - 2vv^T

        References
        ----------
        Golub, G., & Van Loan, C. (2013). Matrix computations (3rd ed.). Baltimore (MD): Johns Hopkins U.P.

        Householder transformation. (2017, March 19). In Wikipedia, The Free Encyclopedia.
            From https://en.wikipedia.org/w/index.php?title=Householder_transformation&oldid=771169379

        Trefethen, L., & Bau, D. (1997). Numerical linear algebra (1st ed.). Philadelphia: SIAM.

        """
        h = []
        r = self.x.copy()

        if self.m > self.n:
            c = self.n
        else:
            c = self.m

        for j in np.arange(c):
            hj = _householder_mat(r[j:self.m, j])
            if j > 0:
                hj = block_diag(np.eye(j), hj)

            r = np.dot(hj, r)
            h.append(hj)

        self.q = reduce(np.dot, reversed(h))[0:self.n].T
        r = np.array(r)[0:self.n]

        qr = (self.q, r)

        return qr
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号