@@ -90,14 +90,9 @@ generate_instance(bench::MyStochasticBenchmark, rng::AbstractRNG; kwargs...) ->
9090
9191# Draw one scenario given the instance encoded in context
9292generate_scenario (bench:: MyStochasticBenchmark , rng:: AbstractRNG ; context... ) -> scenario
93- # Note: sample.context is spread as kwargs when called by the framework
93+ # Note: sample.context is spread as kwargs when called
9494```
9595
96- The framework ` generate_sample ` calls ` generate_instance ` , draws ` nb_scenarios `
97- scenarios via ` generate_scenario ` , then:
98- - If ` target_policy ` is provided: calls ` target_policy(sample, scenarios) -> Vector{DataSample} ` .
99- - Otherwise: returns unlabeled samples with ` extra=(; scenario=ξ) ` for each scenario.
100-
10196#### Anticipative solver (optional)
10297
10398``` julia
@@ -189,89 +184,3 @@ DataSample(; x=feat, y=nothing, instance=inst, extra=(; scenario=ξ))
189184```
190185
191186Keys must not appear in both ` context ` and ` extra ` , the constructor raises an error.
192-
193- ---
194-
195- ## Small examples
196-
197- ### Static benchmark
198-
199- ``` julia
200- using DecisionFocusedLearningBenchmarks
201- const DFLBenchmarks = DecisionFocusedLearningBenchmarks
202-
203- struct MyStaticBenchmark <: AbstractBenchmark end
204-
205- function DFLBenchmarks. generate_instance (bench:: MyStaticBenchmark , rng:: AbstractRNG ; kwargs... )
206- instance = build_my_instance (rng)
207- x = compute_features (instance)
208- return DataSample (; x= x, instance= instance) # y = nothing
209- end
210-
211-
212- DFLBenchmarks. generate_statistical_model (bench:: MyStaticBenchmark ; seed= nothing ) =
213- Chain (Dense (10 => 32 , relu), Dense (32 => 5 ))
214-
215- DFLBenchmarks. generate_maximizer (bench:: MyStaticBenchmark ) =
216- (θ; instance, kwargs... ) -> solve_my_problem (θ, instance)
217- ```
218-
219- ### Stochastic benchmark
220-
221- ``` julia
222-
223- struct MyStochasticBenchmark <: AbstractStochasticBenchmark{true} end
224-
225- function DFLBenchmarks. generate_instance (bench:: MyStochasticBenchmark , rng:: AbstractRNG ; kwargs... )
226- instance = build_my_instance (rng)
227- x = compute_features (instance)
228- return DataSample (; x= x, instance= instance)
229- end
230-
231- function DFLBenchmarks. generate_scenario (bench:: MyStochasticBenchmark , rng:: AbstractRNG ; instance, kwargs... )
232- return sample_scenario (instance, rng)
233- end
234-
235- DFLBenchmarks. generate_anticipative_solver (bench:: MyStochasticBenchmark ) =
236- (scenario; instance, kwargs... ) -> solve_with_scenario (instance, scenario)
237- ```
238-
239- ### Dynamic benchmark
240-
241- ``` julia
242- struct MyDynamicBenchmark <: AbstractDynamicBenchmark{true} end
243-
244- mutable struct MyEnv <: AbstractEnvironment
245- const instance:: MyInstance
246- const seed:: Int
247- state:: MyState
248- end
249-
250- DFLBenchmarks. get_seed (env:: MyEnv ) = env. seed
251- DFLBenchmarks. reset! (env:: MyEnv ; reset_rng= true , seed= env. seed) = (env. state = initial_state (env. instance))
252- DFLBenchmarks. observe (env:: MyEnv ) = (env. state, nothing )
253- DFLBenchmarks. step! (env:: MyEnv , action) = apply_action! (env. state, action)
254- DFLBenchmarks. is_terminated (env:: MyEnv ) = env. state. done
255-
256- function DFLBenchmarks. generate_environment (bench:: MyDynamicBenchmark , rng:: AbstractRNG ; kwargs... )
257- inst = build_my_instance (rng)
258- seed = rand (rng, Int)
259- return MyEnv (inst, seed, initial_state (inst))
260- end
261-
262- function DFLBenchmarks. generate_baseline_policies (bench:: MyDynamicBenchmark )
263- greedy = function (env)
264- samples = DataSample[]
265- reset! (env)
266- while ! is_terminated (env)
267- obs, _ = observe (env)
268- x = compute_features (obs)
269- y = greedy_action (obs)
270- r = step! (env, y)
271- push! (samples, DataSample (; x= x, y= y, instance= obs, extra= (; reward= r)))
272- end
273- return samples
274- end
275- return (; greedy)
276- end
277- ```
0 commit comments