r - 高斯牛顿法 R
问题描述
求非线性分布的 MLE(在 R 中,使用 Gauss-Newton 方法):
y = sin(x*theta) + epsilon
where epsilon ~ N(0 , 0.01^2)
为此,我被要求生成一些从 0 <= x <= 10 均匀(和随机)分布的数据,其中 n = 200 和 theta = 2(仅用于生成)。
例如,接近 sin 函数最大值(1、4 等)的值会收敛,但其他值不会。
已编辑我现在了解theta.iter 的含义,但我似乎无法理解为什么它有时甚至在那时收敛,输入哪些值以获得有用的输出。有人可以解释吗?
theta <- 2
x <- runif(200, 0, 10)
x <- sort(x) #this is just to sort the generated data so that plotting it
#actually looks like a sine funciton
y <- sin(x*theta) + rnorm(200, mean = 0, sd = 0.1^2)
GN_sin <- function(theta.iter, x , y, epsilon){
index <- TRUE
while (index){
y.iter <- matrix(y - sin(x*theta.iter), 200, 1)
x.iter <- matrix(theta.iter*cos(x*theta.iter), 200, 1)
theta.new <- theta.iter +
solve(t(x.iter)%*%x.iter)%*%t(x.iter)%*%y.iter
if (abs(theta.new-theta.iter) < epsilon) {index <- FALSE}
theta.iter <- as.vector(theta.new)
cat(theta.iter, '\n')
}
}
解决方案
推荐阅读
- ionic-framework - Ionic 2:NavPop 将我带到 root 而不是上一页
- db2 - DB2 表空间处于恢复挂起状态
- c# - DropDownListFor 选择一个项目并使其被选中
- mysql - COALESCE 不返回所有结果
- node.js - (节点:13606)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝 id:1):[object Object] - 离子框架
- electron - WebRTC 通话音频 - 安静、低沉和掉线
- php - 在 phpv 中的 echo 字段中使用 html 在数据库中添加值
- android - React native android:如何设置 WebChromeClient
- xml - XML 验证:不需要前缀?
- android - 'adb' 未被识别为内部或外部命令