• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python interpolate.PiecewisePolynomial类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中scipy.interpolate.PiecewisePolynomial的典型用法代码示例。如果您正苦于以下问题:Python PiecewisePolynomial类的具体用法?Python PiecewisePolynomial怎么用?Python PiecewisePolynomial使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了PiecewisePolynomial类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_scalar

 def test_scalar(self):
     P = PiecewisePolynomial(self.xi,self.yi,3)
     assert_almost_equal(P(self.test_xs[0]),self.spline_ys[0])
     assert_almost_equal(P.derivative(self.test_xs[0],1),self.spline_yps[0])
     assert_almost_equal(P(np.array(self.test_xs[0])),self.spline_ys[0])
     assert_almost_equal(P.derivative(np.array(self.test_xs[0]),1),
                         self.spline_yps[0])
开发者ID:AGPeddle,项目名称:scipy,代码行数:7,代码来源:test_polyint.py


示例2: test_shapes_scalarvalue_derivative

 def test_shapes_scalarvalue_derivative(self):
     P = PiecewisePolynomial(self.xi,self.yi,4)
     n = 4
     assert_array_equal(np.shape(P.derivative(0,1)), ())
     assert_array_equal(np.shape(P.derivative(np.array(0),1)), ())
     assert_array_equal(np.shape(P.derivative([0],1)), (1,))
     assert_array_equal(np.shape(P.derivative([0,1],1)), (2,))
开发者ID:AGPeddle,项目名称:scipy,代码行数:7,代码来源:test_polyint.py


示例3: test_derivatives

 def test_derivatives(self):
     P = PiecewisePolynomial(self.xi, self.yi, 3)
     m = 4
     r = P.derivatives(self.test_xs, m)
     # print r.shape, r
     for i in xrange(m):
         assert_almost_equal(P.derivative(self.test_xs, i), r[i])
开发者ID:huard,项目名称:scipy-work,代码行数:7,代码来源:test_polyint.py


示例4: test_incremental

    def test_incremental(self):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            P = PiecewisePolynomial([self.xi[0]], [self.yi[0]], 3)

        for i in xrange(1,len(self.xi)):
            P.append(self.xi[i],self.yi[i],3)
        assert_almost_equal(P(self.test_xs),self.spline_ys)
开发者ID:hitej,项目名称:meta-core,代码行数:8,代码来源:test_polyint.py


示例5: test_wrapper

 def test_wrapper(self):
     P = PiecewisePolynomial(self.xi, self.yi)
     assert_almost_equal(P(self.test_xs), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs))
     assert_almost_equal(
         P.derivative(self.test_xs, 2), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs, der=2)
     )
     assert_almost_equal(
         P.derivatives(self.test_xs, 2), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs, der=[0, 1])
     )
开发者ID:huard,项目名称:scipy-work,代码行数:9,代码来源:test_polyint.py


示例6: test_scalar

    def test_scalar(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi, self.yi, 3)

        assert_almost_equal(P(self.test_xs[0]), self.spline_ys[0])
        assert_almost_equal(P.derivative(self.test_xs[0], 1), self.spline_yps[0])
        assert_almost_equal(P(np.array(self.test_xs[0])), self.spline_ys[0])
        assert_almost_equal(P.derivative(np.array(self.test_xs[0]), 1), self.spline_yps[0])
开发者ID:BioSoundSystems,项目名称:scipy,代码行数:9,代码来源:test_polyint.py


示例7: test_shapes_vectorvalue_derivative

    def test_shapes_vectorvalue_derivative(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi, np.multiply.outer(self.yi, np.arange(3)), 4)

        n = 4
        assert_array_equal(np.shape(P.derivative(0, 1)), (3,))
        assert_array_equal(np.shape(P.derivative([0], 1)), (1, 3))
        assert_array_equal(np.shape(P.derivative([0, 1], 1)), (2, 3))
开发者ID:BioSoundSystems,项目名称:scipy,代码行数:9,代码来源:test_polyint.py


示例8: test_vector

 def test_vector(self):
     xs = [0, 1, 2]
     ys = [[[0, 1]], [[1, 0], [-1, -1]], [[2, 1]]]
     P = PiecewisePolynomial(xs, ys)
     Pi = [PiecewisePolynomial(xs, [[yd[i] for yd in y] for y in ys]) for i in xrange(len(ys[0][0]))]
     test_xs = np.linspace(-1, 3, 100)
     assert_almost_equal(P(test_xs), np.rollaxis(np.asarray([p(test_xs) for p in Pi]), -1))
     assert_almost_equal(
         P.derivative(test_xs, 1), np.transpose(np.asarray([p.derivative(test_xs, 1) for p in Pi]), (1, 0))
     )
