-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
72 lines (49 loc) · 1.97 KB
/
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
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
__author__ = 'Janin Koch'
import bandit
from ast import literal_eval
VectorList = []
# initiating bandits
def initiateBandit(name):
# 0: bandit dimensions
context_dimension = (6, 2, 2, 2, 2) # H = 60
decision_dimension = (3, 2, 2, 2, 3) # H = 20
arm_dimensions = (4, 1, 1, 1, 1) # H = 5
# 1: Get prior data
# prior_data = get_prior_data()
prior_data = []
# 2: Get user history
#user_data = get_user_data(name)
user_data = []
# 3: set up bandit and context space
cBandit = bandit.ContextualBandit(arm_dimensions, decision_dimension, context_dimension, user_data, prior_data)
return cBandit
def addVector(Vector,cBandit):
# Vector: (H (0-360), S (0-1), L (0-1), O (0,1), Dist (0,60,120))
VectorList.append(Vector)
#If key_selected in Empty
if not cBandit.key_selected:
cBandit.key_selected.append(Vector)
def newVector(cBandit):
#receive new image vector based on VectorList
cBandit, context, next_image, expected_reward = cBandit.suggest_images()
return next_image
if __name__ == "__main__":
banditObj = initiateBandit('Janin')
#Input Image after processing
currentVector = raw_input("What is your initial image (H:0-360, S:0-1, L:0-1, O:0,1, Dist:0-180) => e.g (123,0.6,0.3,0,178): ")
#Add image to bandit Object
addVector(literal_eval(currentVector),banditObj)
#Keep Suggesting images until decision == 'quit'
while (True):
nextImage = newVector(banditObj)
print "New image characteristics: ", nextImage
decision = raw_input("would you like to use this image? (y/n/quit) ")
if (decision=="y"):
addVector(nextImage,banditObj)
bandit.update_bandit(banditObj, 1, VectorList )
elif (decision=="n"):
addVector(nextImage,banditObj)
bandit.update_bandit(banditObj, 0, VectorList )
elif (decision=="quit"):
print "Thank you"
break #Ending the session