Skip to content

Commit

Permalink
not a descent direction?!?
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuszbaran committed Jan 16, 2024
1 parent 30a0b6d commit 377d242
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
19 changes: 11 additions & 8 deletions benchmarks/benchmark_comparison.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ using ProfileView
using BenchmarkTools
using Plots
using ManoptExamples
using ImprovedHagerZhangLinesearch

"""
StopWhenGradientInfNormLess <: StoppingCriterion
Expand Down Expand Up @@ -221,7 +222,7 @@ function generate_cmp(
for N in N_vals
f, g!, f_manopt, g_manopt! = problem_for_N(N)
println("Benchmarking for N=$N, f=$(typeof(f))")

M = manifold_maker(manifold_name, N, :Manopt)
x0 = zeros(N)
x0[1] = 1
manopt_time, manopt_iters, manopt_obj = benchmark_time_state(
Expand All @@ -231,9 +232,10 @@ function generate_cmp(
f_manopt,
g_manopt!,
x0,
Manopt.LineSearchesStepsize(ls_hz),
HagerZhangLinesearch(M),
mem_len,
gtol,
gtol;
vector_transport_method=ParallelTransport(),
)

push!(times_manopt, manopt_time)
Expand Down Expand Up @@ -285,22 +287,23 @@ end
# generate_cmp(generate_rayleigh_problem, manifold_names=[:Sphere], mem_len=4)

function test_case_manopt()
N = 4
mem_len = 2
M = Manifolds.Euclidean(N)
N = 128
mem_len = 1
M = Manifolds.Sphere(N - 1)
ls_hz = LineSearches.HagerZhang()

x0 = zeros(N)
x0[1] = 0
x0[1] = 1
manopt_sc = StopWhenGradientInfNormLess(1e-6) | StopAfterIteration(1000)

return quasi_Newton(
M,
f_rosenbrock_manopt,
g_rosenbrock_manopt!,
x0;
stepsize=Manopt.LineSearchesStepsize(ls_hz),
stepsize=HagerZhangLinesearch(M),
evaluation=InplaceEvaluation(),
vector_transport_method=ProjectionTransport(),
return_state=true,
memory_size=mem_len,
stopping_criterion=manopt_sc,
Expand Down
5 changes: 5 additions & 0 deletions src/solvers/quasi_Newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,11 @@ function step_solver!(mp::AbstractManoptProblem, qns::QuasiNewtonState, iter)
M = get_manifold(mp)
get_gradient!(mp, qns.X, qns.p)
qns.direction_update(qns.η, mp, qns)
if real(inner(M, qns.p, qns.η, qns.X)) > 0
# reset direction if not a descent one
copyto!(M, qns.η, qns.X)
qns.η .*= -1
end
α = qns.stepsize(mp, qns, iter, qns.η)
copyto!(M, qns.p_old, get_iterate(qns))
retract!(M, qns.p, qns.p, qns.η, α, qns.retraction_method)
Expand Down

0 comments on commit 377d242

Please sign in to comment.