Skip to content

Commit

Permalink
Merge pull request #223 from ZIB-IOL/fixing-BCG-bug
Browse files Browse the repository at this point in the history
Fixed nasty bug in rankone arithmetic
  • Loading branch information
pokutta authored Jul 20, 2021
2 parents dfba2f6 + 2559316 commit c779c0b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
34 changes: 29 additions & 5 deletions examples/nuclear_norm.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,29 @@ v0 = FrankWolfe.compute_extreme_point(lmo, gradient)

const k = 500

x00 = copy(x0)

xfin, vmin, _, _, traj_data = FrankWolfe.frank_wolfe(
f,
grad!,
lmo,
x0;
x00;
epsilon=1e7,
max_iteration=k,
print_iter=k / 10,
trajectory=true,
verbose=true,
linesearch_tol=1e-7,
line_search=FrankWolfe.Adaptive(),
emphasis=FrankWolfe.memory,
gradient=spzeros(size(x0)...),
)

xfinlcg, vmin, _, _, traj_data = FrankWolfe.lazified_conditional_gradient(
f,
grad!,
lmo,
x00;
epsilon=1e7,
max_iteration=k,
print_iter=k / 10,
Expand All @@ -81,11 +99,13 @@ xfin, vmin, _, _, traj_data = FrankWolfe.frank_wolfe(
)


x00 = copy(x0)

xfinAFW, vmin, _, _, traj_data = FrankWolfe.away_frank_wolfe(
f,
grad!,
lmo,
x0;
x00;
epsilon=1e7,
max_iteration=k,
print_iter=k / 10,
Expand All @@ -97,12 +117,13 @@ xfinAFW, vmin, _, _, traj_data = FrankWolfe.away_frank_wolfe(
emphasis=FrankWolfe.memory,#,
)

x00 = copy(x0)

xfinBCG, vmin, _, _, traj_data = FrankWolfe.blended_conditional_gradient(
f,
grad!,
lmo,
x0;
x00;
epsilon=1e7,
max_iteration=k,
print_iter=k / 10,
Expand All @@ -113,9 +134,12 @@ xfinBCG, vmin, _, _, traj_data = FrankWolfe.blended_conditional_gradient(
emphasis=FrankWolfe.memory,#,
)

plot(svdvals(xfin), label="FW", width=3, yaxis=:log)
plot!(svdvals(xfinAFW), label="AFW", width=3, yaxis=:log)
pit = plot(svdvals(xfin), label="FW", width=3, yaxis=:log)
plot!(svdvals(xfinlcg), label="LCG", width=3, yaxis=:log)
plot!(svdvals(xfinAFW), label="LAFW", width=3, yaxis=:log)
plot!(svdvals(xfinBCG), label="BCG", width=3, yaxis=:log)
plot!(svdvals(xgd), label="Gradient descent", width=3, yaxis=:log)
plot!(svdvals(Xreal), label="Real matrix", linestyle=:dash, width=3, color=:black)
title!("Singular values")

savefig(pit, "matrix_completion.pdf")
4 changes: 2 additions & 2 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ end

Base.:-(x::RankOneMatrix) = RankOneMatrix(-x.u, x.v)

Base.:*(x::Number, m::RankOneMatrix) = RankOneMatrix(-x * m.u, m.v)
Base.:*(m::RankOneMatrix, x::Number) = RankOneMatrix(-x * m.u, m.v)
Base.:*(x::Number, m::RankOneMatrix) = RankOneMatrix(x * m.u, m.v)
Base.:*(m::RankOneMatrix, x::Number) = RankOneMatrix(x * m.u, m.v)

Base.@propagate_inbounds function Base.:+(a::RankOneMatrix, b::RankOneMatrix)
@boundscheck size(a) == size(b) || throw(DimensionMismatch())
Expand Down
6 changes: 6 additions & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ end
r2 = M * x
@test r1 r2
end
@testset "Identity test" begin
x = 1.0
r1 = R
r2 = R * x
@test r1 r2
end
@testset "Add and sub" begin
@test M + R R + R
@test M - R R - R
Expand Down

0 comments on commit c779c0b

Please sign in to comment.