用R?

用R?,r,ggplot2,curve-fitting,R,Ggplot2,Curve Fitting,相关: 这个问题试图找到最小/最大y(斜率=0);我想找到最小/最大值 作为背景,我正在进行一些不同的建模技术,我想在迭代神经网络结果时,我可能会使用slope来衡量由随机种子生成的最佳模型 获取数据: nn <- read.csv("http://pastebin.com/raw.php?i=6SSCb3QR", header=T) rbf <- read.csv("http://pastebin.com/raw.php?i=hfmY1g46", header=T) 类似地,这

相关:
这个问题试图找到最小/最大y(斜率=0);我想找到最小/最大值

作为背景,我正在进行一些不同的建模技术,我想在迭代神经网络结果时,我可能会使用slope来衡量由随机种子生成的最佳模型

获取数据:

nn <- read.csv("http://pastebin.com/raw.php?i=6SSCb3QR", header=T)
rbf <- read.csv("http://pastebin.com/raw.php?i=hfmY1g46", header=T)

类似地,这里有一个rbf模型:

ggplot(rbf, aes(x=x, y=y, colour=factor(group))) + 
geom_point() + stat_smooth(method="loess", se=F)

RBF模型对数据拟合较好,与变量的背景知识吻合较好。我想尝试计算拟合线的最小/最大坡度,以便修剪出陡峭悬崖与较平缓曲线的NN。识别交叉线是另一种修剪方法,但这是另一个问题

谢谢你的建议



注意:我在这里使用了
ggplot2
,并相应地为问题添加了标签,但这并不意味着它不能通过其他功能完成。我只是想直观地说明我为什么要这么做。我想循环可以用y1-y0/x1-x0实现这一点,但也许有更好的方法。

我认为最简单的解决方案是使用一阶差分(使用函数
diff
)作为一阶导数的近似值

slope.loess <-function(X, data){
    # First your loess function:
    my_loess <- loess(y~x, data=data, subset=data$group==X, degree=2)
    # Then the first difference
    first_diff <- diff(my_loess$fitted)
    # Then the corresponding x and y values for the minima and maxima
    res <- cbind(my_loess$x[c(which.min(first_diff), which.max(first_diff))], 
            my_loess$fitted[c(which.min(first_diff), which.max(first_diff))])
    colnames(res) <- c("x", "y")
    rownames(res) <- c("min", "max")
    res
    }

#Then apply the function to each group
slope.rbf <- lapply(levels(rbf$group), FUN=slope.loess, data=rbf)
names(slope.rbf) <- levels(rbf$group)

slope.rbf
$A
           x        y
min 3.310345 20.30981
max 7.724138 18.47787

$B
           x        y
min 3.310345 21.75368
max 7.724138 20.06883

$C
           x        y
min 3.310345 23.53051
max 7.724138 21.47636

$D
           x        y
min 4.413793 25.02747
max 0.000000 26.22230

$E
           x        y
min 4.413793 27.45100
max 0.000000 27.39809

slope.alluch我自己正在为超快交易编写一个神经网络。一开始我用黄土或洛维斯拟合时间序列,但我想要的是平滑导数,黄土不能提供。甚至,如果您自己实现黄土,并对每个点使用正交多项式来计算导数,您会得到奇怪的结果。这是有原因的

你的问题可以在Graciela Boente的一篇论文中找到解决方案:回归函数高阶导数的稳健估计。公式见第3页。这篇论文可以在互联网上免费获得。一旦获得了值和导数,就可以使用它来唯一地定义三次样条曲线,这将给出连续的导数


我不熟悉R

对于类似的情况,请参见:numericDeriv(my_Leash$y)
足够吗?@CarlWitthoft:我对R不够熟悉,不知道my_Leash会是什么。@Hendy抱歉:这是对象
Leash
返回的缩写,即
my Leash@CarlWitthoft我需要传递更多选项吗?我按照你的建议做了我的工作
slope.loess <-function(X, data){
    # First your loess function:
    my_loess <- loess(y~x, data=data, subset=data$group==X, degree=2)
    # Then the first difference
    first_diff <- diff(my_loess$fitted)
    # Then the corresponding x and y values for the minima and maxima
    res <- cbind(my_loess$x[c(which.min(first_diff), which.max(first_diff))], 
            my_loess$fitted[c(which.min(first_diff), which.max(first_diff))])
    colnames(res) <- c("x", "y")
    rownames(res) <- c("min", "max")
    res
    }

#Then apply the function to each group
slope.rbf <- lapply(levels(rbf$group), FUN=slope.loess, data=rbf)
names(slope.rbf) <- levels(rbf$group)

slope.rbf
$A
           x        y
min 3.310345 20.30981
max 7.724138 18.47787

$B
           x        y
min 3.310345 21.75368
max 7.724138 20.06883

$C
           x        y
min 3.310345 23.53051
max 7.724138 21.47636

$D
           x        y
min 4.413793 25.02747
max 0.000000 26.22230

$E
           x        y
min 4.413793 27.45100
max 0.000000 27.39809