最近在實作梯度下降
想要畫出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
想要畫出跟教科書一樣的圖 就是第一個點射到第二個點 第二個點在射到第三個點