本文整理匯總了Python中numpy.polynomial.chebyshev.chebfit方法的典型用法代碼示例。如果您正苦於以下問題:Python chebyshev.chebfit方法的具體用法?Python chebyshev.chebfit怎麽用?Python chebyshev.chebfit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類numpy.polynomial.chebyshev
的用法示例。
在下文中一共展示了chebyshev.chebfit方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_chebfit
# 需要導入模塊: from numpy.polynomial import chebyshev [as 別名]
# 或者: from numpy.polynomial.chebyshev import chebfit [as 別名]
def test_chebfit(self) :
def f(x) :
return x*(x - 1)*(x - 2)
# Test exceptions
assert_raises(ValueError, cheb.chebfit, [1], [1], -1)
assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0)
assert_raises(TypeError, cheb.chebfit, [], [1], 0)
assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0)
assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0)
assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0)
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]])
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
y = f(x)
#
coef3 = cheb.chebfit(x, y, 3)
assert_equal(len(coef3), 4)
assert_almost_equal(cheb.chebval(x, coef3), y)
#
coef4 = cheb.chebfit(x, y, 4)
assert_equal(len(coef4), 5)
assert_almost_equal(cheb.chebval(x, coef4), y)
#
coef2d = cheb.chebfit(x, np.array([y, y]).T, 3)
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
# test weighting
w = np.zeros_like(x)
yw = y.copy()
w[1::2] = 1
y[0::2] = 0
wcoef3 = cheb.chebfit(x, yw, 3, w=w)
assert_almost_equal(wcoef3, coef3)
#
wcoef2d = cheb.chebfit(x, np.array([yw, yw]).T, 3, w=w)
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
# test scaling with complex values x points whose square
# is zero when summed.
x = [1, 1j, -1, -1j]
assert_almost_equal(cheb.chebfit(x, x, 1), [0, 1])
示例2: th_plot
# 需要導入模塊: from numpy.polynomial import chebyshev [as 別名]
# 或者: from numpy.polynomial.chebyshev import chebfit [as 別名]
def th_plot(data, tt):
fields = 'concurence', 'iops_mediana', 'lat_mediana'
conc_4k = filter_data('concurrence_test_' + tt, fields, blocksize='4k')
filtered_data = sorted(list(conc_4k(data)))
x, iops, lat = zip(*filtered_data)
_, ax1 = plt.subplots()
xnew = np.linspace(min(x), max(x), 50)
# plt.plot(xnew, power_smooth, 'b-', label='iops')
ax1.plot(x, iops, 'b*')
for degree in (3,):
c = chebfit(x, iops, degree)
vals = chebval(xnew, c)
ax1.plot(xnew, vals, 'g--')
# ax1.set_xlabel('thread count')
# ax1.set_ylabel('iops')
# ax2 = ax1.twinx()
# lat = [i / 1000 for i in lat]
# ax2.plot(x, lat, 'r*')
# tck = splrep(x, lat, s=0.0)
# power_smooth = splev(xnew, tck)
# ax2.plot(xnew, power_smooth, 'r-', label='lat')
# xp = xnew[0]
# yp = power_smooth[0]
# for _x, _y in zip(xnew[1:], power_smooth[1:]):
# if _y >= 100:
# xres = (_y - 100.) / (_y - yp) * (_x - xp) + xp
# ax2.plot([xres, xres], [min(power_smooth), max(power_smooth)], 'g--')
# break
# xp = _x
# yp = _y
# ax2.plot([min(x), max(x)], [20, 20], 'g--')
# ax2.plot([min(x), max(x)], [100, 100], 'g--')
# ax2.set_ylabel("lat ms")
# plt.legend(loc=2)
示例3: test_chebfit
# 需要導入模塊: from numpy.polynomial import chebyshev [as 別名]
# 或者: from numpy.polynomial.chebyshev import chebfit [as 別名]
def test_chebfit(self):
def f(x):
return x*(x - 1)*(x - 2)
# Test exceptions
assert_raises(ValueError, cheb.chebfit, [1], [1], -1)
assert_raises(TypeError, cheb.chebfit, [[1]], [1], 0)
assert_raises(TypeError, cheb.chebfit, [], [1], 0)
assert_raises(TypeError, cheb.chebfit, [1], [[[1]]], 0)
assert_raises(TypeError, cheb.chebfit, [1, 2], [1], 0)
assert_raises(TypeError, cheb.chebfit, [1], [1, 2], 0)
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[[1]])
assert_raises(TypeError, cheb.chebfit, [1], [1], 0, w=[1, 1])
# Test fit
x = np.linspace(0, 2)
y = f(x)
#
coef3 = cheb.chebfit(x, y, 3)
assert_equal(len(coef3), 4)
assert_almost_equal(cheb.chebval(x, coef3), y)
#
coef4 = cheb.chebfit(x, y, 4)
assert_equal(len(coef4), 5)
assert_almost_equal(cheb.chebval(x, coef4), y)
#
coef2d = cheb.chebfit(x, np.array([y, y]).T, 3)
assert_almost_equal(coef2d, np.array([coef3, coef3]).T)
# test weighting
w = np.zeros_like(x)
yw = y.copy()
w[1::2] = 1
y[0::2] = 0
wcoef3 = cheb.chebfit(x, yw, 3, w=w)
assert_almost_equal(wcoef3, coef3)
#
wcoef2d = cheb.chebfit(x, np.array([yw, yw]).T, 3, w=w)
assert_almost_equal(wcoef2d, np.array([coef3, coef3]).T)
# test scaling with complex values x points whose square
# is zero when summed.
x = [1, 1j, -1, -1j]
assert_almost_equal(cheb.chebfit(x, x, 1), [0, 1])