Created
November 16, 2021 11:25
-
-
Save pat-alt/26729245384a4f87e72f363f978e652e to your computer and use it in GitHub Desktop.
Newton's method with Arminjo backtracking in Julia language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Newton's Method | |
function arminjo(๐, g_t, ฮธ_t, d_t, args, ฯ, c=1e-4) | |
๐(ฮธ_t .+ ฯ .* d_t, args...) <= ๐(ฮธ_t, args...) .+ c .* ฯ .* d_t'g_t | |
end | |
function newton(๐, ฮธ, โ๐, โโ๐, args; max_iter=100, ฯ=1e-5) | |
# Intialize: | |
converged = false # termination state | |
t = 1 # iteration count | |
ฮธ_t = ฮธ # initial parameters | |
# Descent: | |
while !converged && t<max_iter | |
global g_t = โ๐(ฮธ_t, args...) # gradient | |
global H_t = โโ๐(ฮธ_t, args...) # hessian | |
converged = all(abs.(g_t) .< ฯ) && isposdef(H_t) # check first-order condition | |
# If not converged, descend: | |
if !converged | |
d_t = -inv(H_t)*g_t # descent direction | |
# Line search: | |
ฯ_t = 1.0 # initialize at 1.0 | |
count = 1 | |
while !arminjo(๐, g_t, ฮธ_t, d_t, args, ฯ_t) | |
ฯ_t /= 2 | |
end | |
ฮธ_t = ฮธ_t .+ ฯ_t .* d_t # update parameters | |
end | |
t += 1 | |
end | |
# Output: | |
return ฮธ_t, H_t | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment