首页 > 解决方案 > 高斯牛顿法 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')

 }
}

标签: rmle

解决方案


推荐阅读