Skip to content

Commit ac2c69f

Browse files
committed
Rename DataSample fields
1 parent 48a812c commit ac2c69f

File tree

11 files changed

+28
-25
lines changed

11 files changed

+28
-25
lines changed

src/FixedSizeShortestPath/FixedSizeShortestPath.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,10 @@ function Utils.generate_dataset(
132132

133133
# Label solutions
134134
solutions = shortest_path_maximizer.(costs)
135-
return [DataSample(; x=x, θ=θ, y=y) for (x, θ, y) in zip(features, costs, solutions)]
135+
return [
136+
DataSample(; x, θ_true, y_true) for
137+
(x, θ_true, y_true) in zip(features, costs, solutions)
138+
]
136139
end
137140

138141
"""

src/PortfolioOptimization/PortfolioOptimization.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,10 @@ function Utils.generate_dataset(
110110
maximizer = Utils.generate_maximizer(bench)
111111
solutions = maximizer.(costs)
112112

113-
return [DataSample(; x=x, θ=θ, y=y) for (x, θ, y) in zip(features, costs, solutions)]
113+
return [
114+
DataSample(; x, θ_true, y_true) for
115+
(x, θ_true, y_true) in zip(features, costs, solutions)
116+
]
114117
end
115118

116119
"""

src/SubsetSelection/SubsetSelection.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,10 @@ function Utils.generate_dataset(
7373
mapping.(features)
7474
end
7575
solutions = top_k.(costs, k)
76-
return [DataSample(; x=x, θ=θ, y=y) for (x, θ, y) in zip(features, costs, solutions)]
76+
return [
77+
DataSample(; x, θ_true, y_true) for
78+
(x, θ_true, y_true) in zip(features, costs, solutions)
79+
]
7780
end
7881

7982
"""

src/Utils/data_sample.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ $TYPEDFIELDS
99
@kwdef struct DataSample{F,S,C,I}
1010
"features"
1111
x::F
12-
"costs"
13-
θ::C = nothing
14-
"solution"
15-
y::S = nothing
16-
"instance"
12+
"target cost parameters (optional)"
13+
θ_true::C = nothing
14+
"target solution (optional)"
15+
y_true::S = nothing
16+
"instance object (optional)"
1717
instance::I = nothing
1818
end

src/Utils/interface.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ function compute_gap(
7373

7474
for sample in dataset
7575
x = sample.x
76-
θ̄ = sample.θ
77-
= sample.y
76+
θ̄ = sample.θ_true
77+
= sample.y_true
7878
θ = statistical_model(x)
7979
y = maximizer(θ)
8080
target_obj = objective_value(bench, θ̄, ȳ)

src/Warcraft/Warcraft.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,14 @@ The keyword argument `θ_true` is used to set the color range of the weights plo
8787
function Utils.plot_data(
8888
::WarcraftBenchmark,
8989
sample::DataSample;
90-
θ_true=sample.θ,
90+
θ_true=sample.θ_true,
9191
θ_title="Weights",
9292
y_title="Path",
9393
kwargs...,
9494
)
95-
(; x, y, θ) = sample
95+
x = sample.x
96+
y = sample.y_true
97+
θ = sample.θ_true
9698
im = dropdims(x; dims=4)
9799
img = convert_image_for_plot(im)
98100
p1 = Plots.plot(

src/Warcraft/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function create_dataset(decompressed_path::String, nb_samples::Int)
4040
]
4141
Y = [BitMatrix(terrain_labels[:, :, i]) for i in 1:N]
4242
WG = [-terrain_weights[:, :, i] for i in 1:N]
43-
return [DataSample(; x, y, θ) for (x, y, θ) in zip(X, Y, WG)]
43+
return [DataSample(; x, y_true, θ_true) for (x, y_true, θ_true) in zip(X, Y, WG)]
4444
end
4545

4646
"""

test/fixed_size_shortest_path.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
@test gap >= 0
1919

2020
for sample in dataset
21-
x = sample.x
22-
θ_true = sample.θ
23-
y_true = sample.y
21+
(; x, θ_true, y_true) = sample
2422
@test all(θ_true .< 0)
2523
@test size(x) == (p,)
2624
@test length(θ_true) == A

test/portfolio_optimization.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@
1010
maximizer = generate_maximizer(b)
1111

1212
for sample in dataset
13-
x = sample.x
14-
θ_true = sample.θ
15-
y_true = sample.y
13+
(; x, θ_true, y_true) = sample
1614
@test size(x) == (p,)
1715
@test length(θ_true) == d
1816
@test length(y_true) == d

test/subset_selection.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@
1616
maximizer = generate_maximizer(b)
1717

1818
for (i, sample) in enumerate(dataset)
19-
x = sample.x
20-
θ_true = sample.θ
21-
y_true = sample.y
19+
(; x, θ_true, y_true) = sample
2220
@test size(x) == (n,)
2321
@test length(θ_true) == n
2422
@test length(y_true) == n

0 commit comments

Comments
 (0)