Warcraft
Public
DecisionFocusedLearningBenchmarks.Warcraft.WarcraftBenchmark
— Typestruct WarcraftBenchmark <: AbstractBenchmark
Benchmark for the Warcraft shortest path problem. Does not have any field.
Private
DecisionFocusedLearningBenchmarks.Utils.generate_dataset
— Functiongenerate_dataset(::WarcraftBenchmark) -> Vector
generate_dataset(
::WarcraftBenchmark,
dataset_size::Int64
) -> Vector
Downloads and decompresses the Warcraft dataset the first time it is called.
dataset_size
is capped at 10000, i.e. the number of available samples in the dataset files.
DecisionFocusedLearningBenchmarks.Utils.generate_maximizer
— Methodgenerate_maximizer(
::WarcraftBenchmark;
dijkstra
) -> typeof(DecisionFocusedLearningBenchmarks.Warcraft.dijkstra_maximizer)
Returns an optimization algorithm that computes a longest path on the grid graph with given weights. Uses a shortest path algorithm on opposite weights to get the longest path.
DecisionFocusedLearningBenchmarks.Utils.generate_statistical_model
— Methodgenerate_statistical_model(
::WarcraftBenchmark;
seed
) -> Flux.Chain{T} where T<:Tuple{Any, Any, Any, Any, Flux.AdaptiveMaxPool{4, 2}, typeof(DecisionFocusedLearningBenchmarks.Utils.average_tensor), typeof(DecisionFocusedLearningBenchmarks.Utils.neg_tensor), typeof(DecisionFocusedLearningBenchmarks.Utils.squeeze_last_dims)}
Create and return a Flux.Chain
embedding for the Warcraft terrains, inspired by differentiation of blackbox combinatorial solvers.
The embedding is made as follows:
- The first 5 layers of ResNet18 (convolution, batch normalization, relu, maxpooling and first resnet block).
- An adaptive maxpooling layer to get a (12x12x64) tensor per input image.
- An average over the third axis (of size 64) to get a (12x12x1) tensor per input image.
- The element-wize
neg_tensor
function to get cell weights of proper sign to apply shortest path algorithms. - A squeeze function to forget the two last dimensions.
DecisionFocusedLearningBenchmarks.Utils.plot_data
— Methodplot_data(
::WarcraftBenchmark,
sample::DataSample;
θ_true,
θ_title,
y_title,
kwargs...
) -> Any
Plot the content of input DataSample
as images. x
as the initial image, θ
as the weights, and y
as the path.
The keyword argument θ_true
is used to set the color range of the weights plot.
DecisionFocusedLearningBenchmarks.Warcraft.bellman_maximizer
— Methodbellman_maximizer(
θ::AbstractMatrix;
kwargs...
) -> Matrix{Int64}
Computes the longest path in given grid graph weights by computing the shortest path in the graph with opposite weights. Using the Ford-Bellman dynamic programming algorithm.
DecisionFocusedLearningBenchmarks.Warcraft.convert_image_for_plot
— Methodconvert_image_for_plot(
image::Array{Float32, 3}
) -> Matrix{ColorTypes.RGB{FixedPointNumbers.N0f8}}
Convert image
to the proper data format to enable plots in Julia.
DecisionFocusedLearningBenchmarks.Warcraft.create_dataset
— Methodcreate_dataset(
decompressed_path::String,
nb_samples::Int64
) -> Vector
Create the dataset corresponding to the data located at decompressed_path
, possibly sub-sampling nb_samples
points. The dataset is made of images of Warcraft terrains, cell cost labels and shortest path labels. It is a Vector
of tuples, each Tuple
being a dataset point.
DecisionFocusedLearningBenchmarks.Warcraft.dijkstra_maximizer
— Methoddijkstra_maximizer(
θ::AbstractMatrix;
kwargs...
) -> Matrix{Int64}
Computes the longest path in given grid graph weights by computing the shortest path in the graph with opposite weights. Using the Dijkstra algorithm.
Only works on graph with positive weights, i.e. if θ
only contains negative values.
DecisionFocusedLearningBenchmarks.Warcraft.grid_bellman_ford_warcraft
— Functiongrid_bellman_ford_warcraft(g, s, d, length_max)
Apply the Bellman-Ford algorithm on an GridGraph
g
, and return a ShortestPathTree
with source s
and destination d
, among the paths having length smaller than length_max
.
DecisionFocusedLearningBenchmarks.Warcraft.read_dataset
— Functionread_dataset(
decompressed_path::String
) -> Tuple{Any, Any, Any}
read_dataset(
decompressed_path::String,
dtype::String
) -> Tuple{Any, Any, Any}
Read the dataset of type dtype
at the decompressed_path
location. The dataset is made of images of Warcraft terrains, cell cost labels and shortest path labels. They are returned separately, with proper axis permutation and image scaling to be consistent with Flux
embeddings.