python拐点检测_python – 在样条拟合1d数据中找到拐点

我有一些一维数据,并与样条拟合.然后我想在其中找到拐点(忽略鞍点).现在我通过在splev生成的很多值上使用scipy.signal.argrelmin(和argrelmax)来搜索其第一个派生的极值.

import scipy.interpolate

import scipy.optimize

import scipy.signal

import numpy as np

import matplotlib.pyplot as plt

import operator

y = [-1,5,6,4,2,8,1]

x = np.arange(0,len(y))

tck = scipy.interpolate.splrep(x,y,s=0)

print 'roots',scipy.interpolate.sproot(tck)

# output:

# [0.11381478]

xnew = np.arange(0,len(y),0.01)

ynew = scipy.interpolate.splev(xnew,tck,der=0)

ynew_deriv = scipy.interpolate.splev(xnew,der=1)

min_idxs = scipy.signal.argrelmin(ynew_deriv)

max_idxs = scipy.signal.argrelmax(ynew_deriv)

mins = zip(xnew[min_idxs].tolist(),ynew_deriv[min_idxs].tolist())

maxs = zip(xnew[max_idxs].tolist(),ynew_deriv[max_idxs].tolist())

inflection_points = sorted(mins + maxs,key=operator.itemgetter(0))

print 'inflection_points',inflection_points

# output:

# [(3.13,-2.9822449358974357),# (5.03,4.3817785256410255)

# (7.13,-4.867132628205128)]

plt.legend(['data','Cubic Spline','1st deriv'])

plt.plot(x,'o',xnew,ynew,'-',ynew_deriv,'-')

plt.show()

但这感觉非常错误.我想有可能在没有产生这么多价值的情况下找到我要找的东西.像sproot这样的东西,但也许适用于二次推导?

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值