Skip to content

Commit f0f14b2

Browse files
committed
improve compute_gap method
1 parent 44afabe commit f0f14b2

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

src/Utils/Utils.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ using LinearAlgebra: dot
88
using SCIP: SCIP
99
using SimpleWeightedGraphs: SimpleWeightedDiGraph
1010
using StatsBase: StatsBase
11+
using Statistics: mean
1112

1213
include("data_sample.jl")
1314
include("interface.jl")

src/Utils/interface.jl

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -137,21 +137,20 @@ function compute_gap(
137137
bench::AbstractBenchmark,
138138
dataset::AbstractVector{<:DataSample},
139139
statistical_model,
140-
maximizer;
141-
percentage::Bool=false,
140+
maximizer,
141+
op=mean,
142142
)
143-
res = 0.0
144143
check = is_minimization_problem(bench)
145144

146-
for sample in dataset
147-
target_obj = objective_value(bench, sample)
148-
x = sample.x
149-
θ = statistical_model(x)
150-
y = maximizer(θ; maximizer_kwargs(bench, sample)...)
151-
obj = objective_value(bench, sample, y)
152-
Δ = check ? obj - target_obj : target_obj - obj
153-
res += Δ / abs(target_obj)
154-
end
155-
gap = res / length(dataset)
156-
return percentage ? gap * 100 : gap
145+
return op(
146+
map(dataset) do sample
147+
target_obj = objective_value(bench, sample)
148+
x = sample.x
149+
θ = statistical_model(x)
150+
y = maximizer(θ; maximizer_kwargs(bench, sample)...)
151+
obj = objective_value(bench, sample, y)
152+
Δ = check ? obj - target_obj : target_obj - obj
153+
return Δ / abs(target_obj)
154+
end,
155+
)
157156
end

0 commit comments

Comments
 (0)