Skip to content

Commit

Permalink
Fix Shortstep for zero direction (#435)
Browse files Browse the repository at this point in the history
* Fix Shortstep for d=0
---------

Co-authored-by: Mathieu Besançon <[email protected]>
  • Loading branch information
JannisHal and matbesancon authored Oct 10, 2023
1 parent 6be7c09 commit 4ade11e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/linesearch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,12 @@ function perform_line_search(
workspace,
memory_mode,
)
dd = fast_dot(d, d)
if dd <= eps(float(dd))
return dd
end

return min(max(fast_dot(gradient, d) * inv(line_search.L * fast_dot(d, d)), 0), gamma_max)
return min(max(fast_dot(gradient, d) * inv(line_search.L * dd), 0), gamma_max)
end

Base.print(io::IO, ::Shortstep) = print(io, "Shortstep")
Expand Down
13 changes: 13 additions & 0 deletions test/alternating_methods_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,19 @@ lmo3 = FrankWolfe.ScaledBoundLInfNormBall(ones(n), 2 * ones(n))
@test abs(x[1, 1]) < 1e-6
@test abs(x[1, 2]) < 1e-6

# test the edge case with a zero vector as direction for the step size computation
x, _, _, _, _ = FrankWolfe.alternating_linear_minimization(
FrankWolfe.block_coordinate_frank_wolfe,
x -> 0,
(storage, x) -> zero(x),
(lmo1, lmo3),
ones(n),
line_search=FrankWolfe.Shortstep(2),
)

@test norm(x[:,1] - zeros(n)) < 1e-6
@test norm(x[:,2] - ones(n)) < 1e-6

x, _, _, _, _, traj_data = FrankWolfe.alternating_linear_minimization(
FrankWolfe.block_coordinate_frank_wolfe,
f,
Expand Down

0 comments on commit 4ade11e

Please sign in to comment.