当前位置: 首页>>代码示例>>Python>>正文


Python LinearAlgebra.eigenvectors方法代码示例

本文整理汇总了Python中LinearAlgebra.eigenvectors方法的典型用法代码示例。如果您正苦于以下问题:Python LinearAlgebra.eigenvectors方法的具体用法?Python LinearAlgebra.eigenvectors怎么用?Python LinearAlgebra.eigenvectors使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在LinearAlgebra的用法示例。


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

示例1: calcEigenPairs

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
	def calcEigenPairs( self, RtR ):
		"""
		Calculate the corresponding eigenpairs for RtR, and sort them accordingly:
		M{m1 >= m2 >= m3}; set M{v3 = v1 x v2} to ensure a RHS
		(CORRECT)
		
		@postcondition: The eigen pairs are calculated, sorted such that M{m1 >= m2 >= m3} and
		M{v3 = v1 x v2}.
		
		@param RtR: 3x3 Matrix of M{R^t * R}.
		@type  RtR: 3x3 Matrix
		@return : Eigenpairs for the RtR matrix.
		@rtype  : List of stuff
		
		"""
		
		eVal, eVec = LinearAlgebra.eigenvectors(RtR)

		# This is cool.  We sort it using Numeric.sort(eVal)
		# then we reverse it using nifty-crazy ass notation [::-1].
		eVal2 = Numeric.sort(eVal)[::-1]
		eVec2 = [[],[],[]] #Numeric.zeros((3,3), Numeric.Float64)
				
		# Map the vectors to their appropriate owners		
		if ( eVal2[0] == eVal[0]):
			eVec2[0] = eVec[0]
			if ( eVal2[1] == eVal[1] ):
				eVec2[1] = eVec[1]
				eVec2[2] = eVec[2]
			else:
				eVec2[1] = eVec[2]
				eVec2[2] = eVec[1]
		elif( eVal2[0] == eVal[1]):
			eVec2[0] = eVec[1]
			if ( eVal2[1] == eVal[0] ):
				eVec2[1] = eVec[0]
				eVec2[2] = eVec[2]
			else:
				eVec2[1] = eVec[2]
				eVec2[2] = eVec[0]
		elif( eVal2[0] == eVal[2]):
			eVec2[0] = eVec[2]
			if ( eVal2[1] == eVal[1] ):
				eVec2[1] = eVec[1]
				eVec2[2] = eVec[0]
			else:
				eVec2[1] = eVec[0]
				eVec2[2] = eVec[1]

		eVec2[2][0] = eVec2[0][1]*eVec2[1][2] - eVec2[0][2]*eVec2[1][1]
		eVec2[2][1] = eVec2[0][2]*eVec2[1][0] - eVec2[0][0]*eVec2[1][2]
		eVec2[2][2] = eVec2[0][0]*eVec2[1][1] - eVec2[0][1]*eVec2[1][0]
		
		return [eVal2, eVec2]
开发者ID:svensken,项目名称:octathorp,代码行数:56,代码来源:kabsch.py

示例2: eig

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
def eig(object,**kw):
    """We try to adhere to the numpy way of doing things, so we need to do a transpose on the results
    that we get back from Numeric"""
    global _LinearAlgebra, _numpy_linalg
    if _LinearAlgebra:
        eigval,eigvec =  _LinearAlgebra.eigenvectors(object,**kw)
        eigvec = objects.numeric.transpose(eigvec)
        return eigval,eigvec
    elif _numpy_linalg:
        return _numpy_linalg.eig(object,**kw)
    else:
        raise AttributeError("No linear algebra functionality to deal with an eigenvectors.")
开发者ID:alexei-matveev,项目名称:ccp1gui,代码行数:14,代码来源:linalg.py

示例3: findTransformationAsQuaternion

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
    def findTransformationAsQuaternion(self, conf1, conf2 = None):
	if conf2 is None:
	    conf1, conf2 = conf2, conf1
        ref = conf1
        conf = conf2
        weights = self.universe().masses()
        weights = weights/self.mass()
        ref_cms = self.centerOfMass(ref).array
        pos = Numeric.zeros((3,), Numeric.Float)
        possq = 0.
        cross = Numeric.zeros((3, 3), Numeric.Float)
        for a in self.atomList():
            r = a.position(conf).array
            r_ref = a.position(ref).array-ref_cms
            w = weights[a]
            pos = pos + w*r
            possq = possq + w*Numeric.add.reduce(r*r) \
                          + w*Numeric.add.reduce(r_ref*r_ref)
            cross = cross + w*r[:, Numeric.NewAxis]*r_ref[Numeric.NewAxis, :]
        k = Numeric.zeros((4, 4), Numeric.Float)
        k[0, 0] = -cross[0, 0]-cross[1, 1]-cross[2, 2]
        k[0, 1] = cross[1, 2]-cross[2, 1]
        k[0, 2] = cross[2, 0]-cross[0, 2]
        k[0, 3] = cross[0, 1]-cross[1, 0]
        k[1, 1] = -cross[0, 0]+cross[1, 1]+cross[2, 2]
        k[1, 2] = -cross[0, 1]-cross[1, 0]
        k[1, 3] = -cross[0, 2]-cross[2, 0]
        k[2, 2] = cross[0, 0]-cross[1, 1]+cross[2, 2]
        k[2, 3] = -cross[1, 2]-cross[2, 1]
        k[3, 3] = cross[0, 0]+cross[1, 1]-cross[2, 2]
        for i in range(1, 4):
            for j in range(i):
                k[i, j] = k[j, i]
        k = 2.*k
        for i in range(4):
            k[i, i] = k[i, i] + possq - Numeric.add.reduce(pos*pos)
	import LinearAlgebra
	e, v = LinearAlgebra.eigenvectors(k)
	i = Numeric.argmin(e)
        v = v[i]
        if v[0] < 0: v = -v
	if e[i] <= 0.:
	    rms = 0.
	else:
	    rms = Numeric.sqrt(e[i])
        return Quaternion.Quaternion(v), Vector(ref_cms), \
               Vector(pos), rms
开发者ID:fxia22,项目名称:ASM_xf,代码行数:49,代码来源:Collection.py

示例4: compute

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
 def compute(self):
     N = len(self.points)
     Ninv = 1. / N
     # get the mean, and deviations from the mean
     mu = Ninv * self.mu
     devs = map(lambda pt,mu=mu: pt - mu, self.points)
     # get a covariance matrix
     C = Numeric.zeros((DIMENSIONS, DIMENSIONS))
     for x in devs:
         C = C + Numeric.matrixmultiply(x,
                                        Numeric.transpose(x))
     C = Ninv * C
     # sort eigenvalue/vector pairs in order of decreasing eigenvalue
     evals, V = LinearAlgebra.eigenvectors(C)
     pairs = map(None, evals, V)
     pairs.sort(lambda x, y: cmp(y, x))
     self.eigenvalues = map(lambda p: p[0], pairs)
     A = Numeric.array(map(lambda x: x[1], pairs))
     self.A = Numeric.transpose(A)
开发者ID:ChrisX34,项目名称:stuff,代码行数:21,代码来源:pca.py

示例5: diagonalization

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
def diagonalization(matrix):

    print 'diagonalizing %sx%s matrix' %(len(matrix),len(matrix))

    import LinearAlgebra

    eigen_tuple = LinearAlgebra.eigenvectors(matrix)
    ## parse eigenvalues and eigenvectors
    eigenvalues = list(eigen_tuple[0])
    eigenvectors = list(eigen_tuple[1])
    ## organize eigenvalues and eigenvectors in list
    eigen_list = zip(eigenvalues, eigenvectors)
    ## sort list
    eigen_list.sort()
    ## reverse list
    eigen_list.reverse()
    ## parse sorted eigenvalues and eigenvectors
    eigenvalues = [eigen_list[eigen][0] for eigen in range(len(eigen_list))]
    eigenvectors = [eigen_list[eigen][1] for eigen in range(len(eigen_list))]

    return eigenvalues, eigenvectors
