@@ -55,10 +55,52 @@ function compute_gap end
5555"""
5656$TYPEDSIGNATURES
5757
58+ For simple benchmarks where there is no instance object, maximizer does not need any keyword arguments.
59+ """
60+ function maximizer_kwargs (
61+ :: AbstractBenchmark , sample:: DataSample{F,S,C,Nothing}
62+ ) where {F,S,C}
63+ return NamedTuple ()
64+ end
65+
66+ """
67+ $TYPEDSIGNATURES
68+
69+ For benchmarks where there is an instance object, maximizer needs the instance object as a keyword argument.
70+ """
71+ function maximizer_kwargs (:: AbstractBenchmark , sample:: DataSample )
72+ return (; instance= sample. instance)
73+ end
74+
75+ """
76+ $TYPEDSIGNATURES
77+
5878Default behaviour of `objective_value`.
5979"""
60- function objective_value (:: AbstractBenchmark , θ̄:: AbstractArray , y:: AbstractArray )
61- return dot (θ̄, y)
80+ function objective_value (:: AbstractBenchmark , θ:: AbstractArray , y:: AbstractArray )
81+ return dot (θ, y)
82+ end
83+
84+ """
85+ $TYPEDSIGNATURES
86+
87+ Compute the objective value of the target in the sample (needs to exist).
88+ """
89+ function objective_value (
90+ bench:: AbstractBenchmark , sample:: DataSample{F,S,C,I}
91+ ) where {F,S<: AbstractArray ,C<: AbstractArray ,I}
92+ return objective_value (bench, sample. θ_true, sample. y_true)
93+ end
94+
95+ """
96+ $TYPEDSIGNATURES
97+
98+ Compute the objective value of given solution `y`.
99+ """
100+ function objective_value (
101+ bench:: AbstractBenchmark , sample:: DataSample{F,S,C,I} , y:: AbstractArray
102+ ) where {F,S,C<: AbstractArray ,I}
103+ return objective_value (bench, sample. θ_true, y)
62104end
63105
64106"""
@@ -72,13 +114,11 @@ function compute_gap(
72114 res = 0.0
73115
74116 for sample in dataset
117+ target_obj = objective_value (bench, sample)
75118 x = sample. x
76- θ̄ = sample. θ_true
77- ȳ = sample. y_true
78119 θ = statistical_model (x)
79- y = maximizer (θ)
80- target_obj = objective_value (bench, θ̄, ȳ)
81- obj = objective_value (bench, θ̄, y)
120+ y = maximizer (θ; maximizer_kwargs (bench, sample)... )
121+ obj = objective_value (bench, sample, y)
82122 res += (target_obj - obj) / abs (target_obj)
83123 end
84124 return res / length (dataset)
0 commit comments