From 64d23279beb38db25a05e0fc76537e76d8ae948d Mon Sep 17 00:00:00 2001 From: Sebastian Pokutta <23001135+pokutta@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:42:39 +0200 Subject: [PATCH 1/4] quick and dirty changes --- examples/birkhoff_polytope.jl | 2 +- examples/open_loop.jl | 77 +++++++++++++++++++++++++++++++++++ src/afw.jl | 2 +- src/blended_cg.jl | 2 +- src/fw_algorithms.jl | 6 +-- src/pairwise.jl | 2 +- 6 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 examples/open_loop.jl diff --git a/examples/birkhoff_polytope.jl b/examples/birkhoff_polytope.jl index a3709f66b..393ba7174 100644 --- a/examples/birkhoff_polytope.jl +++ b/examples/birkhoff_polytope.jl @@ -81,4 +81,4 @@ x0 = deepcopy(x00) data = [trajectoryBCG] label = ["BCG"] -plot_trajectories(data, label) +plot_trajectories(data, label, reduce_size=true, marker_shapes=[:dtriangle]) diff --git a/examples/open_loop.jl b/examples/open_loop.jl new file mode 100644 index 000000000..6c0edbb01 --- /dev/null +++ b/examples/open_loop.jl @@ -0,0 +1,77 @@ +using LinearAlgebra +using FrankWolfe + +include("../examples/plot_utils.jl") + +n = 10000 +k = 500 +@info "Seed $s" +Random.seed!(s) + + +# strongly convex set +xp2 = 10 * ones(n) +diag_term = 100 * rand(n) +covariance_matrix = zeros(n,n) + LinearAlgebra.Diagonal(diag_term) +lmo2 = FrankWolfe.EllipsoidLMO(covariance_matrix) + +f2(x) = norm(x - xp2)^2 +function grad2!(storage, x) + @. storage = 2 * (x - xp2) +end + +x0 = FrankWolfe.compute_extreme_point(lmo2, randn(n)) + +res_2 = FrankWolfe.frank_wolfe( + f2, + grad2!, + lmo2, + copy(x0), + max_iteration=k, + line_search=FrankWolfe.Agnostic(2), + print_iter= k / 10, + epsilon=1e-5, + verbose=true, + trajectory=true, +) + +res_4 = FrankWolfe.frank_wolfe( + f2, + grad2!, + lmo2, + copy(x0), + max_iteration=k, + line_search=FrankWolfe.Agnostic(4), + print_iter= k / 10, + epsilon=1e-5, + verbose=true, + trajectory=true, +) + +res_6 = FrankWolfe.frank_wolfe( + f2, + grad2!, + lmo2, + copy(x0), + max_iteration=k, + line_search=FrankWolfe.Agnostic(6), + print_iter= k / 10, + epsilon=1e-5, + verbose=true, + trajectory=true, +) + +res_10 = FrankWolfe.frank_wolfe( + f2, + grad2!, + lmo2, + copy(x0), + max_iteration=k, + line_search=FrankWolfe.Agnostic(10), + print_iter=k / 10, + epsilon=1e-5, + verbose=true, + trajectory=true, +) + +plot_trajectories([res_2[end], res_4[end], res_6[end], res_10[end]], ["ell = 2 (default)", "ell = 4", "ell = 6", "ell = 10"], marker_shapes=[:dtriangle, :rect, :circle, :pentagon]) \ No newline at end of file diff --git a/src/afw.jl b/src/afw.jl index ee96824f5..428a26029 100644 --- a/src/afw.jl +++ b/src/afw.jl @@ -155,7 +155,7 @@ function away_frank_wolfe( println( "GRADIENTTYPE: $grad_type LAZY: $lazy lazy_tolerance: $lazy_tolerance MOMENTUM: $momentum AWAYSTEPS: $away_steps", ) - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if (use_extra_vertex_storage || add_dropped_vertices) && extra_vertex_storage === nothing @warn( "use_extra_vertex_storage and add_dropped_vertices options are only usable with a extra_vertex_storage storage" diff --git a/src/blended_cg.jl b/src/blended_cg.jl index 2b5e43154..7275a93a6 100644 --- a/src/blended_cg.jl +++ b/src/blended_cg.jl @@ -170,7 +170,7 @@ function blended_conditional_gradient( ) grad_type = typeof(gradient) println("GRADIENTTYPE: $grad_type lazy_tolerance: $lazy_tolerance") - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if (use_extra_vertex_storage || add_dropped_vertices) && extra_vertex_storage === nothing @warn( diff --git a/src/fw_algorithms.jl b/src/fw_algorithms.jl index daddb6145..7ac79402a 100644 --- a/src/fw_algorithms.jl +++ b/src/fw_algorithms.jl @@ -82,7 +82,7 @@ function frank_wolfe( ) grad_type = typeof(gradient) println("MOMENTUM: $momentum GRADIENTTYPE: $grad_type") - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if memory_mode isa InplaceEmphasis @info("In memory_mode memory iterates are written back into x0!") end @@ -330,7 +330,7 @@ function lazified_conditional_gradient( ) grad_type = typeof(gradient) println("GRADIENTTYPE: $grad_type CACHESIZE $cache_size GREEDYCACHE: $greedy_lazy") - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if memory_mode isa InplaceEmphasis @info("In memory_mode memory iterates are written back into x0!") end @@ -570,7 +570,7 @@ function stochastic_frank_wolfe( println( "GRADIENTTYPE: $(typeof(f.storage)) MOMENTUM: $(momentum_iterator !== nothing) batch policy: $(typeof(batch_iterator)) ", ) - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if memory_mode isa InplaceEmphasis @info("In memory_mode memory iterates are written back into x0!") end diff --git a/src/pairwise.jl b/src/pairwise.jl index 1f401405b..2450f43ac 100644 --- a/src/pairwise.jl +++ b/src/pairwise.jl @@ -138,7 +138,7 @@ function blended_pairwise_conditional_gradient( ) grad_type = typeof(gradient) println("GRADIENTTYPE: $grad_type LAZY: $lazy lazy_tolerance: $lazy_tolerance") - println("Linear Minimization Oracle: $(typeof(lmo))") + println("LMO: $(typeof(lmo))") if use_extra_vertex_storage && !lazy @info("vertex storage only used in lazy mode") end From 78746b2c3c7974ef5a1f17481dec8fdf2b4828bf Mon Sep 17 00:00:00 2001 From: Sebastian Pokutta <23001135+pokutta@users.noreply.github.com> Date: Fri, 29 Sep 2023 17:46:27 +0200 Subject: [PATCH 2/4] typo --- examples/open_loop.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/open_loop.jl b/examples/open_loop.jl index 6c0edbb01..1a7da8502 100644 --- a/examples/open_loop.jl +++ b/examples/open_loop.jl @@ -5,6 +5,7 @@ include("../examples/plot_utils.jl") n = 10000 k = 500 +s = 97 @info "Seed $s" Random.seed!(s) From 5aebeb7179fbcd64f03946873423ff71881079ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathieu=20Besan=C3=A7on?= Date: Fri, 29 Sep 2023 17:57:42 +0200 Subject: [PATCH 3/4] Update examples/open_loop.jl --- examples/open_loop.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/open_loop.jl b/examples/open_loop.jl index 1a7da8502..28d68e118 100644 --- a/examples/open_loop.jl +++ b/examples/open_loop.jl @@ -75,4 +75,4 @@ res_10 = FrankWolfe.frank_wolfe( trajectory=true, ) -plot_trajectories([res_2[end], res_4[end], res_6[end], res_10[end]], ["ell = 2 (default)", "ell = 4", "ell = 6", "ell = 10"], marker_shapes=[:dtriangle, :rect, :circle, :pentagon]) \ No newline at end of file +plot_trajectories([res_2[end], res_4[end], res_6[end], res_10[end]], ["ell = 2 (default)", "ell = 4", "ell = 6", "ell = 10"], marker_shapes=[:dtriangle, :rect, :circle, :pentagon]) From 2bafbe00e72f422084829288f3f61426a19c69c3 Mon Sep 17 00:00:00 2001 From: Sebastian Pokutta <23001135+pokutta@users.noreply.github.com> Date: Sat, 30 Sep 2023 13:08:58 +0200 Subject: [PATCH 4/4] fix forgotten random --- examples/open_loop.jl | 1 + 1 file changed, 1 insertion(+) diff --git a/examples/open_loop.jl b/examples/open_loop.jl index 28d68e118..e7f8617b7 100644 --- a/examples/open_loop.jl +++ b/examples/open_loop.jl @@ -1,5 +1,6 @@ using LinearAlgebra using FrankWolfe +using Random include("../examples/plot_utils.jl")