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 an `instance_kwargs ` field (solver kwargs, spread into the maximizer as
8- `maximizer(θ; sample.instance_kwargs ...)`) and an `extra` field (non-solver data, never passed
7+ Additionally, it has an `maximizer_kwargs ` field (solver kwargs, spread into the maximizer as
8+ `maximizer(θ; sample.maximizer_kwargs ...)`) and an `extra` field (non-solver data, never passed
99to the maximizer).
1010
1111The separation prevents silent breakage from accidentally passing non-solver data
@@ -15,8 +15,8 @@ The separation prevents silent breakage from accidentally passing non-solver dat
1515$TYPEDFIELDS
1616"""
1717struct DataSample{
18- CTX <: NamedTuple ,
19- EX <: NamedTuple ,
18+ K <: NamedTuple ,
19+ E <: NamedTuple ,
2020 F<: Union{AbstractArray,Nothing} ,
2121 S<: Union{AbstractArray,Nothing} ,
2222 C<: Union{AbstractArray,Nothing} ,
@@ -28,63 +28,63 @@ struct DataSample{
2828 " output solution (optional)"
2929 y:: S
3030 " solver kwargs, e.g. instance, graph, etc."
31- instance_kwargs :: CTX
31+ maximizer_kwargs :: 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."
34- extra:: EX
34+ extra:: E
3535end
3636
3737"""
3838$TYPEDSIGNATURES
3939
4040Constructor for `DataSample` with keyword arguments.
4141
42- All keyword arguments beyond `x`, `θ`, `y`, and `extra` are collected into the `instance_kwargs `
42+ All keyword arguments beyond `x`, `θ`, `y`, and `extra` are collected into the `maximizer_kwargs `
4343field (solver kwargs). The `extra` keyword accepts a `NamedTuple` of non-solver data.
4444
45- Fields in `instance_kwargs ` and `extra` must be disjoint. An error is thrown if they overlap.
45+ Fields in `maximizer_kwargs ` and `extra` must be disjoint. An error is thrown if they overlap.
4646Both can be accessed directly via property forwarding.
4747
4848# Examples
4949```julia
50- # Instance goes in instance_kwargs
50+ # Instance goes in maximizer_kwargs
5151d = DataSample(x=[1,2,3], θ=[4,5,6], y=[7,8,9], instance="my_instance")
52- d.instance # "my_instance" (from instance_kwargs )
52+ d.instance # "my_instance" (from maximizer_kwargs )
5353
5454# Scenario goes in extra
5555d = DataSample(x=x, y=y, instance=inst, extra=(; scenario=ξ))
5656d.scenario # ξ (from extra)
5757
58- # State goes in instance_kwargs , reward in extra
58+ # State goes in maximizer_kwargs , reward in extra
5959d = DataSample(x=x, y=y, instance=state, extra=(; reward=-1.5))
60- d.instance # state (from instance_kwargs )
60+ d.instance # state (from maximizer_kwargs )
6161d.reward # -1.5 (from extra)
6262```
6363"""
6464function DataSample (; x= nothing , θ= nothing , y= nothing , extra= NamedTuple (), kwargs... )
65- instance_kwargs = (; kwargs... )
66- overlap = intersect (keys (instance_kwargs ), keys (extra))
65+ maximizer_kwargs = (; kwargs... )
66+ overlap = intersect (keys (maximizer_kwargs ), keys (extra))
6767 if ! isempty (overlap)
6868 error (
69- " Keys $(collect (overlap)) appear in both instance_kwargs and extra of DataSample" ,
69+ " Keys $(collect (overlap)) appear in both maximizer_kwargs and extra of DataSample" ,
7070 )
7171 end
72- return DataSample (x, θ, y, instance_kwargs , extra)
72+ return DataSample (x, θ, y, maximizer_kwargs , extra)
7373end
7474
7575"""
7676$TYPEDSIGNATURES
7777
7878Extended property access for `DataSample`.
7979
80- Allows accessing `instance_kwargs ` and `extra` fields directly as properties.
81- `instance_kwargs ` is searched first; if the key is not found there, `extra` is searched.
80+ Allows accessing `maximizer_kwargs ` and `extra` fields directly as properties.
81+ `maximizer_kwargs ` is searched first; if the key is not found there, `extra` is searched.
8282"""
8383function Base. getproperty (d:: DataSample , name:: Symbol )
84- if name in (:x , :θ , :y , :instance_kwargs , :extra )
84+ if name in (:x , :θ , :y , :maximizer_kwargs , :extra )
8585 return getfield (d, name)
8686 else
87- ctx = getfield (d, :instance_kwargs )
87+ ctx = getfield (d, :maximizer_kwargs )
8888 if haskey (ctx, name)
8989 return getproperty (ctx, name)
9090 end
9696$TYPEDSIGNATURES
9797
9898Return all property names of a `DataSample`, including both struct fields and forwarded
99- fields from `instance_kwargs ` and `extra`.
99+ fields from `maximizer_kwargs ` and `extra`.
100100
101101This enables tab completion for all available properties.
102102"""
103103function Base. propertynames (d:: DataSample , private:: Bool = false )
104- ctx_names = propertynames (getfield (d, :instance_kwargs ), private)
104+ ctx_names = propertynames (getfield (d, :maximizer_kwargs ), private)
105105 extra_names = propertynames (getfield (d, :extra ), private)
106106 return (fieldnames (DataSample)... , ctx_names... , extra_names... )
107107end
@@ -128,7 +128,7 @@ function Base.show(io::IO, d::DataSample)
128128 y_str = sprint (show, d. y; context= io_limited)
129129 push! (fields, " y_true=$y_str " )
130130 end
131- for (key, value) in pairs (d. instance_kwargs )
131+ for (key, value) in pairs (d. maximizer_kwargs )
132132 value_str = sprint (show, value; context= io_limited)
133133 push! (fields, " $key =$value_str " )
134134 end
@@ -156,8 +156,8 @@ Transform the features in the dataset.
156156"""
157157function StatsBase. transform (t, dataset:: AbstractVector{<:DataSample} )
158158 return map (dataset) do d
159- (; instance_kwargs , extra, x, θ, y) = d
160- DataSample (StatsBase. transform (t, x), θ, y, instance_kwargs , extra)
159+ (; maximizer_kwargs , extra, x, θ, y) = d
160+ DataSample (StatsBase. transform (t, x), θ, y, maximizer_kwargs , extra)
161161 end
162162end
163163
@@ -179,8 +179,8 @@ Reconstruct the features in the dataset.
179179"""
180180function StatsBase. reconstruct (t, dataset:: AbstractVector{<:DataSample} )
181181 return map (dataset) do d
182- (; instance_kwargs , extra, x, θ, y) = d
183- DataSample (StatsBase. reconstruct (t, x), θ, y, instance_kwargs , extra)
182+ (; maximizer_kwargs , extra, x, θ, y) = d
183+ DataSample (StatsBase. reconstruct (t, x), θ, y, maximizer_kwargs , extra)
184184 end
185185end
186186
0 commit comments