• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python linalg.rq函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.linalg.rq函数的典型用法代码示例。如果您正苦于以下问题:Python rq函数的具体用法?Python rq怎么用?Python rq使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了rq函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_random

 def test_random(self):
     n = 20
     for k in range(2):
         a = random([n,n])
         r,q = rq(a)
         assert_array_almost_equal(dot(transpose(q),q),identity(n))
         assert_array_almost_equal(dot(r,q),a)
开发者ID:dagss,项目名称:private-scipy-refactor,代码行数:7,代码来源:test_decomp.py


示例2: test_random_complex

 def test_random_complex(self):
     n = 20
     for k in range(2):
         a = random([n,n])+1j*random([n,n])
         r,q = rq(a)
         assert_array_almost_equal(dot(q, conj(transpose(q))),identity(n))
         assert_array_almost_equal(dot(r,q),a)
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:7,代码来源:test_decomp.py


示例3: test_random_tall

 def test_random_tall(self):
     m = 200
     n = 100
     for k in range(2):
         a = random([m,n])
         r,q = rq(a)
         assert_array_almost_equal(dot(q, transpose(q)),identity(n))
         assert_array_almost_equal(dot(r,q),a)
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:8,代码来源:test_decomp.py


示例4: factor

def factor(P):
    K, R = linalg.rq(P[:, :3])
    T = np.diag(np.sign(np.diag(K)))
    if linalg.det(T) < 0:
        T[1, 1] *= -1

    K = np.dot(K, T)
    R = np.dot(T, R)
    t = np.dot(linalg.inv(K), P[:, 3])
    return K, R, t
开发者ID:Nate711,项目名称:TurbidityVideoProcessing,代码行数:10,代码来源:GPSCoorTest.py


示例5: test_random_complex_economic

 def test_random_complex_economic(self):
     m = 100
     n = 200
     for k in range(2):
         a = random([m,n])+1j*random([m,n])
         r,q = rq(a, mode='economic')
         assert_array_almost_equal(dot(q,conj(transpose(q))),identity(m))
         assert_array_almost_equal(dot(r,q),a)
         assert_equal(q.shape, (m, n))
         assert_equal(r.shape, (m, m))
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:10,代码来源:test_decomp.py


示例6: factor

	def factor(self):
		""" Factorize the camera matrix into K,R,t as P = K[R|t]. """
		# factor first 3*3 part
		K,R = linalg.rq(self.P[:,:3])
		# make diagonal of K positive
		T = diag(sign(diag(K)))
		if linalg.det(T) < 0:
			T[1,1] *= -1
		self.K = dot(K,T)
		self.R = dot(T,R) # T is its own inverse
		self.t = dot(linalg.inv(self.K),self.P[:,3])
		return self.K, self.R, self.t
开发者ID:maxschommer,项目名称:Multirotors,代码行数:12,代码来源:camera.py


示例7: factor

def factor(self):

    K,R = linalg.rq(self.P[:,:3])
    T = diag(sign(diag(K)))
    if linalg.det(T) < 0:
        T[1,1] *= -1

    self.K = dot(K,T)
    self.R = dot(T,R)
    self.t = dot(linalg.inv(self.K), self.P[:,:3])

    return self.K, self.R, self.t
开发者ID:GumpCode,项目名称:CodemySummer,代码行数:12,代码来源:camera.py


示例8: factor

 def factor(self):
     """Factorize the camera matrix into K, R, t as P=K[P|t]"""
     K,R = linalg.rq(self.P[:,:3])
     #make diagonal of K positive
     T = np.diag(np.sign(np.diag(K)))
     if linalg.det(T)<0:
         T[1,1]*=-1
         
     self.K = np.dot(K,T)
     self.R = np.dot(T,R)
     self.t = np.dot(linalg.inv(self.K),self.P[:,3])
     
     return self.K, self.R, self.t
开发者ID:rayjim,项目名称:python_proj,代码行数:13,代码来源:camera.py


示例9: factor

 def factor(self):
     """ P = K[R|t]に従い、カメラ行列を K,R,tに分解する """
     # 最初の3*3の部分を分解する
     K,R = linalg.rq(self.P[:,:3])
     
     # Kの対角成分が正になるようにする。
     T = np.diag(np.sign(np.diag(K)))
     if linalg.det(T) < 0:
         T[1,1] *= -1
         
     self.K = np.dot(K,T)
     self.R = np.dot(T,R) # Tはそれ自身が逆行列
     self.t = np.dot(linalg.inv(self.K),self.P[:,3])
         
     return self.K, self.R, self.t
开发者ID:ta-oyama,项目名称:PCV,代码行数:15,代码来源:camera.py


示例10: extract_KRt

