Skip to content

Commit 7b47d13

Browse files
committed
new optional parameter for subset selection
1 parent 86777ca commit 7b47d13

File tree

3 files changed

+32
-14
lines changed

3 files changed

+32
-14
lines changed

docs/make.jl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ tutorial_dir = joinpath(@__DIR__, "src", "tutorials")
99
tutorial_files = readdir(tutorial_dir)
1010
md_tutorial_files = [split(file, ".")[1] * ".md" for file in tutorial_files]
1111

12-
for file in tutorial_files
13-
filepath = joinpath(tutorial_dir, file)
14-
Literate.markdown(filepath, md_dir; documenter=true, execute=false)
12+
include_tutorial = false
13+
14+
if include_tutorial
15+
for file in tutorial_files
16+
filepath = joinpath(tutorial_dir, file)
17+
Literate.markdown(filepath, md_dir; documenter=true, execute=false)
18+
end
1519
end
1620

1721
makedocs(;
@@ -21,7 +25,7 @@ makedocs(;
2125
format=Documenter.HTML(),
2226
pages=[
2327
"Home" => "index.md",
24-
# "Tutorials" => md_tutorial_files,
28+
"Tutorials" => include_tutorial ? md_tutorial_files : [],
2529
"Benchmark problems list" => [
2630
"benchmarks/subset_selection.md",
2731
"benchmarks/portfolio_optimization.md",
@@ -33,9 +37,11 @@ makedocs(;
3337
],
3438
)
3539

36-
for file in md_tutorial_files
37-
filepath = joinpath(md_dir, file)
38-
rm(filepath)
40+
if include_tutorial
41+
for file in md_tutorial_files
42+
filepath = joinpath(md_dir, file)
43+
rm(filepath)
44+
end
3945
end
4046

4147
deploydocs(;
Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
# Subset Selection
22

3-
[`SubsetSelectionBenchmark`](@ref) is a very simple benchmark problem of subset selection.
3+
[`SubsetSelectionBenchmark`](@ref) is the most trivial benchmark problem in this package.
4+
It is minimalistic and serves as a simple example for debugging and testing purposes.
45

5-
We have a set of ``n`` items, each item having an `unknown' value.
6+
## Description
7+
We have a set of ``n`` items, each item having an unknown value.
68
We want to select a subset of ``k`` items that maximizes the sum of the values of the selected items.
79

8-
As input, we are given a feature vector, that contains exactly the value of each item.
9-
The goal is to learn the identity mapping between the feature vector and the value of the items.
10+
As input, instead of the items costs, we are given a feature vector, such that an unknown linear mapping between the feature vector and the value of the items exists.
11+
12+
By default, this linear mapping is the identity mapping, i.e., the value of each item is equal to the value of the corresponding feature vector element.
13+
However, this mapping can be changed by setting the `identity_mapping` parameter to false.

src/SubsetSelection/SubsetSelection.jl

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,21 @@ Generate a dataset of labeled instances for the subset selection problem.
5858
The mapping between features and cost is identity.
5959
"""
6060
function Utils.generate_dataset(
61-
bench::SubsetSelectionBenchmark, dataset_size::Int=10; seed::Int=0
61+
bench::SubsetSelectionBenchmark,
62+
dataset_size::Int=10;
63+
seed::Int=0,
64+
identity_mapping=true,
6265
)
6366
(; n, k) = bench
6467
rng = MersenneTwister(seed)
6568
features = [randn(rng, Float32, n) for _ in 1:dataset_size]
66-
costs = copy(features) # we assume that the cost is the same as the feature
67-
solutions = top_k.(features, k)
69+
costs = if identity_mapping
70+
copy(features) # we assume that the cost is the same as the feature
71+
else
72+
mapping = Dense(n => n; bias=false)
73+
mapping.(features)
74+
end
75+
solutions = top_k.(costs, k)
6876
return [DataSample(; x=x, θ=θ, y=y) for (x, θ, y) in zip(features, costs, solutions)]
6977
end
7078

0 commit comments

Comments
 (0)