簡體   English   中英

在曲線中找到肘部/膝蓋

[英]Finding the elbow/knee in a curve

我有這些數據:

x <- c(6.626,6.6234,6.6206,6.6008,6.5568,6.4953,6.4441,6.2186,6.0942,5.8833,5.702,5.4361,5.0501,4.744,4.1598,3.9318,3.4479,3.3462,3.108,2.8468,2.3365,2.1574,1.899,1.5644,1.3072,1.1579,0.95783,0.82376,0.67734,0.34578,0.27116,0.058285)

y <- c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32)

看起來像:

plot(x,y)

在此處輸入圖片說明

我想找到一種方法讓肘部/膝蓋點在x=6.5左右

我認為擬合loess曲線然后取二階導數可能有效,但是:

plot(x,predict(loess(y ~ x)),type="l")

在此處輸入圖片說明

看起來它不會完成這項工作。

任何的想法?

我認為你想找到函數y=f(x)的導數在值上有巨大跳躍的點。 您可以嘗試以下操作,如您所見,根據我們選擇的閾值(對於巨大跳躍),可以有一個或多個這樣的點:

get.elbow.points.indices <- function(x, y, threshold) {
  d1 <- diff(y) / diff(x) # first derivative
  d2 <- diff(d1) / diff(x[-1]) # second derivative
  indices <- which(abs(d2) > threshold)  
  return(indices)
}

# first approximate the function, since we have only a few points
ap <- approx(x, y, n=1000, yleft=min(y), yright=max(y))
x <- ap$x
y <- ap$y

indices <- get.elbow.points.indices(x, y, 1e4) # threshold for huge jump = 1e4
x[indices]
#[1] 6.612851 # there is one such point
plot(x, y, pch=19)
points(x[indices], y[indices], pch=19, col='red')

在此處輸入圖片說明

 indices <- get.elbow.points.indices(x, y, 1e3) # threshold for huge jump = 1e3
 x[indices]
 #[1] 0.3409794 6.4353456 6.5931286 6.6128514 # there are 4 such points
 plot(x, y, pch=19)
 points(x[indices], y[indices], pch=19, col='red')

在此處輸入圖片說明

您現在可以通過使用soilphysics 包中maxcurv函數使用不同的方法找到膝蓋/肘部。

有這個圖書館

https://www.rdocumentation.org/packages/SamSPECTRAL/versions/1.26.0/topics/kneepointDetection

        if (!requireNamespace("BiocManager", quietly = TRUE))
            install.packages("BiocManager")

        BiocManager::install("SamSPECTRAL")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM