Skip to content

Commit

Permalink
Checking for non-descent direction in qN (#361)
Browse files Browse the repository at this point in the history
* Checking for non-descent direction in qN
* add test, fix tolerance

---------

Co-authored-by: Ronny Bergmann <[email protected]>
  • Loading branch information
mateuszbaran and kellertuer authored Mar 3, 2024
1 parent 5253f86 commit 20d82e3
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@ All notable Changes to the Julia package `Manopt.jl` will be documented in this
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.4.55] unreleased
## [0.4.55] March 3, 2024

### Added

* Option `nondescent_direction_behavior` for quasi-Newton solvers.
By default it checks for non-descent direction which may not be handled well by
some stepsize selection algorithms.

### Fixed

Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Manopt"
uuid = "0fc0a36d-df90-57f3-8f93-d78a9fc72bb5"
authors = ["Ronny Bergmann <[email protected]>"]
version = "0.4.54"
version = "0.4.55"

[deps]
ColorSchemes = "35d6a980-a343-548e-a6ea-1d62b119f2f4"
Expand Down
11 changes: 11 additions & 0 deletions src/solvers/quasi_Newton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ mutable struct QuasiNewtonState{
stop::SC
X_old::T
vector_transport_method::VT
nondescent_direction_behavior::Symbol
end
function QuasiNewtonState(
M::AbstractManifold,
Expand All @@ -77,6 +78,7 @@ function QuasiNewtonState(
retraction_method=retraction_method,
vector_transport_method=vector_transport_method,
),
nondescent_direction_behavior::Symbol=:step_towards_negative_gradient,
kwargs..., # collect but ignore rest to be more tolerant
) where {
P,
Expand All @@ -101,6 +103,7 @@ function QuasiNewtonState(
stopping_criterion,
copy(M, p, initial_vector),
vector_transport_method,
nondescent_direction_behavior,
)
end
function get_message(qns::QuasiNewtonState)
Expand Down Expand Up @@ -200,6 +203,7 @@ The ``k``th iteration consists of
* `stopping_criterion`: ([`StopAfterIteration`](@ref)`(max(1000, memory_size)) | `[`StopWhenGradientNormLess`](@ref)`(1e-6)`)
specify a [`StoppingCriterion`](@ref)
* `vector_transport_method`: (`default_vector_transport_method(M, typeof(p))`) a vector transport to use.
* `nondescent_direction_behavior`: (`:step_towards_negative_gradient`) specify how non-descent direction is handled. Can be either `:ignore` (in which case it is not checked if the selected direction is a descent one) or `:step_towards_negative_gradient` (in which case the direction is replaced with negative gradient).
# Output
Expand Down Expand Up @@ -349,6 +353,13 @@ 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 qns.nondescent_direction_behavior === :step_towards_negative_gradient &&
real(inner(M, qns.p, qns.η, qns.X)) > 0
# reset direction if not a descent one
@warn "Computed direction is not a descent direction; resetting to negative gradient"
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
2 changes: 1 addition & 1 deletion test/solvers/test_convex_bundle_method.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
28 changes: 28 additions & 0 deletions test/solvers/test_quasi_Newton.jl
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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]
Expand Down

2 comments on commit 20d82e3

@kellertuer
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release notes:

Added

  • Option nondescent_direction_behavior for quasi-Newton solvers.
    By default it checks for non-descent direction which may not be handled well by
    some stepsize selection algorithms.

Fixed

  • unified documentation, especially function signatures further.
  • fixed a few typos related to math formulae in the doc strings.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/102155

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.55 -m "<description of version>" 20d82e353539680e4cb6fffafbbadbc230f044ae
git push origin v0.4.55

Please sign in to comment.