# NOT RUN {
# Create an optimizer
opt <- make_mize(method = "L-BFGS")
# Function to optimize and starting point defined after creating optimizer
rosenbrock_fg <- list(
fn = function(x) {
100 * (x[2] - x[1] * x[1])^2 + (1 - x[1])^2
},
gr = function(x) {
c(
-400 * x[1] * (x[2] - x[1] * x[1]) - 2 * (1 - x[1]),
200 * (x[2] - x[1] * x[1])
)
}
)
rb0 <- c(-1.2, 1)
# Initialize with function and starting point before commencing optimization
opt <- mize_init(opt, rb0, rosebrock_fg)
# Finally, can commence the optimization loop
par <- rb0
for (iter in 1:3) {
res <- mize_step(opt, par, rosenbrock_fg)
par <- res$par
opt <- res$opt
}
# }
Run the code above in your browser using DataLab