def extract_KRt(P):
	"""Based on http://www.janeriksolem.net/2011/03/rq-factorization-of-camera-matrices.html"""
	H = P[0:3, 0:3]
	K, R = rq(H)
	T = np.diag(np.sign(np.diag(K)))
	K = np.dot(K,T)
	R = np.dot(T,R)
	t = np.dot(np.linalg.inv(K), P[:,-1])

	if np.linalg.det(R) < 0 :
		R = np.dot(R, -1 * np.eye(3))
		t = np.dot(-1 * np.eye(3), t)

	K = K/K[-1,-1]

	return K,R,t
开发者ID:srajotte,项目名称:visiontk,代码行数:16,代码来源:algo.py


示例11: retr

    def retr(self, X, Z):
        XU, XS, XV = X
        ZUp, ZM, ZVp = Z
        Qu, Ru = la.qr(ZUp)
        Rv, Qv = rq(ZVp, mode='economic')

        zero_block = np.zeros((Ru.shape[0], Rv.shape[1]))
        block_mat = np.array(np.bmat([[XS + ZM, Rv],
                                     [Ru, zero_block]]))

        Ut, St, Vt = la.svd(block_mat, full_matrices=False)

        U = np.hstack((XU, Qu)).dot(Ut[:, :self._k])
        V = Vt[:self._k, :].dot(np.vstack((XV, Qv)))
        # add some machinery eps to get a slightly perturbed element of a manifold
        # even if we have some zeros in S
        S = np.diag(St[:self._k]) + np.diag(np.spacing(1) * np.ones(self._k))
        return (U, S, V)
开发者ID:Nehoroshiy,项目名称:logmat_riemannian,代码行数:18,代码来源:fixed_rank.py


示例12: factor

    def factor(self, K=None):
        """    Factorize the camera matrix into K,R,t as P = K[R|t]. """
        if K is not None:
            # factor first 3*3 part
            K,R = linalg.rq(self.P[:,:3])

            # make diagonal of K positive
            T = diag(sign(diag(K)))
            if linalg.det(T) < 0:
                T[1,1] *= -1

            self.K = dot(K,T)
            self.R = dot(T,R) # T is its own inverse
            self.t = dot(linalg.inv(self.K),self.P[:,3])

            return self.K, self.R, self.t
        else:
            print("K")
            print(self.K)
            print("Kinv")
            Kinv = linalg.inv(self.K)
            print(Kinv)
            Pose = dot(Kinv, self.P)
开发者ID:mirwox,项目名称:robotica16,代码行数:23,代码来源:camera.py


示例13: RDU

def RDU(A): # Calculate the RDU decomposition of a matrix {{{
    r,U = rq(A)
    d = numpy.diagonal(r)
    R = r / d[newaxis,:]
    D = diagflat(d)
    return R,D,U #}}}
开发者ID:SuperFluffy,项目名称:DeerQMC,代码行数:6,代码来源:math_functions.py


示例14: decomposeQR

    def decomposeQR(self, gl=None, order='qr'):
        """
        Decomposes gl using QR decomposition into:

          gl = q p s m (order 'qr' or 'qpsm') 
          gl = p s m q (order 'rq' or 'psmq')

        where:
          - q: rotation (orthogonal, with det +1) matrix
          - p: parity (diagonal, all elements +1, except that the element 
          corresponding to self.parity_axismatrix can be -1)
          possibly -1
          - s: scale martix, diagonal and positive
          - m: shear matrix, upper triangular, all diagonal elements 1

        Arguments:
          - gl: (ndarray) general linear transformation
          - order: decomposition order 'qr' or 'rq'

        Returns: (q, p, s, m)
        """

        # set decomposition type
        self.order = order

        # parse arg
        if gl is None:
            gl = self.gl
        ndim = gl.shape[0]

        # QR decompose 
        if (order == 'rq') or (order == 'psmq'):
            r, q = linalg.rq(gl)
        elif (order == 'qr') or (order == 'qpsm'):
            q, r = linalg.qr(gl)
        else:
            ValueError("Argumnet order: ", order, " not understood. It should ",
                       "be 'psmq' (same as 'rq') or 'qpsm' (same as 'qr').")

        # extract s, p and m
        r_diag = r.diagonal()
        s_diag = numpy.abs(r_diag)
        s = numpy.diag(s_diag)
        p_diag = numpy.sign(r_diag)
        p = numpy.diag(p_diag)
        s_inv_diag = 1. * p_diag / s_diag
        m = numpy.dot(numpy.diag(s_inv_diag), r)

        # make q = q p and p = 1
        if (order == 'rq') or (order == 'psmq'):
            m = numpy.dot(numpy.dot(p, m), p)
            q = numpy.dot(p, q)
        elif (order == 'qr') or (order == 'qpsm'):
            q = numpy.dot(q, p)
        p = numpy.abs(p)

        # make sure det(q) > 0 and adjust p accordingly
        if linalg.det(q) < 0:
            p = numpy.identity(ndim, dtype=int)
            p[self.parity_axis, self.parity_axis] = -1
            if (order == 'rq') or (order == 'psmq'):
                q = numpy.dot(p, q)
                m = numpy.dot(numpy.dot(p, m), p)
            elif (order == 'qr') or (order == 'qpsm'):
                q = numpy.dot(q, p)

        return q, p, s, m
