Python numpy.polyder() Examples
The following are 26
code examples of numpy.polyder().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: k_analysis.py From ocelot with GNU General Public License v3.0 | 6 votes |
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))
Example #2
Source File: thermo_bulk.py From pyiron with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #3
Source File: test_regression.py From pySINDy with MIT License | 5 votes |
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))
Example #4
Source File: test_regression.py From keras-lambda with MIT License | 5 votes |
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))
Example #5
Source File: test_regression.py From twitter-stock-recommendation with MIT License | 5 votes |
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))
Example #6
Source File: test_regression.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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))
Example #7
Source File: auto_yaw_trajectory.py From uav_trajectories with MIT License | 5 votes |
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
Example #8
Source File: auto_yaw_trajectory.py From uav_trajectories with MIT License | 5 votes |
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
Example #9
Source File: generate_trajectory.py From uav_trajectories with MIT License | 5 votes |
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
Example #10
Source File: generate_trajectory.py From uav_trajectories with MIT License | 5 votes |
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
Example #11
Source File: test_regression.py From coffeegrindsize with MIT License | 5 votes |
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))
Example #12
Source File: test_regression.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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))
Example #13
Source File: questionnaire.py From reportgen with MIT License | 5 votes |
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 ## =========================================================== # # # æ°æ®åæåèŸåº # # # ## ==========================================================
Example #14
Source File: test_regression.py From ImageFusion with MIT License | 5 votes |
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))
Example #15
Source File: test_regression.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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))
Example #16
Source File: test_regression.py From predictive-maintenance-using-machine-learning with Apache License 2.0 | 5 votes |
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))
Example #17
Source File: test_regression.py From GraphicDesignPatternByPython with MIT License | 5 votes |
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))
Example #18
Source File: num.py From pwtools with BSD 3-Clause "New" or "Revised" License | 5 votes |
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
Example #19
Source File: test_regression.py From Mastering-Elasticsearch-7.0 with MIT License | 5 votes |
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))
Example #20
Source File: test_regression.py From Computable with MIT License | 5 votes |
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))
Example #21
Source File: test_regression.py From vnpy_crypto with MIT License | 5 votes |
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))
Example #22
Source File: test_regression.py From auto-alt-text-lambda-api with MIT License | 5 votes |
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))
Example #23
Source File: test_regression.py From lambda-packs with MIT License | 5 votes |
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))
Example #24
Source File: test_regression.py From recruit with Apache License 2.0 | 5 votes |
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))
Example #25
Source File: ni.py From simnibs with GNU General Public License v3.0 | 4 votes |
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
Example #26
Source File: train_model.py From TheCannon with MIT License | 4 votes |
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, )