0

You can see my below curve has multiple elbow points. Currently I am using two algorithm to find the elbow points and both of then found the 2nd elbow point which has x value of 10. I'd like to find the first elbow point at x=0.6. so question is how to find these 2 elbow points.

The algorithms I have tested out are here:

find the "elbow point" on an optimization curve with Python

Finding the best trade-off point on a curve

I prefer the 2nd algorithm which is easy to implement and no other parameters to adjust which is listed here as well. Thanks for your help.

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)

enter image description here

roudan
  • 3,082
  • 5
  • 31
  • 72
  • 1
    are you sure that x=0.6 is an "elbow point"? (not familiar with the term, but I assume "a point from where the trend of the curve changes"). Only 2-3 datapoints can be seen before that, which are stretched out due to the logarithmic x-axis. If plotted linearly, this region would look similar to x = 1.4 and x=3. I guess providing the full dataset would help finding a suitable algorithm. – Christian Karcher Sep 16 '22 at 05:50

0 Answers0