-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlinear_bai.jl
161 lines (127 loc) · 5.08 KB
/
linear_bai.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
using JLD2;
using Distributed;
using Printf;
using IterTools;
using Distributions
include("../thresholds.jl")
include("../peps.jl")
include("../elimination_rules.jl")
include("../stopping_rules.jl")
include("../sampling_rules.jl")
include("../runit.jl")
include("../experiment_helpers.jl")
include("../utils.jl")
include("../envelope.jl")
δ = 0.01
d = 20
K = 50
m = 5 # for topm
# for reproducibility
rng = MersenneTwister(123)
arms = Vector{Float64}[]
mid = Int(ceil(d/2))
for k = 1:mid
v = zeros(d)
v[k] = 1.0
push!(arms, v)
end
θ = zeros(d)
θ[1] = 1
θ[2:Int(mid/2)] .= 0.9
θ[Int(mid/2)+1:mid] .= 0.8
θ[mid+1:end] = rand(rng, d-mid) .- 1 # uniform in [-0.5,0.5]
while length(arms) < K
v = zeros(d)
v[1] = 1100
while v'θ > 0.5
v = 2 .* rand(rng, d) .- 1 # Uniform in [-1,1]
v ./= norm(v) # make sure unit norm
end
push!(arms, v)
end
μ = [arm'θ for arm in arms]
topm_arms = istar(Topm(arms, m), θ)
println("min abs value of μ: ", minimum(abs.(μ)))
println("min gap: ", minimum(maximum(μ) .- maximum(μ[setdiff(1:K, Set([argmax(μ)]))])))
println("min gap topm: ", minimum(minimum(μ[topm_arms]) .- maximum(μ[setdiff(1:K, topm_arms)])))
# β = LinearThreshold(d, 1, 1, 1)
# β = GK16()
β = HeuristicThreshold()
pep = BAI(arms);
w_star = optimal_allocation(pep, θ, false, 10000)
println("Optimal allocation: ", round.(w_star, digits=3))
max_samples = 1e6
repeats = 100;
seed = 123;
function run()
# One fake run for each algorithm
# This is to have fair comparison of compute times later since Julia compiles stuff at the first calls
@time data = map( # TODO: replace by pmap (it is easier to debug with map)
((sampling, stopping, elim),) -> runit(seed, sampling, stopping, elim, θ, pep, β, δ),
zip(sampling_rules, stopping_rules, elim_rules)
);
@time data = map( # TODO: replace by pmap (it is easier to debug with map)
(((sampling, stopping, elim), i),) -> runit(seed + i, sampling, stopping, elim, θ, pep, β, δ),
Iterators.product(zip(sampling_rules, stopping_rules, elim_rules), 1:repeats),
);
dump_stats(pep, θ, δ, β, stopping_rules, sampling_rules, elim_rules, data, repeats);
# save
isdir("experiments/results") || mkdir("experiments/results")
@save isempty(ARGS) ? "experiments/results/lin_$(typeof(pep))_$(typeof(sampling_rules[1]))_K$(K)_d$(d).dat" : ARGS[1] θ pep stopping_rules sampling_rules elim_rules data δ β repeats seed
end
#################################################
# LinGapE
#################################################
elim_rules = [NoElim(), CompElim(), CompElim()]
stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
sampling_rules = [LinGapE(NoElimSR), LinGapE(NoElimSR), LinGapE(ElimSR)]
run()
#################################################
# LinGame
#################################################
elim_rules = [NoElim(), CompElim(), CompElim()]
stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
sampling_rules = [LinGame(CTracking, NoElimSR, false), LinGame(CTracking, NoElimSR, false), LinGame(CTracking, ElimSR, false)]
run()
#################################################
# Oracle
#################################################
elim_rules = [NoElim(), CompElim()]
stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
sampling_rules = [FixedWeights(w_star), FixedWeights(w_star)]
run()
#################################################
# LazyTaS
#################################################
elim_rules = [NoElim(), CompElim(), CompElim()]
stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
sampling_rules = [LazyTaS(NoElimSR), LazyTaS(NoElimSR), LazyTaS(ElimSR)]
run()
#################################################
# FWS
#################################################
elim_rules = [NoElim(), CompElim(), CompElim()]
stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
sampling_rules = [FWSampling(NoElimSR), FWSampling(NoElimSR), FWSampling(ElimSR)]
run()
#################################################
# XY-Adaptive
#################################################
elim_rules = [NoElim()]
stopping_rules = [NoStopping()]
sampling_rules = [XYAdaptive()]
run()
#################################################
# RAGE
#################################################
elim_rules = [NoElim()]
stopping_rules = [NoStopping()]
sampling_rules = [RAGE()]
run()
#################################################
# LinGIFA
#################################################
# elim_rules = [NoElim(), CompElim()]
# stopping_rules = [Force_Stopping(max_samples, LLR_Stopping()), Force_Stopping(max_samples, Elim_Stopping())]
# sampling_rules = [LinGIFA(), LinGIFA()]
# run()