本文整理汇总了Python中numpy.polyder方法的典型用法代码示例。如果您正苦于以下问题:Python numpy.polyder方法的具体用法?Python numpy.polyder怎么用?Python numpy.polyder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类numpy
的用法示例。
在下文中一共展示了numpy.polyder方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: data_analysis
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def data_analysis(e_ph, flux, method="least"):
if method == "least":
coeffs = np.polyfit(x=e_ph, y=flux, deg=11)
polynom = np.poly1d(coeffs)
x = np.linspace(e_ph[0], e_ph[-1], num=100)
pd = np.polyder(polynom, m=1)
indx = np.argmax(np.abs(pd(x)))
eph_c = x[indx]
pd2 = np.polyder(polynom, m=2)
p2_roots = np.roots(pd2)
p2_roots = p2_roots[p2_roots[:].imag == 0]
p2_roots = np.real(p2_roots)
Eph_fin = find_nearest(p2_roots,eph_c)
return Eph_fin, polynom
elif method == "new method":
pass
#plt.plot(Etotal, total, "ro")
#plt.plot(x, polynom(x))
示例2: get_minimum_energy_path
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def get_minimum_energy_path(self, pressure=None):
"""
Args:
pressure:
Returns:
"""
if pressure is not None:
raise NotImplemented()
v_min_lst = []
for c in self._coeff.T:
v_min = np.roots(np.polyder(c, 1))
p_der2 = np.polyder(c, 2)
p_val2 = np.polyval(p_der2, v_min)
v_m_lst = v_min[p_val2 > 0]
if len(v_m_lst) > 0:
v_min_lst.append(v_m_lst[0])
else:
v_min_lst.append(np.nan)
return np.array(v_min_lst)
示例3: test_polyder_return_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def test_polyder_return_type(self):
# Ticket #1249
assert_(isinstance(np.polyder(np.poly1d([1]), 0), np.poly1d))
assert_(isinstance(np.polyder([1], 0), np.ndarray))
assert_(isinstance(np.polyder(np.poly1d([1]), 1), np.poly1d))
assert_(isinstance(np.polyder([1], 1), np.ndarray))
示例4: test_polyder_return_type
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def test_polyder_return_type(self):
"""Ticket #1249"""
assert_(isinstance(np.polyder(np.poly1d([1]), 0), np.poly1d))
assert_(isinstance(np.polyder([1], 0), np.ndarray))
assert_(isinstance(np.polyder(np.poly1d([1]), 1), np.poly1d))
assert_(isinstance(np.polyder([1], 1), np.ndarray))
示例5: polyval
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def polyval(fit, points, der=0):
"""Evaluate polynomial generated by :func:`polyfit` on `points`.
Parameters
----------
fit, points : see :func:`polyfit`
der : int, optional
Derivative order. Only for 1D, uses np.polyder().
Notes
-----
For 1D we provide "analytic" derivatives using np.polyder(). For ND, we
didn't implement an equivalent machinery. For 2D, you might get away with
fitting a bispline (see Interpol2D) and use it's derivs. For ND, try rbf.py's RBF
interpolator which has at least 1st derivatives for arbitrary dimensions.
See Also
--------
:class:`PolyFit`, :class:`PolyFit1D`, :func:`polyfit`
"""
assert points.ndim == 2, "points must be 2d array"
pscale, pmin = fit['pscale'], fit['pmin']
vscale, vmin = fit['vscale'], fit['vmin']
if der > 0:
assert points.shape[1] == 1, "deriv only for 1d poly (ndim=1)"
# ::-1 b/c numpy stores poly coeffs in reversed order
dcoeffs = np.polyder(fit['coeffs'][::-1], m=der)
return np.polyval(dcoeffs, (points[:,0] - pmin[0,0]) / pscale[0,0]) / \
pscale[0,0]**der * vscale
else:
vand = vander((points - pmin) / pscale, fit['deg'])
return np.dot(vand, fit['coeffs']) * vscale + vmin
示例6: clean_ftime
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def clean_ftime(ftime,cut_percent=0.25):
'''
ftime 是完成问卷的秒数
思路:
1、只考虑截断问卷完成时间较小的样本
2、找到完成时间变化的拐点,即需要截断的时间点
返回:r
建议截断<r的样本
'''
t_min=int(ftime.min())
t_cut=int(ftime.quantile(cut_percent))
x=np.array(range(t_min,t_cut))
y=np.array([len(ftime[ftime<=i]) for i in range(t_min,t_cut)])
z1 = np.polyfit(x, y, 4) # 拟合得到的函数
z2=np.polyder(z1,2) #求二阶导数
r=np.roots(np.polyder(z2,1))
r=int(r[0])
return r
## ===========================================================
#
#
# 数据分析和输出 #
#
#
## ==========================================================
示例7: func_eq_constraint_der
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def func_eq_constraint_der(coefficients, i, piece_length, order):
result = 0
last_der = np.polyder(coefficients[(i-1)*8:i*8], order)
this_der = np.polyder(coefficients[i*8:(i+1)*8], order)
end_val = np.polyval(last_der, piece_length)
start_val = np.polyval(this_der, 0)
return end_val - start_val
示例8: func_eq_constraint_der_value
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def func_eq_constraint_der_value(coefficients, i, t, desired_value, order):
result = 0
der = np.polyder(coefficients[i*8:(i+1)*8], order)
value = np.polyval(der, t)
return value - desired_value
# def func_eq_constraint(coefficients, tss, yawss):
# result = 0
# last_derivative = None
# for ts, yaws, i in zip(tss, yawss, range(0, len(tss))):
# derivative = np.polyder(coefficients[i*8:(i+1)*8])
# if last_derivative is not None:
# result += np.polyval(derivative, 0) - last_derivative
# last_derivative = np.polyval(derivative, tss[-1])
# # apply coefficients to trajectory
# for i,p in enumerate(traj.polynomials):
# p.pyaw.p = coefficients[i*8:(i+1)*8]
# # evaluate at each timestep and compute the sum of squared differences
# result = 0
# for t,yaw in zip(ts,yaws):
# e = traj.eval(t)
# result += (e.yaw - yaw) ** 2
# return result
示例9: func_eq_constraint_der
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def func_eq_constraint_der(coefficients, i, tss, yawss):
result = 0
last_der = np.polyder(coefficients[(i-1)*8:i*8])
this_der = np.polyder(coefficients[i*8:(i+1)*8])
end_val = np.polyval(last_der, tss[i-1][-1])
start_val = np.polyval(this_der, tss[i][0])
return end_val - start_val
示例10: func_eq_constraint_der_value
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def func_eq_constraint_der_value(coefficients, i, t, desired_value):
result = 0
der = np.polyder(coefficients[i*8:(i+1)*8])
value = np.polyval(der, t)
return value - desired_value
# def func_eq_constraint(coefficients, tss, yawss):
# result = 0
# last_derivative = None
# for ts, yaws, i in zip(tss, yawss, range(0, len(tss))):
# derivative = np.polyder(coefficients[i*8:(i+1)*8])
# if last_derivative is not None:
# result += np.polyval(derivative, 0) - last_derivative
# last_derivative = np.polyval(derivative, tss[-1])
# # apply coefficients to trajectory
# for i,p in enumerate(traj.polynomials):
# p.pyaw.p = coefficients[i*8:(i+1)*8]
# # evaluate at each timestep and compute the sum of squared differences
# result = 0
# for t,yaw in zip(ts,yaws):
# e = traj.eval(t)
# result += (e.yaw - yaw) ** 2
# return result
示例11: localsens
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def localsens(self, coeffs, xi):
""" Determine the local derivative based sensitivity coefficients in the
point of operation xi (normalized coordinates!).
example: xi = np.array([[0,0,...,0]]) size: [1 x DIM]
localsens = calc_localsens(self, coeffs, xi)
input: coeffs ... gpc coefficients, np.array() [N_coeffs x N_out]
xi ... point in variable space to evaluate local sensitivity in
(norm. coordinates) np.array() [1 x DIM]
output: localsens ... local sensitivity coefficients, np.array() [DIM x N_out]
"""
Nmax = len(self.poly)
self.poly_der = [[0 for x in range(self.DIM)] for x in range(Nmax+1)]
poly_der_xi = [[0 for x in range(self.DIM)] for x in range(Nmax+1)]
poly_opvals = [[0 for x in range(self.DIM)] for x in range(Nmax+1)]
# preprocess polynomials
for i_DIM in range(self.DIM):
for i_order in range(Nmax+1):
# evaluate the derivatives of the polynomials
self.poly_der[i_order][i_DIM] = np.polyder(self.poly[i_order][i_DIM])
# evaluate poly and poly_der at point of operation
poly_opvals[i_order][i_DIM] = self.poly[i_order][i_DIM](xi[1,i_DIM])
poly_der_xi[i_order][i_DIM] = self.poly_der[i_order][i_DIM](xi[1,i_DIM])
N_vals = 1
poly_sens = np.zeros([self.DIM, self.N_poly])
for i_sens in range(self.DIM):
for i_poly in range(self.N_poly):
A1 = np.ones(N_vals)
# construct polynomial basis according to partial derivatives
for i_DIM in range(self.DIM):
if i_DIM == i_sens:
A1 *= poly_der_xi[self.poly_idx[i_poly][i_DIM]][i_DIM]
else:
A1 *= poly_opvals[self.poly_idx[i_poly][i_DIM]][i_DIM]
poly_sens[i_sens,i_poly] = A1
# sum up over all coefficients
# [DIM x N_points] = [DIM x N_poly] * [N_poly x N_points]
localsens = np.dot(poly_sens,coeffs)
return localsens
示例12: _do_one_regression
# 需要导入模块: import numpy [as 别名]
# 或者: from numpy import polyder [as 别名]
def _do_one_regression(lams, fluxes, ivars, lvec):
"""
Optimizes to find the scatter associated with the best-fit model.
This scatter is the deviation between the observed spectrum and the model.
It is wavelength-independent, so we perform this at a single wavelength.
Input
-----
lams: numpy ndarray
the common wavelength array
fluxes: numpy ndarray
pixel intensities
ivars: numpy ndarray
inverse variances associated with pixel intensities
lvec = numpy ndarray
the label vector
Output
-----
output of do_one_regression_at_fixed_scatter
"""
ln_scatter_vals = np.arange(np.log(0.0001), 0., 0.5)
# minimize over the range of scatter possibilities
chis_eval = np.zeros_like(ln_scatter_vals)
for jj, ln_scatter_val in enumerate(ln_scatter_vals):
coeff, lTCinvl, chi, logdet_Cinv = \
_do_one_regression_at_fixed_scatter(lams, fluxes, ivars, lvec,
np.exp(ln_scatter_val))
chis_eval[jj] = np.sum(chi*chi) - logdet_Cinv
if np.any(np.isnan(chis_eval)):
best_scatter = np.exp(ln_scatter_vals[-1])
_r = _do_one_regression_at_fixed_scatter(lams, fluxes, ivars, lvec,
best_scatter)
return _r + (best_scatter, )
lowest = np.argmin(chis_eval)
if (lowest == 0) or (lowest == len(ln_scatter_vals) - 1):
best_scatter = np.exp(ln_scatter_vals[lowest])
_r = _do_one_regression_at_fixed_scatter(lams, fluxes, ivars, lvec,
best_scatter)
return _r + (best_scatter, )
ln_scatter_vals_short = ln_scatter_vals[np.array(
[lowest-1, lowest, lowest+1])]
chis_eval_short = chis_eval[np.array([lowest-1, lowest, lowest+1])]
z = np.polyfit(ln_scatter_vals_short, chis_eval_short, 2)
fit_pder = np.polyder(z)
best_scatter = np.exp(np.roots(fit_pder)[0])
_r = _do_one_regression_at_fixed_scatter(lams, fluxes, ivars, lvec,
best_scatter)
return _r + (best_scatter, )