fd.py 文件源码

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

项目:anompy 作者: takuti 项目源码 文件源码
def update(self, Y):
        """Alg. 3: Randomized streaming update of the singular vectors at time t.

        Args:
            Y (numpy array): m-by-n_t matrix which has n_t "normal" unit vectors.

        """

        if not hasattr(self, 'E'):
            # initial sketch
            M = np.empty_like(Y)
            M[:] = Y[:]
        else:
            # combine current sketched matrix with input at time t
            # D: m-by-(n+ell-1) matrix
            M = np.concatenate((self.E[:, :-1], Y), axis=1)

        G = np.random.normal(0., 0.1, (self.m, 100 * self.ell))
        MM = np.dot(M, M.T)
        Q, R = ln.qr(np.dot(MM, G))

        # eig() returns eigen values/vectors with unsorted order
        s, A = ln.eig(np.dot(np.dot(Q.T, MM), Q))
        order = np.argsort(s)[::-1]
        s = s[order]
        A = A[:, order]

        U = np.dot(Q, A)

        # update k orthogonal bases
        self.U_k = U[:, :self.k]

        U_ell = U[:, :self.ell]
        s_ell = s[:self.ell]

        # shrink step in the Frequent Directions algorithm
        delta = s_ell[-1]
        s_ell = np.sqrt(s_ell - delta)

        self.E = np.dot(U_ell, np.diag(s_ell))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号