计算“肘部”自动且数学地绘制曲线

发布于 2024-10-08 14:50:09 字数 114 浏览 0 评论 0原文

曲线的一个示例如下所示。肘点可能是 x=3 或 4。 如何自动且数学地计算曲线的弯头?

替代文字

One example for curve is shown as below. The elbow point might be x=3 or 4.
How to compute the elbow for a curve automatically and mathematically?

alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

皇甫轩 2024-10-15 14:50:09

我创建了一个 Python package 尝试实现 Kneedle 算法

要重新创建上述函数并检测最大曲率点:

x = range(1,21)
y = [0.065, 0.039, 0.030, 0.024, 0.023, 0.022, 0.019, 0.0185, 0.0187,
     0.016, 0.015, 0.016, 0.0135, 0.0130, 0.0125, 0.0120, 0.0117, 0.0115, 0.0112, 0.013]

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

print(kn.knee)
7
import matplotlib.pyplot as plt
plt.xlabel('x')
plt.ylabel('f(x)')
plt.xticks(range(1,21))
plt.plot(x, y, 'bx-')
plt.vlines(kn.knee, plt.ylim()[0], plt.ylim()[1], linestyles='dashed')

在此处输入图像描述

更新
Kneed 有一种改进的样条拟合方法来处理局部最小值,请使用 interp_method='polynomial'

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

print(kn.knee)
4

新情节:

plt.xlabel('x')
plt.ylabel('f(x)')
plt.xticks(range(1,21))
plt.plot(x, y, 'bx-')
plt.vlines(kn.knee, plt.ylim()[0], plt.ylim()[1], linestyles='dashed')

在此处输入图像描述

I created a Python package that attempts to implement the Kneedle algorithm.

To recreate the function above and detect the point of maximum curvature:

x = range(1,21)
y = [0.065, 0.039, 0.030, 0.024, 0.023, 0.022, 0.019, 0.0185, 0.0187,
     0.016, 0.015, 0.016, 0.0135, 0.0130, 0.0125, 0.0120, 0.0117, 0.0115, 0.0112, 0.013]

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

print(kn.knee)
7
import matplotlib.pyplot as plt
plt.xlabel('x')
plt.ylabel('f(x)')
plt.xticks(range(1,21))
plt.plot(x, y, 'bx-')
plt.vlines(kn.knee, plt.ylim()[0], plt.ylim()[1], linestyles='dashed')

enter image description here

update
Kneed has an improved spline fitting method for handling local minima, use interp_method='polynomial'.

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

print(kn.knee)
4

And the new plot:

plt.xlabel('x')
plt.ylabel('f(x)')
plt.xticks(range(1,21))
plt.plot(x, y, 'bx-')
plt.vlines(kn.knee, plt.ylim()[0], plt.ylim()[1], linestyles='dashed')

enter image description here

画▽骨i 2024-10-15 14:50:09

您可能想要寻找具有最大绝对二阶导数的点,对于您在那里的一组离散点x[i],可以用中心差来近似:

secondDerivative [i] = x[i+1] + x[i-1] - 2 * x[i]

如上所述,您真正想要的是曲率最大的点,但二阶导数就可以了,这个中心差是二阶导数的一个很好的代表。

You might want to look for the point with the maximum absolute second derivative which, for a set of discrete points x[i] as you have there, can be approximated with a central difference:

secondDerivative[i] = x[i+1] + x[i-1] - 2 * x[i]

As noted above, what you really want is the point with maximum curvature, but the second derivative will do, and this central difference is a good proxy for the second derivative.

风流物 2024-10-15 14:50:09

像这样的函数因其形状通常被称为L 曲线。它们在通过正则化解决不适定问题时出现。

“肘”点是曲线上具有最大绝对二阶导数的点。

Functions like this one are usually called L-curves for their shapes. They appear when solving ill-posed problems through regularization.

The 'elbow'-point is the point on the curve with the maximum absolute second derivative.

妄断弥空 2024-10-15 14:50:09

你真正想要的是最大曲率的点。当斜率远小于 1 时,可以通过二阶导数来近似(如 @ebo 指出的),但情况并非总是如此。

What you really want is the point with maximum curvature. When the slope is much smaller than 1, this can be approximated by the second derivative (as @ebo points out), but this is not always the case.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文