如何在曲线中找到多个拐点?

21 浏览
0 Comments

如何在曲线中找到多个拐点?

您可以看到下面的曲线有多个拐点。目前我正在使用两种算法来找到这些拐点,它们都找到了第二个拐点,其x值为10。我想找到第一个拐点,即x=0.6。问题是如何找到这两个拐点。\n我测试过的算法如下:\nfind the \"elbow point\" on an optimization curve with Python\nFinding the best trade-off point on a curve\n我更喜欢第二个算法,它易于实现,而且没有其他需要调整的参数,下面也列出了这个算法。谢谢您的帮助。\n

def find_elbow(allCoord):
    # https://stackoverflow.com/questions/18062135/combining-two-series-into-a-dataframe-in-pandas
    # allcord is a array
    import numpy.matlib    # need to ne import separately
    nPoints=len(allCoord)
    firstPoint = allCoord[0]
    lineVec = allCoord[-1] - allCoord[0]
    lineVecNorm = lineVec / np.sqrt(np.sum(lineVec**2))
    vecFromFirst = allCoord - firstPoint
    scalarProduct = np.sum(vecFromFirst*numpy.matlib.repmat(lineVecNorm, nPoints, 1), axis=1)
    vecFromFirstParallel = np.outer(scalarProduct, lineVecNorm)
    vecToLine = vecFromFirst - vecFromFirstParallel
    distToLine = np.sqrt(np.sum(vecToLine ** 2, axis=1))
    idxOfBestPoint = np.argmax(distToLine)
    x_elbow= allCoord[idxOfBestPoint,0]
    y_elbow= allCoord[idxOfBestPoint,1]
    return idxOfBestPoint,x_elbow,y_elbow
        x=delta_time_seconds
        y=delta_data.iloc[:,inx].values
        df1=pd.concat([pd.Series(np.log10(x).tolist()),pd.Series(y)],axis=1)
        data_curve_array=df1.iloc[1:,:].to_numpy()
        inx_elbow,x_elbow,y_elbow=find_elbow(data_curve_array)

\n\"enter

0