-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
31 lines (28 loc) · 952 Bytes
/
main.py
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
import serverCommunication
from algorithm import Algorithm
from config import config
stopped = False
algorithm = Algorithm()
def main(max_its=None, verbose=True):
run_id = 0
if verbose: print "-- Starting --"
while not stopped:
for i in range(50000):
context = serverCommunication.getContext(run_id, i)
ad_data = algorithm.make_selection(context)
datalist = (ad_data['header'], ad_data['adtype'], ad_data['color'],
ad_data['productid'], ad_data['price'])
result = serverCommunication.proposePage(run_id, i, *datalist)
algorithm.learn(context, ad_data, result)
if verbose and i % config['updateinterval'] == 0:
print "Iteration #{}".format(i)
if i % config['saveinterval'] == 0:
algorithm.save()
if verbose: print "Saved"
if max_its is not None and run_id * 50000 + i > max_its:
if verbose: print "-- Stopping --"
return
run_id+=1
run_id = run_id % 50000
if __name__ == "__main__":
main()