python 插值法对比两组数据

Using python scipy.interpolate for 1d interpolation

You should avoid “A value in x_new is above the interpolation”, which means the range of inserted value (x) must smaller or equel to the basic interpolation value, in order to find the corresponding y.

Because my range of data is unstable, sometimes will above the interpolation range, I pop() the last 2 value of inserted value (x).

from scipy.interpolate import interp1d

# compare the timelength, smaller value timestamp[0] means longer timelength
# shorter interpolate into longer one
if self.__robot1.timestamp[0] < self.__robot2.timestamp[0]: 
	robot_long = self.__robot1
	robot_short = self.__robot2
else:
	robot_long = self.__robot2
	robot_short = self.__robot1

# pop last 2 timestamp, in order to avoid "A value in x_new is above the interpolation "
robot_short.timestamp.pop()
robot_short.timestamp.pop()

# longer one build interpolation dataset
y_long = np.reshape(robot_long.torque[:,joint], len(robot_long.timestamp))
x_long = np.reshape(robot_long.timestamp,len(robot_long.timestamp))
			
x_short = np.reshape(robot_short.timestamp,len(robot_short.timestamp))
			
interpld_func = interp1d(x_long, y_long, kind='quadratic')
y_long = interpld_func(x_short)

y_short = np.reshape(robot_short.torque[:-2,joint], -1)

error = mean_absolute_error(y_short,y_long)
joint_error.append(error)

plt.figure("traj "+str(traj_index)+" joint "+str(joint))
plt.plot(robot_short.timestamp, y_short,  label = robot_short.name)
plt.plot(robot_short.timestamp, y_long, label = robot_long.name)
plt.legend(loc = "best")

在这里插入图片描述
Reference:
插值interpolate模块

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值