开发者ID:huard,项目名称:scipy-work,代码行数:10,代码来源:test_polyint.py


示例9: test_derivatives

    def test_derivatives(self):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi,self.yi,3)

        m = 4
        r = P.derivatives(self.test_xs,m)
        #print r.shape, r
        for i in xrange(m):
            assert_almost_equal(P.derivative(self.test_xs,i),r[i])
开发者ID:hitej,项目名称:meta-core,代码行数:10,代码来源:test_polyint.py


示例10: test_shapes_scalarvalue_derivative

    def test_shapes_scalarvalue_derivative(self):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi,self.yi,4)

        n = 4
        assert_array_equal(np.shape(P.derivative(0,1)), ())
        assert_array_equal(np.shape(P.derivative(np.array(0),1)), ())
        assert_array_equal(np.shape(P.derivative([0],1)), (1,))
        assert_array_equal(np.shape(P.derivative([0,1],1)), (2,))
开发者ID:hitej,项目名称:meta-core,代码行数:10,代码来源:test_polyint.py


示例11: test_wrapper

    def test_wrapper(self):
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi, self.yi)

        assert_almost_equal(P(self.test_xs), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs))
        assert_almost_equal(
            P.derivative(self.test_xs, 2), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs, der=2)
        )
        assert_almost_equal(
            P.derivatives(self.test_xs, 2), piecewise_polynomial_interpolate(self.xi, self.yi, self.test_xs, der=[0, 1])
        )
开发者ID:BioSoundSystems,项目名称:scipy,代码行数:12,代码来源:test_polyint.py


示例12: test_vector

    def test_vector(self):
        xs = [0, 1, 2]
        ys = [[[0, 1]], [[1, 0], [-1, -1]], [[2, 1]]]
        with warnings.catch_warnings():
            warnings.filterwarnings("ignore", category=DeprecationWarning)
            P = PiecewisePolynomial(xs, ys)
            Pi = [PiecewisePolynomial(xs, [[yd[i] for yd in y] for y in ys]) for i in xrange(len(ys[0][0]))]

        test_xs = np.linspace(-1, 3, 100)
        assert_almost_equal(P(test_xs), np.rollaxis(np.asarray([p(test_xs) for p in Pi]), -1))
        assert_almost_equal(
            P.derivative(test_xs, 1), np.transpose(np.asarray([p.derivative(test_xs, 1) for p in Pi]), (1, 0))
        )
开发者ID:BioSoundSystems,项目名称:scipy,代码行数:13,代码来源:test_polyint.py


示例13: _create_from_control_points

    def _create_from_control_points(self, control_points, tangents, scale):
        """
        Creates the FiberSource instance from control points, and a specified 
        mode to compute the tangents.

        Parameters
        ----------
        control_points : ndarray shape (N, 3)
        tangents : 'incoming', 'outgoing', 'symmetric'
        scale : multiplication factor. 
            This is useful when the coodinates are given dimensionless, and we 
            want a specific size for the phantom.
        """
        # Compute instant points ts, from 0. to 1. 
        # (time interval proportional to distance between control points)
        nb_points = control_points.shape[0]
        dists = np.zeros(nb_points)
        dists[1:] = np.sqrt((np.diff(control_points, axis=0) ** 2).sum(1))
        ts = dists.cumsum()
        length = ts[-1]
        ts = ts / np.max(ts)

        # Create interpolation functions (piecewise polynomials) for x, y and z
        derivatives = np.zeros((nb_points, 3))

        # The derivatives at starting and ending points are normal
        # to the surface of a sphere.
        derivatives[0, :] = -control_points[0]
        derivatives[-1, :] = control_points[-1]
 
        # As for other derivatives, we use discrete approx
        if tangents == 'incoming':
            derivatives[1:-1, :] = (control_points[1:-1] - control_points[:-2])
        elif tangents == 'outgoing':
            derivatives[1:-1, :] = (control_points[2:] - control_points[1:-1])
        elif tangents == 'symmetric':
            derivatives[1:-1, :] = (control_points[2:] - control_points[:-2])
        else:
            raise Error('tangents should be one of the following: incoming, ' 
                        'outgoing, symmetric')
 
        derivatives = (derivatives.T / np.sqrt((derivatives ** 2).sum(1))).T \
                    * length
               
        self.x_poly = PiecewisePolynomial(ts, 
               scale * np.vstack((control_points[:, 0], derivatives[:, 0])).T)
        self.y_poly = PiecewisePolynomial(ts, 
               scale * np.vstack((control_points[:, 1], derivatives[:, 1])).T)
        self.z_poly = PiecewisePolynomial(ts, 
               scale * np.vstack((control_points[:, 2], derivatives[:, 2])).T)
