Skip to content

Commit dc48513

Browse files
authored
Merge pull request #9 from JuliaDecisionFocusedLearning/better-doc
Document existing benchmarks
2 parents 116a1cc + 4f83cbd commit dc48513

File tree

7 files changed

+67
-10
lines changed

7 files changed

+67
-10
lines changed

docs/make.jl

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,20 @@ cp(joinpath(@__DIR__, "..", "README.md"), joinpath(@__DIR__, "src", "index.md");
66

77
md_dir = joinpath(@__DIR__, "src")
88
tutorial_dir = joinpath(@__DIR__, "src", "tutorials")
9+
benchmarks_dir = joinpath(@__DIR__, "src", "benchmarks")
10+
911
tutorial_files = readdir(tutorial_dir)
1012
md_tutorial_files = [split(file, ".")[1] * ".md" for file in tutorial_files]
13+
benchmark_files = readdir(benchmarks_dir)
14+
md_benchmark_files = [split(file, ".")[1] * ".md" for file in benchmark_files]
15+
16+
include_tutorial = true
1117

12-
for file in tutorial_files
13-
filepath = joinpath(tutorial_dir, file)
14-
Literate.markdown(filepath, md_dir; documenter=true, execute=false)
18+
if include_tutorial
19+
for file in tutorial_files
20+
filepath = joinpath(tutorial_dir, file)
21+
Literate.markdown(filepath, md_dir; documenter=true, execute=false)
22+
end
1523
end
1624

1725
makedocs(;
@@ -21,15 +29,23 @@ makedocs(;
2129
format=Documenter.HTML(),
2230
pages=[
2331
"Home" => "index.md",
24-
"Tutorials" => md_tutorial_files,
32+
"Tutorials" => include_tutorial ? md_tutorial_files : [],
33+
"Benchmark problems list" => [
34+
"benchmarks/subset_selection.md",
35+
"benchmarks/fixed_size_shortest_path.md",
36+
"benchmarks/warcraft.md",
37+
"benchmarks/portfolio_optimization.md",
38+
],
2539
"API reference" =>
2640
["api/interface.md", "api/decision_focused.md", "api/warcraft.md"],
2741
],
2842
)
2943

30-
for file in md_tutorial_files
31-
filepath = joinpath(md_dir, file)
32-
rm(filepath)
44+
if include_tutorial
45+
for file in md_tutorial_files
46+
filepath = joinpath(md_dir, file)
47+
rm(filepath)
48+
end
3349
end
3450

3551
deploydocs(;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Shortest paths
2+
3+
[`FixedSizeShortestPathBenchmark`](@ref) is a benchmark problem that consists of finding the shortest path in a grid graph between the top left and bottom right corners.
4+
In this benchmark, the grid size is the same for all instances.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Portfolio Optimization
2+
3+
[`PortfolioOptimizationBenchmark`](@ref) is a Markovitz portfolio optimization problem, where asset prices are unknown, and only contextual data is available to predict these prices.
4+
The goal is to predict asset prices $c$ and maximize the expected return of a portfolio, subject to a risk constraint using this maximization program:
5+
```math
6+
\begin{aligned}
7+
\max\quad & c^\top x\\
8+
\text{s.t.}\quad & x^\top \Sigma x \leq \gamma\\
9+
& 1^\top x \leq 1\\
10+
& x \geq 0
11+
\end{aligned}
12+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Subset Selection
2+
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.
5+
6+
## Description
7+
We have a set of ``n`` items, each item having an unknown value.
8+
We want to select a subset of ``k`` items that maximizes the sum of the values of the selected items.
9+
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`.

docs/src/benchmarks/warcraft.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Warcraft
2+
3+
See the tutorial for a full demo of [`WarcraftBenchmark`](@ref).

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

test/subset_selection.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@test String(take!(io)) == "SubsetSelectionBenchmark(n=25, k=5)"
1212

1313
dataset = generate_dataset(b, 50)
14+
dataset2 = generate_dataset(b, 50; identity_mapping=false)
1415
model = generate_statistical_model(b)
1516
maximizer = generate_maximizer(b)
1617

0 commit comments

Comments
 (0)