-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathrun_MAB.py
More file actions
40 lines (34 loc) · 1.06 KB
/
run_MAB.py
File metadata and controls
40 lines (34 loc) · 1.06 KB
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
"""
run_MAB.py
James Wang
Nov 29. 2014
"""
from environment.rejection_MAB import RejectionMAB
from policy.UCB import UCB, IndexedUCB, KLUCB
from policy.thompson import Thompson
from policy.oblivious import Oblivious
from policy.epsilon_greedy import EpsilonGreedy
import sqlite3
import time
import datetime
db = 'data/final_copy.db'
conn = sqlite3.connect(db)
c = conn.cursor()
c.execute('SELECT articleID FROM article')
arms = [arm[0] for arm in c.fetchall()]
policies = [UCB(arms), IndexedUCB(arms, range(2, 7)), KLUCB(arms),
Thompson(arms), Oblivious(arms), EpsilonGreedy(arms),
EpsilonGreedy(arms, .2)]
conn.close()
n = 1000000
t0 = time.time()
MAB = RejectionMAB(db, n, range(2, 7), arms, policies)
MAB.run()
MAB.output_decisions('results4.gz')
print MAB.total_pulls
t1 = time.time()
the_time = str(datetime.timedelta(seconds=t1-t0))
print('Now: {}'.format(time.time()))
print('Took a total of {}'.format(the_time))
print('Number of pulls required to reach {} was {}'.format(n,
MAB.total_pulls))