Skip to content

Commit e2fc841

Browse files
committed
fix a few issues with quasi-Newton
1 parent 853f377 commit e2fc841

2 files changed

Lines changed: 29 additions & 6 deletions

File tree

src/plans/box_plan.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ end
8585

8686
function initialize_update!(ha::QuasiNewtonLimitedMemoryBoxDirectionUpdate)
8787
initialize_update!(ha.qn_du)
88+
ha.last_gcp_result = :not_searched
8889
return ha
8990
end
9091

@@ -652,8 +653,7 @@ function find_generalized_cauchy_direction!(gcp::GeneralizedCauchyDirectionFinde
652653
dt_min = max(dt_min, 0.0)
653654
t_old = t_old + dt_min
654655
d_out .*= t_old
655-
set_stepsize_bound!(M, d_out, p, ts, t_current)
656-
656+
set_stepsize_bound!(M, d_out, p, ts, t_old)
657657
if has_finite_limit
658658
return :found_limited
659659
else

src/solvers/quasi_Newton.jl

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,15 @@ function quasi_Newton!(
389389
end
390390
calls_with_kwargs(::typeof(quasi_Newton!)) = (decorate_objective!, decorate_state!)
391391

392+
function _get_max_stepsize(M::AbstractManifold, qns::QuasiNewtonState)
393+
current_max_stepsize = get_parameter(qns.direction_update, Val(:max_stepsize))
394+
if !isnothing(current_max_stepsize) && !isfinite(current_max_stepsize)
395+
return max_stepsize(M, qns.p) / norm(qns.η)
396+
else
397+
return current_max_stepsize
398+
end
399+
end
400+
392401
function initialize_solver!(amp::AbstractManoptProblem, qns::QuasiNewtonState)
393402
M = get_manifold(amp)
394403
get_gradient!(amp, qns.X, qns.p)
@@ -401,10 +410,7 @@ function step_solver!(mp::AbstractManoptProblem, qns::QuasiNewtonState, k)
401410
M = get_manifold(mp)
402411
get_gradient!(mp, qns.X, qns.p)
403412
qns.direction_update(qns.η, mp, qns)
404-
current_max_stepsize = get_parameter(qns.direction_update, Val(:max_stepsize))
405-
if !isnothing(current_max_stepsize) && !isfinite(current_max_stepsize)
406-
current_max_stepsize = max_stepsize(M, qns.p) / norm(qns.η)
407-
end
413+
current_max_stepsize = _get_max_stepsize(M, qns)
408414
if !(qns.nondescent_direction_behavior === :ignore)
409415
qns.nondescent_direction_value = real(inner(M, qns.p, qns.η, qns.X))
410416
if qns.nondescent_direction_value >= 0
@@ -416,6 +422,12 @@ function step_solver!(mp::AbstractManoptProblem, qns::QuasiNewtonState, k)
416422
if qns.nondescent_direction_behavior === :reinitialize_direction_update
417423
initialize_update!(qns.direction_update)
418424
end
425+
# update direction after reinitialization to get a valid one
426+
if qns.nondescent_direction_behavior === :step_towards_negative_gradient ||
427+
qns.nondescent_direction_behavior === :reinitialize_direction_update
428+
qns.direction_update(qns.η, mp, qns)
429+
current_max_stepsize = _get_max_stepsize(M, qns)
430+
end
419431
end
420432
end
421433
local α # COV_EXCL_LINE
@@ -802,6 +814,17 @@ function update_hessian!(
802814
end
803815

804816
if reforming_required
817+
# we need to move first vectors in memory too because they most likely won't be
818+
# overwritten by new pairs
819+
if start == 2
820+
vector_transport_to!(
821+
M, d.memory_s[1], p_old, d.memory_s[1], p, d.vector_transport_method
822+
)
823+
vector_transport_to!(
824+
M, d.memory_y[1], p_old, d.memory_y[1], p, d.vector_transport_method
825+
)
826+
fill_rho_i!(M, p, d, 1)
827+
end
805828
_drop_zero_rho_vectors!(d)
806829
end
807830

0 commit comments

Comments
 (0)