Skip to content

Commit 80b142a

Browse files
committed
cleanup docstrings and add optional noise in dataset
1 parent 94eeb79 commit 80b142a

File tree

2 files changed

+24
-16
lines changed

2 files changed

+24
-16
lines changed

src/Argmax/Argmax.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ using Random
88
"""
99
$TYPEDEF
1010
11-
Benchmark problem with an argmax as the CO algorithm.
11+
Basic benchmark problem with an argmax as the CO algorithm.
1212
1313
# Fields
1414
$TYPEDFIELDS
1515
"""
1616
struct ArgmaxBenchmark <: AbstractBenchmark
17-
"iinstances dimension, total number of classes"
17+
"instances dimension, total number of classes"
1818
instance_dim::Int
1919
"number of features"
2020
nb_features::Int
@@ -45,7 +45,7 @@ end
4545
"""
4646
$TYPEDSIGNATURES
4747
48-
Return a top k maximizer.
48+
Return an argmax maximizer.
4949
"""
5050
function Utils.generate_maximizer(bench::ArgmaxBenchmark)
5151
return one_hot_argmax
@@ -54,19 +54,23 @@ end
5454
"""
5555
$TYPEDSIGNATURES
5656
57-
Generate a dataset of labeled instances for the subset selection problem.
58-
The mapping between features and cost is identity.
57+
Generate a dataset of labeled instances for the argmax problem.
5958
"""
60-
function Utils.generate_dataset(bench::ArgmaxBenchmark, dataset_size::Int=10; seed::Int=0)
59+
function Utils.generate_dataset(
60+
bench::ArgmaxBenchmark, dataset_size::Int=10; seed::Int=0, noise_std=0.0
61+
)
6162
(; instance_dim, nb_features) = bench
6263
rng = MersenneTwister(seed)
6364
features = [randn(rng, Float32, nb_features, instance_dim) for _ in 1:dataset_size]
6465
mapping = Chain(Dense(nb_features => 1; bias=false), vec)
6566
costs = mapping.(features)
66-
solutions = one_hot_argmax.(costs)
67+
# solutions = one_hot_argmax.(costs)
68+
noisy_solutions = [
69+
one_hot_argmax+ noise_std * randn(rng, Float32, instance_dim)) for θ in costs
70+
]
6771
return [
6872
DataSample(; x, θ_true, y_true) for
69-
(x, θ_true, y_true) in zip(features, costs, solutions)
73+
(x, θ_true, y_true) in zip(features, costs, noisy_solutions)
7074
]
7175
end
7276

src/Ranking/Ranking.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ using Random
88
"""
99
$TYPEDEF
1010
11-
Benchmark problem with an argmax as the CO algorithm.
11+
Basic benchmark problem with ranking as the CO algorithm.
1212
1313
# Fields
1414
$TYPEDFIELDS
1515
"""
1616
struct RankingBenchmark <: AbstractBenchmark
17-
"iinstances dimension, total number of classes"
17+
"instances dimension, total number of classes"
1818
instance_dim::Int
1919
"number of features"
2020
nb_features::Int
@@ -43,7 +43,7 @@ end
4343
"""
4444
$TYPEDSIGNATURES
4545
46-
Return a top k maximizer.
46+
Return a ranking maximizer.
4747
"""
4848
function Utils.generate_maximizer(bench::RankingBenchmark)
4949
return ranking
@@ -52,19 +52,23 @@ end
5252
"""
5353
$TYPEDSIGNATURES
5454
55-
Generate a dataset of labeled instances for the subset selection problem.
56-
The mapping between features and cost is identity.
55+
Generate a dataset of labeled instances for the ranking problem.
5756
"""
58-
function Utils.generate_dataset(bench::RankingBenchmark, dataset_size::Int=10; seed::Int=0)
57+
function Utils.generate_dataset(
58+
bench::RankingBenchmark, dataset_size::Int=10; seed::Int=0, noise_std=0.0
59+
)
5960
(; instance_dim, nb_features) = bench
6061
rng = MersenneTwister(seed)
6162
features = [randn(rng, Float32, nb_features, instance_dim) for _ in 1:dataset_size]
6263
mapping = Chain(Dense(nb_features => 1; bias=false), vec)
6364
costs = mapping.(features)
64-
solutions = ranking.(costs)
65+
# solutions = ranking.(costs)
66+
noisy_solutions = [
67+
ranking.+ noise_std * randn(rng, Float32, instance_dim)) for θ in costs
68+
]
6569
return [
6670
DataSample(; x, θ_true, y_true) for
67-
(x, θ_true, y_true) in zip(features, costs, solutions)
71+
(x, θ_true, y_true) in zip(features, costs, noisy_solutions)
6872
]
6973
end
7074

0 commit comments

Comments
 (0)