最近在实作梯度下降
想要画出overshooting
https://imgur.com/S8JZMjp
以下是我的过程
x=seq(-3,3,0.01)
plot( x,x^2 ,type = "l" ,xlab = "x",ylab = "f(x)" )
R=10
#eta is learning rate
eta <- 2
#intail guess of x
intail_x <- -3
# objective function
f <- function(x) {x^2}
# partial objective function
partialf <-function(x) {2*x}
x=numeric(length=(R+1))
x[1] <-intail_x
for(i in 1:R){
x[i+1] <- x[i]-eta*partialf(x[i])
}
data.frame(x,y=f(x))
我有以下的点座标
https://imgur.com/JDxy3oK
想要画出跟教科书一样的图 就是第一个点射到第二个点 第二个点在射到第三个点