python中的膝关节点检测

kneed的Python项目详细描述


跪着

python中的拐点检测

DownloadsDownloadsBinderBuild StatusCodeFactor

这个存储库试图实现kneedle算法,发布了here。给定一组xy值,kneed将返回函数的拐点。膝关节点是最大曲率点。

目录

安装

Tested with Python 3.5 and 3.6

anaconda

$ conda install -c conda-forge kneed

pip

$ pip install kneed

从github克隆

$ git clone https://github.com/arvkevi/kneed.git
$ python setup.py install

用法

这些步骤介绍如何通过从手稿中复制图2来使用kneed

输入数据

DataGenerator类仅作为生成示例数据集的实用程序包含。

Note: x and y must be equal length arrays.

fromkneedimportDataGenerator,KneeLocatorx,y=DataGenerator.figure2()print([round(i,3)foriinx])print([round(i,3)foriiny])[0.0,0.111,0.222,0.333,0.444,0.556,0.667,0.778,0.889,1.0][-5.0,0.263,1.897,2.692,3.163,3.475,3.696,3.861,3.989,4.091]

找到膝盖

膝(或肘)点的计算方法很简单,就是用xy和适当的curvedirection实例化KneeLocator类。 这里,^ {< CD11> }和/或^ {CD12> }存储最大曲率点。

kneedle=KneeLocator(x,y,S=1.0,curve='concave',direction='increasing')print(round(kneedle.knee,3))0.222print(round(kneedle.elbow,3))0.222

可视化

KneeLocator类还有两个用于快速可视化的绘图函数。 注意,所有(x,y)都转换为规范化绘图

# Normalized data, normalized knee, and normalized distance curve.kneedle.plot_knee_normalized()

# Raw data and knee.kneedle.plot_knee()

示例

灵敏度参数

通过设置敏感度参数s可以调整选定的拐点。 摘自手稿:

The sensitivity parameter allows us to adjust how aggressive we want Kneedle to be when detecting knees. Smaller values for S detect knees quicker, while larger values are more conservative. Put simply, S is a measure of how many “flat” points we expect to see in the unmodified data curve before declaring a knee.

importnumpyasnpnp.random.seed(23)sensitivity=[1,3,5,10,100,200,400]knees=[]norm_knees=[]n=1000x=range(1,n+1)y=sorted(np.random.gamma(0.5,1.0,n),reverse=True)forsinsensitivity:kl=KneeLocator(x,y,curve='convex',direction='decreasing',S=s)knees.append(kl.knee)norm_knees.append(kl.norm_knee)print(knees)[43,137,178,258,305,482,482]print([nk.round(2)fornkinnorm_knees])[0.04,0.14,0.18,0.26,0.3,0.48,0.48]importmatplotlib.pyplotaspltplt.style.use('ggplot');plt.figure(figsize=(8,6));plt.plot(kl.x_normalized,kl.y_normalized);plt.plot(kl.x_distance,kl.y_distance);colors=['r','g','k','m','c','orange']fork,c,sinzip(norm_knees,colors,sensitivity):plt.vlines(k,0,1,linestyles='--',colors=c,label=f'S = {s}');plt.legend();

请注意,任何s>;200都将导致上图中482处的膝关节(0.48,标准化)。

多项式拟合

这里是一个“颠簸”或“嘈杂”线的例子,其中默认的^ {< CD14>}样条拟合方法没有提供最大曲率点的最佳估计。 此示例演示设置参数interp_method='polynomial'将通过平滑直线来选择更精确的点。

The argument for interp_method parameter is a string of either "interp1d" or "polynomial".

x=list(range(90))y=[7304,6978,6666,6463,6326,6048,6032,5762,5742,5398,5256,5226,5001,4941,4854,4734,4558,4491,4411,4333,4234,4139,4056,4022,3867,3808,3745,3692,3645,3618,3574,3504,3452,3401,3382,3340,3301,3247,3190,3179,3154,3089,3045,2988,2993,2941,2875,2866,2834,2785,2759,2763,2720,2660,2690,2635,2632,2574,2555,2545,2513,2491,2496,2466,2442,2420,2381,2388,2340,2335,2318,2319,2308,2262,2235,2259,2221,2202,2184,2170,2160,2127,2134,2101,2101,2066,2074,2063,2048,2031]# the default spline fit, `interp_method='interp1d'`kneedle=KneeLocator(x,y,S=1.0,curve='convex',direction='decreasing',interp_method='interp1d')kneedle.plot_knee_normalized()

# The same data, only using a polynomial fit this time.kneedle=KneeLocator(x,y,S=1.0,curve='convex',direction='decreasing',interp_method='polynomial')kneedle.plot_knee_normalized()

噪声高斯

手稿中的图3估计一个NoisyGaussian的膝盖是x=60。 这将模拟5000个NoisyGaussian实例并找到平均值。

knees=[]foriinrange(5):x,y=DataGenerator.noisy_gaussian(mu=50,sigma=10,N=1000)kneedle=KneeLocator(x,y,curve='concave',direction='increasing',interp_method='polynomial')knees.append(kneedle.knee)# average knee pointround(sum(knees)/len(knees),3)60.921

选择k个簇

找出k-均值聚类中使用的最优聚类数(k)。 请参阅tutorial in the notebooks目录。

KneeLocator(x,y,curve='convex',direction='decreasing')

贡献

欢迎投稿,如果你有建议或想作出改进,请提交一个问题或拉要求。

引文

大海捞针: 系统行为中膝关节点的检测 萨托帕维尔 ~ ,珍妮·阿尔布雷希特™ 大卫·欧文 ,和Barath Raghavan™ 马萨诸塞州威廉斯敦威廉姆斯学院 马萨诸塞大学阿默斯特分校 ?。 加州伯克利国际计算机科学研究所

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java操作数组上的字符串   java JAXB内容未实例化   图形在Java中如何绘制垂直居中的字符串?   java Apache Ant:使用Junit时出现NoClassDefFoundError   java无法从服务器上运行perl脚本   如何在java中沿树进行预排序遍历,并打印0和1以对应每个节点上的特定字符?   java如何创建。p12文件?   java线程访问无效   java只匹配命名空间中的XML节点,而不知道NS前缀   从java获取2d arraylist元素   数组Java动态集合对象   java Xpath通过通配符或布尔运算查找以相同名称开头的节点?   java注释元素类型   java在中看不到Super()。反编译后的类文件