From 9a6f6d1b0524b6b7129c9f4ee7875715e9d5f980 Mon Sep 17 00:00:00 2001 From: Mateusz Baran Date: Fri, 1 Mar 2024 14:14:39 +0100 Subject: [PATCH] add test, fix tolerance --- test/solvers/test_convex_bundle_method.jl | 2 +- test/solvers/test_quasi_Newton.jl | 28 +++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/test/solvers/test_convex_bundle_method.jl b/test/solvers/test_convex_bundle_method.jl index baa7555166..fd7221c3dd 100644 --- a/test/solvers/test_convex_bundle_method.jl +++ b/test/solvers/test_convex_bundle_method.jl @@ -166,7 +166,7 @@ using Manopt: sectional_curvature, ζ_1, ζ_2, close_point ) q = get_solver_result(cbm_s) m = median(M, data) - @test distance(M, q, m) < 1e-2 #with default params this is not very precise + @test distance(M, q, m) < 1.5e-2 #with default params this is not very precise # tst the other stopping criterion mode q2 = convex_bundle_method( M, diff --git a/test/solvers/test_quasi_Newton.jl b/test/solvers/test_quasi_Newton.jl index 8eda9d829a..784d23c6eb 100644 --- a/test/solvers/test_quasi_Newton.jl +++ b/test/solvers/test_quasi_Newton.jl @@ -1,6 +1,18 @@ using Manopt, Manifolds, Test using LinearAlgebra: I, eigvecs, tr, Diagonal +struct QuasiNewtonGradientDirectionUpdate{VT<:AbstractVectorTransportMethod} <: + AbstractQuasiNewtonDirectionUpdate + vector_transport_method::VT +end +function (d::QuasiNewtonGradientDirectionUpdate)(mp, st) + return get_gradient(st) +end +function (d::QuasiNewtonGradientDirectionUpdate)(r, mp, st) + r .= get_gradient(st) + return r +end + @testset "Riemannian quasi-Newton Methods" begin @testset "Show & Status" begin M = Euclidean(4) @@ -357,6 +369,22 @@ using LinearAlgebra: I, eigvecs, tr, Diagonal @test contains(qns.direction_update.message, "gradient") end + @testset "Broken direction update" begin + M = Euclidean(2) + p = [0.0, 1.0] + f(M, p) = sum(p .^ 2) + grad_f(M, p) = 2 * sum(p) + gmp = ManifoldGradientObjective(f, grad_f) + mp = DefaultManoptProblem(M, gmp) + qns = QuasiNewtonState( + M, p; direction_update=QuasiNewtonGradientDirectionUpdate(ParallelTransport()) + ) + @test_logs ( + :warn, + "Computed direction is not a descent direction; resetting to negative gradient", + ) match_mode = :any solve!(mp, qns) + end + @testset "A Circle example" begin M = Circle() data = [-π / 2, π / 4, 0.0, π / 4]