當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.polyder方法代碼示例

本文整理匯總了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)) 
開發者ID:ocelot-collab,項目名稱:ocelot,代碼行數:26,代碼來源:k_analysis.py

示例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) 
開發者ID:pyiron,項目名稱:pyiron,代碼行數:24,代碼來源:thermo_bulk.py

示例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)) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:8,代碼來源:test_regression.py

示例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)) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:8,代碼來源:test_regression.py

示例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 
開發者ID:elcorto,項目名稱:pwtools,代碼行數:34,代碼來源:num.py

示例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



## ===========================================================
#
#
#                     數據分析和輸出                          #
#
#
## ========================================================== 
開發者ID:gasongjian,項目名稱:reportgen,代碼行數:30,代碼來源:questionnaire.py

示例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 
開發者ID:whoenig,項目名稱:uav_trajectories,代碼行數:10,代碼來源:generate_trajectory.py

示例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 
開發者ID:whoenig,項目名稱:uav_trajectories,代碼行數:28,代碼來源:generate_trajectory.py

示例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 
開發者ID:whoenig,項目名稱:uav_trajectories,代碼行數:10,代碼來源:auto_yaw_trajectory.py

示例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 
開發者ID:whoenig,項目名稱:uav_trajectories,代碼行數:28,代碼來源:auto_yaw_trajectory.py

示例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 
開發者ID:simnibs,項目名稱:simnibs,代碼行數:53,代碼來源:ni.py

示例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, ) 
開發者ID:annayqho,項目名稱:TheCannon,代碼行數:55,代碼來源:train_model.py


注:本文中的numpy.polyder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。