-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/dourouc05/CombinatorialBa…
…ndits.jl into master
- Loading branch information
Showing
2 changed files
with
44 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# OSSB (optimal sampling for structured bandits). | ||
# Based on https://arxiv.org/abs/1711.00400. | ||
|
||
abstract type OSSBOptimisationAlgorithm end | ||
function optimise_ossb(instance::CombinatorialInstance{T}, ::OSSBOptimisationAlgorithm, | ||
weights::Dict{T, Float64}) where T end | ||
|
||
mutable struct OSSB <: Policy | ||
algo::OSSBOptimisationAlgorithm | ||
end | ||
|
||
mutable struct OSSBDetails <: PolicyDetails | ||
n_iterations::Int | ||
solver_time::Float64 | ||
|
||
function OSSBDetails() | ||
return new(0, 0.0) | ||
end | ||
end | ||
|
||
function choose_action(instance::CombinatorialInstance{T}, policy::ESCB2, state::State{T}; with_trace::Bool=false) where T | ||
# For initialisation, if some arms have never been tried, force them to be tried. | ||
# This should not be required for OSSB, but it improves running times for the first few iterations. | ||
if any(v == 0 for v in values(state.arm_counts)) | ||
weights = Dict(arm => iszero(state.arm_counts[arm]) ? 1.0 : 0.0 for arm in keys(state.arm_counts)) | ||
|
||
t0 = time_ns() | ||
sol = solve_linear(instance, weights) | ||
t1 = time_ns() | ||
|
||
if with_trace | ||
run_details = OSSBDetails() | ||
run_details.n_iterations = 1 | ||
run_details.solver_time = (t1 - t0) / 1_000_000_000 | ||
return sol, run_details | ||
else | ||
return sol | ||
end | ||
end | ||
|
||
# Solve OSSB's problem. | ||
return optimise_ossb(instance, policy.algo, state.arm_average_reward, with_trace=with_trace) | ||
end |
d46ad4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JuliaRegistrator register
d46ad4e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error while trying to register: "Tag with name
v0.1.3
already exists and points to a different commit"