44Data sample data structure.
55Its main purpose is to store datasets generated by the benchmarks.
66It has 3 main (optional) fields: features `x`, cost parameters `θ`, and solution `y`.
7- Additionally, it has a `maximizer_kwargs ` field (solver kwargs , spread into the maximizer as
8- `maximizer(θ; sample.maximizer_kwargs ...)`) and an `extra` field (non-solver data, never passed
7+ Additionally, it has a `context ` field (solver and scenario-generation context , spread into the
8+ maximizer as `maximizer(θ; sample.context ...)`) and an `extra` field (non-solver data, never passed
99to the maximizer).
1010
1111The separation prevents silent breakage from accidentally passing non-solver data
@@ -27,8 +27,8 @@ struct DataSample{
2727 θ:: C
2828 " output solution (optional)"
2929 y:: S
30- " solver kwargs , e.g. instance, graph, etc. "
31- maximizer_kwargs :: K
30+ " solver and scenario-generation context , e.g. instance, graph, contextual information "
31+ context :: K
3232 " additional data, never passed to the maximizer, e.g. scenario, objective value, reward,
3333 step count, etc. Can be used for any purpose by the user, such as plotting utilities."
3434 extra:: E
@@ -39,65 +39,61 @@ $TYPEDSIGNATURES
3939
4040Constructor for `DataSample` with keyword arguments.
4141
42- All keyword arguments beyond `x`, `θ`, `y`, and `extra` are collected into the `maximizer_kwargs `
43- field (solver kwargs ). The `extra` keyword accepts a `NamedTuple` of non-solver data.
42+ All keyword arguments beyond `x`, `θ`, `y`, and `extra` are collected into the `context `
43+ field (solver and scenario-generation context ). The `extra` keyword accepts a `NamedTuple` of non-solver data.
4444
45- Fields in `maximizer_kwargs ` and `extra` must be disjoint. Neither may use a reserved
46- struct field name (`x`, `θ`, `y`, `maximizer_kwargs `, `extra`). An error is thrown in
45+ Fields in `context ` and `extra` must be disjoint. Neither may use a reserved
46+ struct field name (`x`, `θ`, `y`, `context `, `extra`). An error is thrown in
4747both cases.
4848Both can be accessed directly via property forwarding.
4949
5050# Examples
5151```julia
52- # Instance goes in maximizer_kwargs
52+ # Instance goes in context
5353d = DataSample(x=[1,2,3], θ=[4,5,6], y=[7,8,9], instance="my_instance")
54- d.instance # "my_instance" (from maximizer_kwargs )
54+ d.instance # "my_instance" (from context )
5555
5656# Scenario goes in extra
5757d = DataSample(x=x, y=y, instance=inst, extra=(; scenario=ξ))
5858d.scenario # ξ (from extra)
5959
60- # State goes in maximizer_kwargs , reward in extra
60+ # State goes in context , reward in extra
6161d = DataSample(x=x, y=y, instance=state, extra=(; reward=-1.5))
62- d.instance # state (from maximizer_kwargs )
62+ d.instance # state (from context )
6363d.reward # -1.5 (from extra)
6464```
6565"""
6666function DataSample (; x= nothing , θ= nothing , y= nothing , extra= NamedTuple (), kwargs... )
67- maximizer_kwargs = (; kwargs... )
68- overlap = intersect (keys (maximizer_kwargs ), keys (extra))
67+ context = (; kwargs... )
68+ overlap = intersect (keys (context ), keys (extra))
6969 if ! isempty (overlap)
70- error (
71- " Keys $(collect (overlap)) appear in both maximizer_kwargs and extra of DataSample" ,
72- )
70+ error (" Keys $(collect (overlap)) appear in both context and extra of DataSample" )
7371 end
74- reserved = (:x , :θ , :y , :maximizer_kwargs , :extra )
75- shadowed_ctx = intersect (keys (maximizer_kwargs ), reserved)
72+ reserved = (:x , :θ , :y , :context , :extra )
73+ shadowed_ctx = intersect (keys (context ), reserved)
7674 if ! isempty (shadowed_ctx)
77- error (
78- " Keys $(collect (shadowed_ctx)) in maximizer_kwargs shadow DataSample struct fields" ,
79- )
75+ error (" Keys $(collect (shadowed_ctx)) in context shadow DataSample struct fields" )
8076 end
8177 shadowed_extra = intersect (keys (extra), reserved)
8278 if ! isempty (shadowed_extra)
8379 error (" Keys $(collect (shadowed_extra)) in extra shadow DataSample struct fields" )
8480 end
85- return DataSample (x, θ, y, maximizer_kwargs , extra)
81+ return DataSample (x, θ, y, context , extra)
8682end
8783
8884"""
8985$TYPEDSIGNATURES
9086
9187Extended property access for `DataSample`.
9288
93- Allows accessing `maximizer_kwargs ` and `extra` fields directly as properties.
94- `maximizer_kwargs ` is searched first; if the key is not found there, `extra` is searched.
89+ Allows accessing `context ` and `extra` fields directly as properties.
90+ `context ` is searched first; if the key is not found there, `extra` is searched.
9591"""
9692function Base. getproperty (d:: DataSample , name:: Symbol )
97- if name in (:x , :θ , :y , :maximizer_kwargs , :extra )
93+ if name in (:x , :θ , :y , :context , :extra )
9894 return getfield (d, name)
9995 else
100- ctx = getfield (d, :maximizer_kwargs )
96+ ctx = getfield (d, :context )
10197 if haskey (ctx, name)
10298 return getproperty (ctx, name)
10399 end
@@ -109,12 +105,12 @@ end
109105$TYPEDSIGNATURES
110106
111107Return all property names of a `DataSample`, including both struct fields and forwarded
112- fields from `maximizer_kwargs ` and `extra`.
108+ fields from `context ` and `extra`.
113109
114110This enables tab completion for all available properties.
115111"""
116112function Base. propertynames (d:: DataSample , private:: Bool = false )
117- ctx_names = propertynames (getfield (d, :maximizer_kwargs ), private)
113+ ctx_names = propertynames (getfield (d, :context ), private)
118114 extra_names = propertynames (getfield (d, :extra ), private)
119115 return (fieldnames (DataSample)... , ctx_names... , extra_names... )
120116end
@@ -141,7 +137,7 @@ function Base.show(io::IO, d::DataSample)
141137 y_str = sprint (show, d. y; context= io_limited)
142138 push! (fields, " y_true=$y_str " )
143139 end
144- for (key, value) in pairs (d. maximizer_kwargs )
140+ for (key, value) in pairs (d. context )
145141 value_str = sprint (show, value; context= io_limited)
146142 push! (fields, " $key =$value_str " )
147143 end
@@ -169,8 +165,8 @@ Transform the features in the dataset.
169165"""
170166function StatsBase. transform (t, dataset:: AbstractVector{<:DataSample} )
171167 return map (dataset) do d
172- (; maximizer_kwargs , extra, x, θ, y) = d
173- DataSample (StatsBase. transform (t, x), θ, y, maximizer_kwargs , extra)
168+ (; context , extra, x, θ, y) = d
169+ DataSample (StatsBase. transform (t, x), θ, y, context , extra)
174170 end
175171end
176172
@@ -192,8 +188,8 @@ Reconstruct the features in the dataset.
192188"""
193189function StatsBase. reconstruct (t, dataset:: AbstractVector{<:DataSample} )
194190 return map (dataset) do d
195- (; maximizer_kwargs , extra, x, θ, y) = d
196- DataSample (StatsBase. reconstruct (t, x), θ, y, maximizer_kwargs , extra)
191+ (; context , extra, x, θ, y) = d
192+ DataSample (StatsBase. reconstruct (t, x), θ, y, context , extra)
197193 end
198194end
199195
0 commit comments