本文整理汇总了Python中scipy.linalg.hilbert函数的典型用法代码示例。如果您正苦于以下问题:Python hilbert函数的具体用法?Python hilbert怎么用?Python hilbert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了hilbert函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_basic
def test_basic(self):
h3 = array([[1.0, 1 / 2.0, 1 / 3.0], [1 / 2.0, 1 / 3.0, 1 / 4.0], [1 / 3.0, 1 / 4.0, 1 / 5.0]])
assert_array_almost_equal(hilbert(3), h3)
assert_array_equal(hilbert(1), [[1.0]])
h0 = hilbert(0)
assert_equal(h0.shape, (0, 0))
开发者ID:person142,项目名称:scipy,代码行数:8,代码来源:test_special_matrices.py
示例2: test_inverse
def test_inverse(self):
for n in xrange(1, 10):
a = hilbert(n)
b = invhilbert(n)
# The Hilbert matrix is increasingly badly conditioned,
# so take that into account in the test
c = cond(a)
assert_allclose(a.dot(b), eye(n), atol=1e-15*c, rtol=1e-15*c)
开发者ID:AGPeddle,项目名称:scipy,代码行数:8,代码来源:test_special_matrices.py
示例3: test_svd_which
def test_svd_which():
# check that the which parameter works as expected
x = hilbert(6)
for which in ['LM', 'SM']:
_, s, _ = sorted_svd(x, 2, which=which)
ss = svds(x, 2, which=which, return_singular_vectors=False)
ss.sort()
assert_allclose(s, ss, atol=np.sqrt(1e-15))
开发者ID:7924102,项目名称:scipy,代码行数:8,代码来源:test_arpack.py
示例4: test_svd_maxiter
def test_svd_maxiter():
# check that maxiter works as expected
x = hilbert(6)
# ARPACK shouldn't converge on such an ill-conditioned matrix with just
# one iteration
assert_raises(ArpackNoConvergence, svds, x, 1, maxiter=1)
# but 100 iterations should be more than enough
u, s, vt = svds(x, 1, maxiter=100)
assert_allclose(s, [1.7], atol=0.5)
开发者ID:7924102,项目名称:scipy,代码行数:9,代码来源:test_arpack.py
示例5: run_stats
def run_stats(dimension):
matrices = {}
# Generation of the 4 relevant matrices
matrices['normal'] = np.matrix(np.random.randn(dimension, dimension))
matrices['hilbert'] = np.matrix(sp.hilbert(dimension))
matrices['pascal'] = np.matrix(pascal(dimension))
if dimension != 100:
matrices['magic'] = np.matrix(magic(dimension))
else:
matrices['magic'] = np.matrix(np.identity(100))
x = np.matrix(np.ones((dimension,1)))
data = {} # these are just bookkeeping things that keep track of variables for future use
for name, matr in matrices.items():
this_matrix_data = {}
b = matr * x
try:
xhat = sp.solve(matr, b)
xhat1 = np.linalg.inv(matr) * b
except np.linalg.LinAlgError:
xhat = x
xhat1 = x
this_matrix_data['delta_b'] = matr * xhat - b
norm_data = {}
# Loop through the three norms we're asked to do
for norm_type in [1, 2, np.inf]:
values = {}
values['x_relative_error'] = sp.norm(x - xhat, norm_type) / sp.norm(x, norm_type)
values['x_relative_error_inv'] = sp.norm(x - xhat1, norm_type) / sp.norm(x, norm_type)
try:
values['condition_no'] = np.linalg.cond(matr, norm_type)
except:
values['condition_no'] = 0
values['cond_rel_b_err'] = values['condition_no'] * (sp.norm(this_matrix_data['delta_b'], norm_type) / sp.norm(b, norm_type))
norm_data[norm_type] = values
this_matrix_data['norm_dep_vals'] = norm_data
data[name] = this_matrix_data
return data
开发者ID:hallliu,项目名称:f2013,代码行数:46,代码来源:no3.py
示例6: demo
def demo(n):
from numpy import random
from scipy import linalg
A = random.randn(n, n)
x = random.randn(n)
print('\n\t\t Random matrix of dimension', n)
showerr(A, x)
A = linalg.hilbert(n)
print('\n\t\t Hilbert matrix of dimension', n)
showerr(A, x)
from . import cond
A = cond.laplace(n)
print('\n\t\t Disc Laplacian of dimension', n)
showerr(A, x)
开发者ID:RTSandberg,项目名称:classes,代码行数:17,代码来源:error.py
示例7: main
def main():
for n in range(12, 20):
H = hilbert(n)
x = [1000 for _ in range(n)]
b = H.dot(x)
x = np.linalg.solve(H, b)
Hx = H.dot(x)
r = b - Hx
print np.linalg.norm(r, np.inf)
iter = 0
while np.linalg.norm(r, np.inf) > 1e-5 and iter < 50:
z = np.linalg.solve(H, r)
x = x + z
Ax = H.dot(x)
r = b - Ax
iter += 1
print iter, x
开发者ID:mcleary,项目名称:sandbox,代码行数:22,代码来源:homework1.1.py
示例8: print
print(A)
#b)
b=np.array([npr.rand(),npr.rand(),npr.rand()])
print(b)
#c)
x=solve(A,b)
print(x)
#sprawdzenie poprawności rozwiązania
print(npl.norm(np.dot(A,x)-b))
# powinno wyjść coś bliskiego zeru
#d)
H=sclin.hilbert(4)
print(H)
#e)
c=np.array([npr.rand(),npr.rand(),npr.rand(),npr.rand()])
print(c)
#f)
y=solve(H,c)
print(y)
#sprawdzenie poprawności rozwiązania
print(npl.norm(np.dot(H,y)-c))
# powinno wyjść coś bliskiego zeru
#g
开发者ID:abemke,项目名称:python-notatki,代码行数:31,代码来源:16IV2016cw2.py
示例9: test_svd_return
def test_svd_return():
# check that the return_singular_vectors parameter works as expected
x = hilbert(6)
_, s, _ = sorted_svd(x, 2)
ss = svds(x, 2, return_singular_vectors=False)
assert_allclose(s, ss)
开发者ID:7924102,项目名称:scipy,代码行数:6,代码来源:test_arpack.py
示例10: array
B
# Out[3]:
# array([[ 1., 2., 3., 4.],
# [ 2., 3., 4., 5.],
# [ 3., 4., 5., 6.],
# [ 4., 5., 6., 7.]])
# In[4]:
A = 1/B
from scipy.linalg import hilbert
A2 = hilbert(n)
print "difference: %g" % la.norm(A-A2)
print "cond: %g" % np.linalg.cond(A)
# Out[4]:
# difference: 0
# cond: 15513.7
#
# /usr/lib/pymodules/python2.7/numpy/oldnumeric/__init__.py:11: ModuleDeprecationWarning: The oldnumeric module will be dropped in Numpy 1.9
# warnings.warn(_msg, ModuleDeprecationWarning)
#
开发者ID:jeromeku,项目名称:numerical,代码行数:30,代码来源:Hilbert+matrix.py
示例11: range
for k in range(n-1,-1,-1):
b[k] = (b[k] - np.dot(L[k+1:n,k],b[k+1:n]))/L[k,k]
return b
choleski(a2)
print ("The answer for problem 11 is:")
print (choleskiSol(a2,b2))
"""
#Problem 15
#Code is not working correctly. I did not have enough time to finish it.
a3 = hilbert(2)
b3 = []
x = []
i = 0
actNorm = 1*10**-6
while True:
b3.append(a3[i].sum())
x.append([1])
xNorm = np.linalg.norm(x, np.inf)
xApprox = np.linalg.solve(a3, b3)
xHat = np.linalg.norm(xApprox, np.inf)
approxErr = xNorm - xHat
if abs(approxErr) < actNorm:
break
i = i + 1
开发者ID:JoshHarris85,项目名称:Linear-Algebra-Python-Homework,代码行数:31,代码来源:homework2.py
示例12: test_badcall
def test_badcall(self):
A = hilbert(5).astype(np.float32)
assert_raises(ValueError, pymatrixid.interp_decomp, A, 1e-6, rand=False)
开发者ID:hitej,项目名称:meta-core,代码行数:3,代码来源:test_interpolative.py
示例13: check_id
def check_id(self, dtype):
# Test ID routines on a Hilbert matrix.
# set parameters
n = 300
eps = 1e-12
# construct Hilbert matrix
A = hilbert(n).astype(dtype)
if np.issubdtype(dtype, np.complexfloating):
A = A * (1 + 1j)
L = aslinearoperator(A)
# find rank
S = np.linalg.svd(A, compute_uv=False)
try:
rank = np.nonzero(S < eps)[0][0]
except:
rank = n
# print input summary
_debug_print("Hilbert matrix dimension: %8i" % n)
_debug_print("Working precision: %8.2e" % eps)
_debug_print("Rank to working precision: %8i" % rank)
# set print format
fmt = "%8.2e (s) / %5s"
# test real ID routines
_debug_print("-----------------------------------------")
_debug_print("Real ID routines")
_debug_print("-----------------------------------------")
# fixed precision
_debug_print("Calling iddp_id / idzp_id ...",)
t0 = time.clock()
k, idx, proj = pymatrixid.interp_decomp(A, eps, rand=False)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
_debug_print("Calling iddp_aid / idzp_aid ...",)
t0 = time.clock()
k, idx, proj = pymatrixid.interp_decomp(A, eps)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
_debug_print("Calling iddp_rid / idzp_rid ...",)
t0 = time.clock()
k, idx, proj = pymatrixid.interp_decomp(L, eps)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
# fixed rank
k = rank
_debug_print("Calling iddr_id / idzr_id ...",)
t0 = time.clock()
idx, proj = pymatrixid.interp_decomp(A, k, rand=False)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
_debug_print("Calling iddr_aid / idzr_aid ...",)
t0 = time.clock()
idx, proj = pymatrixid.interp_decomp(A, k)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
_debug_print("Calling iddr_rid / idzr_rid ...",)
t0 = time.clock()
idx, proj = pymatrixid.interp_decomp(L, k)
t = time.clock() - t0
B = pymatrixid.reconstruct_matrix_from_id(A[:, idx[:k]], idx, proj)
_debug_print(fmt % (t, np.allclose(A, B, eps)))
assert_(np.allclose(A, B, eps))
# check skeleton and interpolation matrices
idx, proj = pymatrixid.interp_decomp(A, k, rand=False)
P = pymatrixid.reconstruct_interp_matrix(idx, proj)
B = pymatrixid.reconstruct_skel_matrix(A, k, idx)
assert_(np.allclose(B, A[:,idx[:k]], eps))
assert_(np.allclose(B.dot(P), A, eps))
# test SVD routines
_debug_print("-----------------------------------------")
_debug_print("SVD routines")
_debug_print("-----------------------------------------")
# fixed precision
_debug_print("Calling iddp_svd / idzp_svd ...",)
t0 = time.clock()
#.........这里部分代码省略.........
开发者ID:hitej,项目名称:meta-core,代码行数:101,代码来源:test_interpolative.py
示例14: time_hilbert
def time_hilbert(self, size):
sl.hilbert(size)
开发者ID:ElDeveloper,项目名称:scipy,代码行数:2,代码来源:linalg.py
示例15:
np.linalg.cond(A)
np.linalg.cond(A_delta)
b=np.matrix('1;1;1') #noise free right hand side
l=.01
k=100
ip.invert(A_delta,b,k,l)
np.linalg.pinv(A_delta)*b
#####################
#Example 3 Hilbert A
#####################
from scipy.linalg import hilbert
A=hilbert(3)
np.linalg.cond(A)
x=np.matrix('1;1;1')
b=A*x
#Now add noise to b of size ro
# dimension of A
r= np.matrix(A.shape)[0,0]
nb= np.random.normal(0, .50, r) #compute vector of normal variants mean=0,std=0.1
#nb= np.random.normal(0, 50, r) #compute vector of normal variants mean=0,std=50
#note that nb is 3 by 1, so we need to flip it
be=b+np.matrix(nb).transpose() #add noise
l=1
k=100
开发者ID:kathrynthegreat,项目名称:InverseProblem,代码行数:30,代码来源:test_problems.py
示例16: isspmatrix
if isspmatrix(m):
m = m.todense()
u, s, vh = svd(m)
if which == 'LM':
ii = np.argsort(s)[-k:]
elif which == 'SM':
ii = np.argsort(s)[:k]
else:
raise ValueError("unknown which=%r" % (which,))
return u[:, ii], s[ii], vh[ii]
def svd_estimate(u, s, vh):
return np.dot(u, np.dot(np.diag(s), vh))
n = 5
x = hilbert(n)
# u,s,vh = svd(x)
# s[2:-1] = 0
# x = svd_estimate(u, s, vh)
which = 'SM'
k = 2
u, s, vh = sorted_svd(x, k, which=which)
su,ss,svh = old_svds(x, k, which=which)
ssu,sss,ssvh = new_svds(x, k, which=which)
m_hat = svd_estimate(u, s, vh)
sm_hat = svd_estimate(su, ss, svh)
ssm_hat = svd_estimate(ssu, sss, ssvh)
开发者ID:apapanico,项目名称:svds,代码行数:31,代码来源:testing3.py
示例17: NumPy
# -*- coding: utf-8 -*-
"""
Created on Wed Sep 25 19:08:23 2013
@author: jschulz1
"""
import numpy as np # NumPy (multidimensional arrays, linear algebra, ...)
import scipy as sp # SciPy (signal and image processing library)
import matplotlib as mpl # Matplotlib (2D/3D plotting library)
import matplotlib.pyplot as plt # Matplotlib's pyplot: MATLAB-like syntax
from pylab import * # Matplotlib's pylab interface
from scipy.linalg import hilbert
A = hilbert(50)
print dot(A[:,2].T,ones((len(A[:,2]),)))
# alternativ
print sum(A[:,2])
开发者ID:laevar,项目名称:mapy,代码行数:19,代码来源:e1a6.py
示例18: mat
r = linalg.norm([ A[j , k] , A[j + 1, k] ], 2)
if r>0:
c=A[j, k]/r; s=A[j + 1, k]/r
A[[j, j + 1],(k + 1):(n+1)] = \
mat([[c, s],[-s, c]])* \
A[[j, j + 1],(k + 1):(n+1)]
A[j, k] = r; A[j+1,k] = 0
z = A[:, n].copy()
rbacksolve(A[:, :n], z, n)
return z
if __name__ == '__main__':
N = 20
H_ = hilbert(N)
xe_ = mat(ones(N)).T
err = empty(N)
errAlt = empty(N)
iterations = arange(N)
for n in iterations:
# H = H_[:n+1, :n+1]; xe = xe_[:n+1]
H = hilbert(n+1); xe = mat(ones(n+1)).T
b = H*xe
x = rotsolve(H, b)
err[n] = linalg.norm(x - xe, 2)
y = rotsolveAlt(H, b)
errAlt[n] = linalg.norm(y - xe, 2)
plt.plot(1+iterations, err, 'b')
plt.plot(1 +iterations, errAlt, 'r')
开发者ID:johanae,项目名称:obliger,代码行数:31,代码来源:rotsolve.py
注:本文中的scipy.linalg.hilbert函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论