Skip to content

Commit

Permalink
somewhat fix L-BFGS memory
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Dec 28, 2023
1 parent 99cb471 commit 4ef1dd7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/plans/quasi_newton_plan.jl
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,7 @@ function (d::QuasiNewtonLimitedMemoryDirectionUpdate{InverseBFGS})(r, mp, st)
r .*= -1
return r
end
# backward pass
for i in m:-1:1
# what if we divide by zero here? Setting to zero ignores this in the next step
# precompute in case inner is expensive
Expand Down Expand Up @@ -562,7 +563,9 @@ function (d::QuasiNewtonLimitedMemoryDirectionUpdate{InverseBFGS})(r, mp, st)
r .*= -1
return r
end
r .*= 1 / (d.ρ[last_safe_index] * norm(M, p, d.memory_y[last_safe_index])^2)
# initial scaling guess
r ./= d.ρ[last_safe_index] * norm(M, p, d.memory_y[last_safe_index])^2
# forward pass
for i in eachindex(d.ρ)
if abs(d.ρ[i]) > 0
coeff = d.ξ[i] - d.ρ[i] * inner(M, p, d.memory_y[i], r)
Expand Down
6 changes: 3 additions & 3 deletions src/solvers/quasi_Newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function show(io::IO, qns::QuasiNewtonState)
## Parameters
* direction update: $(status_summary(qns.direction_update))
* retraction method: $(qns.retraction_method)
* vector trnasport method: $(qns.vector_transport_method)
* vector transport method: $(qns.vector_transport_method)
## Stepsize
$(qns.stepsize)
Expand Down Expand Up @@ -617,8 +617,8 @@ function update_hessian!(
end

# add newest
push!(d.memory_s, st.sk)
push!(d.memory_y, st.yk)
push!(d.memory_s, copy(M, st.sk))
push!(d.memory_y, copy(M, st.yk))
return d
end

Expand Down

0 comments on commit 4ef1dd7

Please sign in to comment.