开发者ID:tommycarstensen,项目名称:sandbox,代码行数:23,代码来源:pca.py

示例6: __init__

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
    def __init__(self, trajectory, object, first=0, last=None, skip=1,
                 reference = None):
        self.trajectory = trajectory
        universe = trajectory.universe
        if last is None: last = len(trajectory)
        first_conf = trajectory.configuration[first]
        offset = universe.contiguousObjectOffset([object], first_conf, 1)
        if reference is None:
            reference = first_conf
        reference = universe.contiguousObjectConfiguration([object],
                                                           reference)
        steps = (last-first+skip-1)/skip
        mass = object.mass()
        ref_cms = object.centerOfMass(reference)
        atoms = object.atomList()

        possq = Numeric.zeros((steps,), Numeric.Float)
        cross = Numeric.zeros((steps, 3, 3), Numeric.Float)
        rcms = Numeric.zeros((steps, 3), Numeric.Float)

        # cms of the CONTIGUOUS object made of CONTINUOUS atom trajectories 
        for a in atoms:
            r = trajectory.readParticleTrajectory(a, first, last, skip,
                                                  "box_coordinates").array
            w = a._mass/mass
            Numeric.add(rcms, w*r, rcms)
            if offset is not None:
                Numeric.add(rcms, w*offset[a].array, rcms)
        
        # relative coords of the CONTIGUOUS reference
        r_ref = Numeric.zeros((len(atoms), 3), Numeric.Float)
        for a in range(len(atoms)):
            r_ref[a] = atoms[a].position(reference).array - ref_cms.array

        # main loop: storing data needed to fill M matrix 
        for a in range(len(atoms)):
            r = trajectory.readParticleTrajectory(atoms[a],
                                                  first, last, skip,
                                                  "box_coordinates").array
            r = r - rcms # (a-b)**2 != a**2 - b**2
            if offset is not None:
                Numeric.add(r, offset[atoms[a]].array,r)
            trajectory._boxTransformation(r, r)
            w = atoms[a]._mass/mass
            Numeric.add(possq, w*Numeric.add.reduce(r*r, -1), possq)
            Numeric.add(possq, w*Numeric.add.reduce(r_ref[a]*r_ref[a],-1),
                        possq)
            Numeric.add(cross, w*r[:,:,Numeric.NewAxis]*r_ref[Numeric.NewAxis,
                                                              a,:],cross)
        self.trajectory._boxTransformation(rcms, rcms)

        # filling matrix M (formula no 40)
        k = Numeric.zeros((steps, 4, 4), Numeric.Float)
        k[:, 0, 0] = -cross[:, 0, 0]-cross[:, 1, 1]-cross[:, 2, 2]
        k[:, 0, 1] = cross[:, 1, 2]-cross[:, 2, 1]
        k[:, 0, 2] = cross[:, 2, 0]-cross[:, 0, 2]
        k[:, 0, 3] = cross[:, 0, 1]-cross[:, 1, 0]
        k[:, 1, 1] = -cross[:, 0, 0]+cross[:, 1, 1]+cross[:, 2, 2]
        k[:, 1, 2] = -cross[:, 0, 1]-cross[:, 1, 0]
        k[:, 1, 3] = -cross[:, 0, 2]-cross[:, 2, 0]
        k[:, 2, 2] = cross[:, 0, 0]-cross[:, 1, 1]+cross[:, 2, 2]
        k[:, 2, 3] = -cross[:, 1, 2]-cross[:, 2, 1]
        k[:, 3, 3] = cross[:, 0, 0]+cross[:, 1, 1]-cross[:, 2, 2]
        del cross
        for i in range(1, 4):
            for j in range(i):
                k[:, i, j] = k[:, j, i]
        Numeric.multiply(k, 2., k)
        for i in range(4):
            Numeric.add(k[:,i,i], possq, k[:,i,i])
        del possq

        quaternions = Numeric.zeros((steps, 4), Numeric.Float)
        fit = Numeric.zeros((steps,), Numeric.Float)
	import LinearAlgebra
        for i in range(steps):
            e, v = LinearAlgebra.eigenvectors(k[i])
            j = Numeric.argmin(e)
            if e[j] < 0.:
                fit[i] = 0.
            else:
                fit[i] = Numeric.sqrt(e[j])
            if v[j,0] < 0.: quaternions[i] = -v[j] # eliminate jumps
            else: quaternions[i] = v[j]
        self.fit = fit
        self.cms = rcms
        self.quaternions = quaternions
