本文整理汇总了Python中LinearAlgebra.generalized_inverse方法的典型用法代码示例。如果您正苦于以下问题:Python LinearAlgebra.generalized_inverse方法的具体用法?Python LinearAlgebra.generalized_inverse怎么用?Python LinearAlgebra.generalized_inverse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LinearAlgebra
的用法示例。
在下文中一共展示了LinearAlgebra.generalized_inverse方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import generalized_inverse [as 别名]
def __init__(self, atoms, constraints):
self.atoms = atoms
natoms = len(self.atoms)
nconst = reduce(operator.add, map(len, constraints))
b = Numeric.zeros((nconst, natoms), Numeric.Float)
c = Numeric.zeros((nconst,), Numeric.Float)
i = 0
for cons in constraints:
cons.setCoefficients(self.atoms, b, c, i)
i = i + len(cons)
u, s, vt = LinearAlgebra.singular_value_decomposition(b)
self.rank = 0
for i in range(min(natoms, nconst)):
if s[i] > 0.:
self.rank = self.rank + 1
self.b = b
self.bi = LinearAlgebra.generalized_inverse(b)
self.p = Numeric.identity(natoms)-Numeric.dot(self.bi, self.b)
self.c = c
self.bi_c = Numeric.dot(self.bi, c)
c_test = Numeric.dot(self.b, self.bi_c)
if Numeric.add.reduce((c_test-c)**2)/nconst > 1.e-12:
Utility.warning("The charge constraints are inconsistent."
" They will be applied as a least-squares"
" condition.")
示例2: testgeneralizedInverse
# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import generalized_inverse [as 别名]
def testgeneralizedInverse (self):
"Test LinearAlgebra.generalized_inverse"
import LinearAlgebra
ca = Numeric.array([[1,1-1j],[0,1]])
cai = LinearAlgebra.inverse(ca)
cai2 = LinearAlgebra.generalized_inverse(ca)
self.failUnless(eq(cai, cai2))
示例3: screwMotion
# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import generalized_inverse [as 别名]
def screwMotion(self):
import LinearAlgebra
axis, angle = self.rotation().axisAndAngle()
d = self.vector*axis
x = d*axis-self.vector
r0 = Numeric.dot(LinearAlgebra.generalized_inverse(
self.tensor.array-Numeric.identity(3)), x.array)
return VectorModule.Vector(r0), axis, angle, d
示例4: fitPolynomial
# 需要导入模块: import LinearAlgebra [as 别名]
# 或者: from LinearAlgebra import generalized_inverse [as 别名]
def fitPolynomial(order, points, values):
if len(points) != len(values):
raise ValueError, 'Inconsistent arguments'
if type(order) != type(()):
order = (order,)
order = tuple(map(lambda n: n+1, order))
if not _isSequence(points[0]):
points = map(lambda p: (p,), points)
if len(order) != len(points[0]):
raise ValueError, 'Inconsistent arguments'
if Numeric.multiply.reduce(order) > len(points):
raise ValueError, 'Not enough points'
matrix = []
for p in points:
matrix.append(Numeric.ravel(_powers(p, order)))
matrix = Numeric.array(matrix)
values = Numeric.array(values)
inv = LinearAlgebra.generalized_inverse(matrix)
coeff = Numeric.dot(inv, values)
#coeff = LinearAlgebra.linear_least_squares(matrix, values)[0]
coeff = Numeric.reshape(coeff, order)
return Polynomial(coeff)