本文整理匯總了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)