开发者ID:daducci,项目名称:phantomas,代码行数:50,代码来源:fiber.py


示例14: __init__

    def __init__(self, x, y, axis=0):
        x = np.asarray(x)
        y = np.asarray(y)

        axis = axis % y.ndim

        xp = x.reshape((x.shape[0],) + (1,)*(y.ndim-1))
        yp = np.rollaxis(y, axis)

        data = np.empty((yp.shape[0], 2) + yp.shape[1:], y.dtype)
        data[:,0] = yp
        data[:,1] = self._get_derivatives(xp, yp)

        s = list(range(2, y.ndim + 1))
        s.insert(axis, 1)
        s.insert(axis, 0)
        data = data.transpose(s)

        PiecewisePolynomial.__init__(self, x, data, orders=3, direction=None,
                                     axis=axis)
开发者ID:nikelsj11,项目名称:Studying,代码行数:20,代码来源:HermiteInterpolation.py


示例15: compute_positions_velocities

    def compute_positions_velocities(self, times, x_positions_velocities, y_positions_velocities, z_positions_velocities): 
        xinterpolator = PiecewisePolynomial(times, x_positions_velocities, orders=3, direction=1)
        yinterpolator = PiecewisePolynomial(times, y_positions_velocities, orders=3, direction=1)
        zinterpolator = PiecewisePolynomial(times, z_positions_velocities, orders=3, direction=1)
        
        T = np.arange(0, times[-1], self.dt)
        n = len(T)

        precomputed_positions = np.empty((3,n))
        precomputed_positions[0,:] = xinterpolator(T)
        precomputed_positions[1,:] = yinterpolator(T)
        precomputed_positions[2,:] = zinterpolator(T)

        precomputed_velocities = np.empty((3,n))
        precomputed_velocities[0,:] = xinterpolator.derivative(T)
        precomputed_velocities[1,:] = yinterpolator.derivative(T)
        precomputed_velocities[2,:] = zinterpolator.derivative(T)

        return T, precomputed_positions, precomputed_velocities, n
开发者ID:ChristoSilvia,项目名称:cs4752_proj2,代码行数:19,代码来源:joint_action_server.py


示例16: test_derivative

    def test_derivative(self):
        with warnings.catch_warnings():
            warnings.filterwarnings('ignore', category=DeprecationWarning)
            P = PiecewisePolynomial(self.xi,self.yi,3)

        assert_almost_equal(P.derivative(self.test_xs,1),self.spline_yps)
开发者ID:hitej,项目名称:meta-core,代码行数:6,代码来源:test_polyint.py


