本文整理汇总了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])