Skip to content

Commit

Permalink
convex hull
Browse files Browse the repository at this point in the history
  • Loading branch information
matbesancon committed Oct 10, 2023
1 parent 6be7c09 commit 83c1b7b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/polytope_oracles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,26 @@ function compute_extreme_point(
v[idx] = ifelse(lower, lmo.lower_bounds[idx], lmo.upper_bounds[idx])
return v
end

"""
ConvexHullOracle{AT,VT}
Convex hull of a finite number of vertices of type `AT`, stored in a vector of type `VT`.
"""
struct ConvexHullOracle{AT, VT <: AbstractVector{AT}}
vertices::VT
end

function compute_extreme_point(lmo::ConvexHullOracle{AT}, direction; v=nothing, kwargs...) where {AT}
T = promote_type(eltype(direction), eltype(AT))
best_val = T(Inf)
best_vertex = first(lmo.vertices)
for vertex in lmo.vertices
val = dot(vertex, direction)
if val < best_val
best_val = val
best_vertex = vertex
end
end
return best_vertex
end
17 changes: 17 additions & 0 deletions test/lmo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -788,3 +788,20 @@ end
xv = JuMP.value.(x)
@test dot(xv, d) dot(v, d) atol=1e-5*n
end

@testset "Convex hull" begin
lmo = FrankWolfe.ConvexHullOracle([
[1, 0, 0],
[0, 1, 0],
[0, 0, 1],
])
for _ in 1:100
d = randn(3)
v = FrankWolfe.compute_extreme_point(lmo, d)
v_simplex = FrankWolfe.compute_extreme_point(FrankWolfe.ProbabilitySimplexOracle(1), d)
@test v == v_simplex
end
d = zeros(3)
v = FrankWolfe.compute_extreme_point(lmo, d)
@test v == lmo.vertices[1]
end

0 comments on commit 83c1b7b

Please sign in to comment.