示例17: move_trajectory

    def move_trajectory(self, times, x_positions_velocities, y_positions_velocities, z_positions_velocities):
                
        xinterpolator = PiecewisePolynomial(times, x_positions_velocities, orders=3, direction=1)
        yinterpolator = PiecewisePolynomial(times, y_positions_velocities, orders=3, direction=1)
        zinterpolator = PiecewisePolynomial(times, z_positions_velocities, orders=3, direction=1)
        
        T = np.arange(0, times[-1], self.dt)
        n = len(T)

        velocity_and_w = np.zeros(6)
        velocity_and_w[0] = xinterpolator.derivative(T[0])
        velocity_and_w[1] = yinterpolator.derivative(T[0])
        velocity_and_w[2] = zinterpolator.derivative(T[0])

        precomputed_positions = np.empty((3,n))
        precomputed_positions[0,:] = xinterpolator(T)
        precomputed_positions[1,:] = yinterpolator(T)
        precomputed_positions[2,:] = zinterpolator(T)

        precomputed_velocities = np.empty((3,n))
        precomputed_velocities[0,:] = xinterpolator.derivative(T)
        precomputed_velocities[1,:] = yinterpolator.derivative(T)
        precomputed_velocities[2,:] = zinterpolator.derivative(T)

        actual_positions = np.empty((3,n))
        actual_positions[:,0] = self.get_position()

        corrector_velocities = np.empty((3,n))
        corrector_velocities[:,0] = np.zeros(3)
        
        proportional_velocities = np.empty((3,n))
        proportional_velocities[:,0] = np.zeros(3)

        integral_velocities = np.empty((3,n)) 
        integral_velocities[:,0] = np.zeros(3)

        derivative_velocities = np.empty((3,n))
        derivative_velocities[:,0] = np.zeros(3)

        vx_proportional, vy_proportional, vz_proportional = 0.0, 0.0, 0.0
        last_vx_proportional, last_vy_proportional, last_vz_proportional = 0.0, 0.0, 0.0
        vx_integral, vy_integral, vz_integral = 0.0, 0.0, 0.0

        for i in xrange(1,n):
            t_start = rospy.get_time()
            self.limb.set_joint_velocities(
                self.make_joint_dict(
                    self.get_joint_velocities(velocity_and_w)))

            time_interval = T[i] - T[i-1]           
 
            position = self.get_position()
            vx_proportional = precomputed_positions[0,i] - position[0]
            vy_proportional = precomputed_positions[1,i] - position[1]
            vz_proportional = precomputed_positions[2,i] - position[2]
            proportional_velocities = self.kp * np.array([vx_proportional, vy_proportional, vz_proportional])

            vx_integral += vx_proportional * time_interval
            vy_integral += vy_proportional * time_interval
            vz_integral += vz_proportional * time_interval
            integral_velocities = self.ki * np.array([vx_integral, vy_integral, vz_integral])

            vx_derivative = (vx_proportional - last_vx_proportional)/time_interval
            vy_derivative = (vy_proportional - last_vy_proportional)/time_interval
            vz_derivative = (vz_proportional - last_vz_proportional)/time_interval
            derivative_velocities = self.kd * np.array([vx_derivative, vy_derivative, vz_derivative])
            
            vx_corrector = self.kp * vx_proportional + self.ki * vx_integral + self.kd * vx_derivative 
            vy_corrector = self.kp * vy_proportional + self.ki * vy_integral + self.kd * vy_derivative 
            vz_corrector = self.kp * vz_proportional + self.ki * vz_integral + self.kd * vz_derivative 
            corrector_velocities[:,i] = np.array([vx_corrector, vy_corrector, vz_corrector])
           
            velocity_and_w[0] = precomputed_velocities[0,i] + vx_corrector
            velocity_and_w[1] = precomputed_velocities[1,i] + vy_corrector 
            velocity_and_w[2] = precomputed_velocities[2,i] + vz_corrector

            last_vx_proportional = vx_proportional
            last_vy_proportional = vy_proportional
            last_vz_proportional = vz_proportional

            actual_positions[:,i] = position
 
            end_time = time_interval + t_start
            loginfo("Computation Took: {0} out of {1} seconds".format(rospy.get_time() - t_start, time_interval))
            rospy.sleep(end_time - rospy.get_time())

        loginfo("exit_control_mode")
   
        self.limb.exit_control_mode()    
             
  
        paramtext = "%1.4f_%1.4f_%1.4f_%1.4f_%1.4f" % (self.kp, self.ki, self.kd, self.extra_motion_maximum, self.extra_motion_multiple)
        # date = ""
        date = str(datetime.now())
        folder = "tests"
        A = np.empty((n,4))
        A[:,0] = T
        A[:,1:] = actual_positions.T
        # np.savetxt("/home/cs4752/ros_ws/src/cs4752_proj2/{2}/{1}actual-positions-{0}.csv".format(paramtext,date,folder),A)
        B = np.empty((n,4))
#.........这里部分代码省略.........
开发者ID:ChristoSilvia,项目名称:cs4752_proj2,代码行数:101,代码来源:joint_action_server.py


示例18: test_shapes_vectorvalue_derivative

 def test_shapes_vectorvalue_derivative(self):
     P = PiecewisePolynomial(self.xi, np.multiply.outer(self.yi, np.arange(3)), 4)
     n = 4
     assert_array_equal(np.shape(P.derivative(0, 1)), (3,))
     assert_array_equal(np.shape(P.derivative([0], 1)), (1, 3))
     assert_array_equal(np.shape(P.derivative([0, 1], 1)), (2, 3))
开发者ID:huard,项目名称:scipy-work,代码行数:6,代码来源:test_polyint.py


示例19: test_derivative

 def test_derivative(self):
     P = PiecewisePolynomial(self.xi, self.yi, 3)
     assert_almost_equal(P.derivative(self.test_xs, 1), self.spline_yps)
开发者ID:huard,项目名称:scipy-work,代码行数:3,代码来源:test_polyint.py


示例20: test_incremental

 def test_incremental(self):
     P = PiecewisePolynomial([self.xi[0]], [self.yi[0]], 3)
     for i in xrange(1, len(self.xi)):
         P.append(self.xi[i], self.yi[i], 3)
     assert_almost_equal(P(self.test_xs), self.spline_ys)
开发者ID:huard,项目名称:scipy-work,代码行数:5,代码来源:test_polyint.py



注:本文中的scipy.interpolate.PiecewisePolynomial类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python interpolate.RectBivariateSpline类代码示例发布时间:2022-05-27
下一篇:
Python interpolate.PPoly类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap