python类qr()的实例源码

word2vec_as_MF.py 文件源码 项目:ro_sgns 作者: AlexGrinch 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def projector_splitting(self, eta=5e-6, d=100, 
                            MAX_ITER=1, from_iter=0, display=0, 
                            init=(False, None, None), save=(False, None)):
        """
        Projector splitting algorithm for word2vec matrix factorization.
        """

        # Initialization
        if (init[0]):
            self.C = init[1]
            self.W = init[2]
        else:
            self.C = np.random.rand(d, self.D.shape[0])
            self.W = np.random.rand(d, self.D.shape[1]) 

        if (save[0] and from_iter==0):
                self.save_CW(save[1], 0)

        X = (self.C).T.dot(self.W)
        for it in xrange(from_iter, from_iter+MAX_ITER):

            if (display):
                print "Iter #:", it+1

            U, S, V = svds(X, d)
            S = np.diag(S)
            V = V.T

            self.C = U.dot(np.sqrt(S)).T
            self.W = np.sqrt(S).dot(V.T)

            if (save[0]):
                self.save_CW(save[1], it+1)

            F = self.grad_MF(self.C, self.W)
            #mask = np.random.binomial(1, .5, size=F.shape)
            #F = F * mask

            U, _ = qr((X + eta*F).dot(V))
            V, S = qr((X + eta*F).T.dot(U))
            V = V.T
            S = S.T

            X = U.dot(S).dot(V)


问题


面经


文章

微信
公众号

扫码关注公众号