class MultiArmedBandit::MultiplePlayTS
Attributes
alpha[RW]
arm_ids[RW]
beta[RW]
k[RW]
l[RW]
Public Class Methods
new(k, l, setseed=true)
click to toggle source
k: num of arms l: num of selected arms
# File lib/multi_armed_bandit/mp_ts.rb, line 11 def initialize(k, l, setseed=true) @k = k @l = l @r = SimpleRandom.new # By default the same random seed is used, so we change it @r.set_seed if setseed==true reset end
Public Instance Methods
get_selected_arms()
click to toggle source
Get selected arm ids
# File lib/multi_armed_bandit/mp_ts.rb, line 27 def get_selected_arms selected_arms = @alpha.zip(@beta).zip(@arm_ids) .map{|c,i| [i, @r.beta(c[0],c[1])]} .sort_by{|v| -v[1]} .map{|v| v[0]}[0..@l-1] end
reset()
click to toggle source
# File lib/multi_armed_bandit/mp_ts.rb, line 20 def reset @alpha = Array.new(@k, 1) @beta = Array.new(@k, 1) @arm_ids = Array.new(@k, '') end
update_params_draw(selected_arms)
click to toggle source
selected_arms: List of selected drawn arms
# File lib/multi_armed_bandit/mp_ts.rb, line 35 def update_params_draw(selected_arms) selected_arms.map{|i| @beta[i]+=1} end
update_params_reward(idx)
click to toggle source
idx: Index number of rewarded arm
# File lib/multi_armed_bandit/mp_ts.rb, line 40 def update_params_reward(idx) @alpha[idx]+=1 @beta[idx]-=1 end