本文整理匯總了Python中LinearAlgebra.linear_least_squares方法的典型用法代碼示例。如果您正苦於以下問題:Python LinearAlgebra.linear_least_squares方法的具體用法?Python LinearAlgebra.linear_least_squares怎麽用?Python LinearAlgebra.linear_least_squares使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類LinearAlgebra
的用法示例。
在下文中一共展示了LinearAlgebra.linear_least_squares方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testLinearLeastSquares2
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [as 別名]
def testLinearLeastSquares2(self):
"""
From bug #503733. Failing with dlapack_lite
"""
import LinearAlgebra
d = [0.49910197] + [0.998203938] * 49
d1 = [0.000898030454] * 50
def tridiagonal(sz):
G = Numeric.zeros((sz,sz), Numeric.Float64)
for i in range(sz):
G[i,i] = d[i]
for i in range(0,sz-1):
G[i+1,i] = G[i,i+1] = d1[i]
return G
yfull = Numeric.array(
[4.37016668e+18, 4.09591905e+18, 3.82167167e+18, 4.12952660e+18,
2.60084719e+18, 2.05944452e+18, 1.69850960e+18, 1.51450383e+18,
1.39419275e+18, 1.25264986e+18, 1.18187857e+18, 1.16772440e+18,
1.17126300e+18, 1.13941580e+18, 1.17834000e+18, 1.20664860e+18,
1.18895580e+18, 1.18895580e+18, 1.21726440e+18, 1.24557296e+18,
1.22434149e+18, 1.23495719e+18, 1.24203436e+18, 1.22434160e+18,
1.23495720e+18, 1.21372580e+18, 1.22434160e+18, 1.21018740e+18,
1.22080300e+18, 1.15357020e+18, 1.19957160e+18, 1.18187880e+18,
1.19249440e+18, 1.18895579e+18, 1.28449704e+18, 1.27742021e+18,
1.30218984e+18, 1.30926700e+18, 1.25972716e+18, 1.15003156e+18,
1.17126296e+18, 1.15710876e+18, 1.10756882e+18, 1.20311006e+18,
1.29511286e+18, 1.28449726e+18, 1.29157446e+18, 1.44373273e+18,])
for i in range(20, 40):
G = tridiagonal(i)
y = yfull[:i]
A = LinearAlgebra.linear_least_squares(G, y)[0]
total = Numeric.add.reduce(y)
residual = Numeric.absolute(y - Numeric.dot(G, A))
assert_eq(0.0, Numeric.add.reduce(residual)/total)
示例2: plotit
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [as 別名]
def plotit(xs,ys,title,legends):
#
# Do it
#
num_points=0
for x in xs:
num_points=num_points+len(x)
print num_points,'data points'
#x=[1,2,3,4,5,6,7,8,9]
#y=[2,4,6,8,10,12,14,16,18]
mat_fix=[]
vec_fix=[]
for x in xs:
for point in x:
mat_fix.append([point,1.0])
for y in ys:
for point in y:
vec_fix.append(point)
import LinearAlgebra
sols,rsq,rank,junk=LinearAlgebra.linear_least_squares(Numeric.array(mat_fix),
Numeric.array(vec_fix))
slope=sols[0]
intercept=sols[1]
print rsq
rsq=float(rsq[0])
print 'Slope: %.2f, Intercept: %.2f, R^2: %.2f' %(slope,intercept,rsq)
file=dislin_driver.graf_mult3(xs,ys,title,'Simple E','PBE_ene',legends)
return
示例3: testLinearLeastSquares
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [as 別名]
def testLinearLeastSquares(self):
"""
From bug #503733.
"""
# XXX not positive on this yet
import LinearAlgebra
from RandomArray import seed, random
seed(7,19)
(n, m) = (180, 35)
yp = random((n,m))
y = random(n)
x, residuals, rank, sv = LinearAlgebra.linear_least_squares(yp, y)
# shouldn't segfault.
assert rank == m
示例4: fitPolynomial
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [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)
示例5: lsf
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [as 別名]
def lsf(data, a, n):
xmat=setxmat(data, a, n)
yvec=setyvec(data, n)
return LinearAlgebra.linear_least_squares(xmat, yvec)
示例6: dot
# 需要導入模塊: import LinearAlgebra [as 別名]
# 或者: from LinearAlgebra import linear_least_squares [as 別名]
import sys,numeric_version
import RandomArray
import LinearAlgebra
print sys.version
print "Numeric version:",numeric_version.version
RandomArray.seed(123,456)
a = RandomArray.normal(0,1,(100,10))
f = RandomArray.normal(0,1,(10,30))
e = RandomArray.normal(0,0.1,(100,30))
print "Got to seed:",RandomArray.get_seed()
b = dot(a,f)+e
(x,res,rank,s)=LinearAlgebra.linear_least_squares(a,b)
f_res = sum((b-dot(a,f))**2)
x_res = sum((b-dot(a,x))**2)
print "'Planted' residues, upper bound for optimal residues:"
print f_res
print "Claimed residues:"
print res
print "Actual residues:"
print x_res
print "Ratio between actual and claimed (shoudl be 1):"
print x_res/res
print "Ratio between actual and planted (should be <1):"
print x_res/f_res
print "Ratio between claimed and planted (shoudl be <1):"