开发者ID:fxia22,项目名称:ASM_xf,代码行数:89,代码来源:Trajectory.py

示例7: open

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
ca = Numeric.reshape(ca_pos, (num_ts, -1))
ca_avg = Numeric.average(ca)
ca2 = ca - ca_avg[Numeric.NewAxis, :]
ca_cov = Numeric.zeros((num_coor, num_coor), Numeric.Float)
for ts in ca2:
    ca_cov += Numeric.outerproduct(ts, ts)
ca_cov /= num_ts
ca_cov1 = Numeric.matrixmultiply(ca_cov, mass_matrix)
del ca_cov
ca_cov2 = Numeric.matrixmultiply(mass_matrix, ca_cov1)
del ca_cov1

N_av = 6.0221367e23
hplanck_bar = 6.6260755e-34 / (2 * Numeric.pi)
k = 1.3806580000000001e-23
T = 300  # kelvin
eigenv, eigenvec = LinearAlgebra.eigenvectors(ca_cov2)
real = [e.real / 100. for e in eigenv]
f = open('eigenval.dat', 'w')
for i, val in enumerate(real):
    f.write("%i\t%s\n" % (i + 1, val))
f.close()

eigenval = eigenv * 1.6605402e-27 * 1e-20
omega_i = Numeric.sqrt(k * T / (eigenval))

term = (hplanck_bar * omega_i) / (k * T)
summation_terms = (term / (Numeric.exp(term) - 1.)) - Numeric.log(1. - Numeric.exp(-term))
S_ho = k * N_av * Numeric.sum(summation_terms)
开发者ID:djay0529,项目名称:mdanalysis,代码行数:31,代码来源:schlitter_quasiharmonic.py

示例8: eig

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
def eig(v):
    """[x,v] = eig(m) returns the eigenvalues of m in x and the corresponding
    eigenvectors in the rows of v.
    """
    return LinearAlgebra.eigenvectors(v)
开发者ID:tomaszpg,项目名称:PogodaTMC,代码行数:7,代码来源:MLab.py

示例9: Vector

# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import eigenvectors [as 别名]
    me.edges.extend(me.verts[i],me.verts[i+1])
me.faces.extend(me.verts[0],me.verts[1],me.verts[2]) # Add the faces, they reference the verts in polyline 1 and 2

scn = Blender.Scene.GetCurrent()
ob = scn.objects.new(me)

print ob.getLocation()

po = []
      
po.extend([1,2,3])
po.extend([2,3])

b = []

c =  la.eigenvectors(a)
d = la.eigenvalues(a)

opa = Vector(c[1][0])

print c[0], 'Mas por que'
print c[1][0], 'Mas por que v1' , opa.magnitude
print c[1][1], 'Mas por que v2'
print c[1][2], 'Mas por que v3'



b =  [Vector(c[1][0]),Vector(c[1][1]),Vector(c[1][2])]

print b,'Felipe b '
开发者ID:duststorm,项目名称:lodpbr,代码行数:32,代码来源:polyFill.py


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