开发者ID:Splo0sh,项目名称:3DCT,代码行数:67,代码来源:affine.py


示例15: test_simple

 def test_simple(self):
     a = [[8,2,3],[2,9,3],[5,3,6]]
     r,q = rq(a)
     assert_array_almost_equal(dot(transpose(q),q),identity(3))
     assert_array_almost_equal(dot(r,q),a)
开发者ID:dagss,项目名称:private-scipy-refactor,代码行数:5,代码来源:test_decomp.py


示例16: state2MPS

def state2MPS(state,sitedim,l,method='qr',tol=1e-8):
    '''
    Parse a normal state into a Matrix produdct state.

    state:
        The target state, 1D array.
    sitedim:
        The dimension of a single site, integer.
    l:
        The division point of left and right canonical scanning, integer between 0 and number of site.
    method:
        The method to extract A,B matrices.
        * 'qr'  -> get A,B matrices by the method of QR decomposition, faster, rank revealing in a non-straight-forward way.
        * 'svd'  -> get A,B matrices by the method of SVD decomposition, slow, rank revealing.
    tol:
        The tolerence of singular value, float.

    *return*:
        A <MPS> instance.
    '''
    nsite=int(round(log(len(state))/log(sitedim)))
    AL,BL=[],[]
    ri=1
    assert(method=='svd' or method=='qr')
    assert(l>=0 and l<=nsite)

    for i in xrange(l):
        state=state.reshape([sitedim*ri,-1])
        if method=='svd':
            U,S,V=svd(state,full_matrices=False)
            #remove zeros from v
            kpmask=abs(S)>tol
            ri=kpmask.sum()
            state=S[kpmask,newaxis]*V[kpmask]
            U=U[:,kpmask]
        else:
            U,state=qr(state,mode='economic')
            kpmask=sum(abs(state),axis=1)>tol
            ri=kpmask.sum()
            state=state[kpmask]
            U=U[:,kpmask]
        ai=swapaxes(U.reshape([-1,sitedim,ri]),0,1)
        AL.append(ai)

    ri=1
    for i in xrange(nsite-l):
        state=state.reshape([-1,sitedim*ri])
        if method=='svd':
            U,S,V=svd(state,full_matrices=False)
            #remove zeros from v
            kpmask=abs(S)>tol
            ri=kpmask.sum()
            state=S[kpmask]*U[:,kpmask]
            V=V[kpmask,:]
        else:
            state,V=rq(state,mode='economic')
            kpmask=sum(abs(state),axis=0)>tol
            ri=kpmask.sum()
            state=state[:,kpmask]
            V=V[kpmask]
        bi=swapaxes(V.reshape([ri,sitedim,-1]),0,1)
        BL.append(bi)
    BL=BL[::-1]
    S=state.diagonal()
    return KMPS(AL,BL,S=S)
开发者ID:Lynn-015,项目名称:NJU_DMRG,代码行数:65,代码来源:mpslib.py


示例17: test_simple_complex

 def test_simple_complex(self):
     a = [[3,3+4j,5],[5,2,2+7j],[3,2,7]]
     r,q = rq(a)
     assert_array_almost_equal(dot(q, conj(transpose(q))),identity(3))
     assert_array_almost_equal(dot(r,q),a)
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:5,代码来源:test_decomp.py


示例18: test_simple_tall

 def test_simple_tall(self):
     a = [[8,2],[2,9],[5,3]]
     r,q = rq(a)
     assert_array_almost_equal(dot(transpose(q),q),identity(2))
     assert_array_almost_equal(dot(r,q),a)
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:5,代码来源:test_decomp.py


示例19: test_r

 def test_r(self):
     a = [[8,2,3],[2,9,3],[5,3,6]]
     r,q = rq(a)
     r2 = rq(a, mode='r')
     assert_array_almost_equal(r, r2)
开发者ID:BeeRad-Johnson,项目名称:scipy-refactor,代码行数:5,代码来源:test_decomp.py



注:本文中的scipy.linalg.rq函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python linalg.signm函数代码示例发布时间:2022-05-27
下一篇:
Python linalg.qr函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap