/
TaxonomyExample.jl
155 lines (118 loc) · 3.88 KB
/
TaxonomyExample.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
function setuptaxonomy()
#set up taxonomy example
#observations
w_strings = ["Laptop","Monitor","Gamepad", #COMPUTERS
"Coffee machine","Vacuum cleaner","Electric toothbrush", #small APPLIANCES
"Grapes","Strawberries","Limes", #FRUIT
"Pancake mix","Baking soda","Baker's yeast","Muffin cups", #BAKING
]
num_obs = size(w_strings,1)
w_vec = collect(1:num_obs)
#actions
a_strings = ["Laptop sleeve","Monitor cable","Video game",
"Coffee","Vacuum cleaner bags","Brush heads",
"Cheese","Cream","Cane sugar",
"Maple syrup","Vinegar","Flour","Chocolate chips",
"COMPUTERS","APPLIANCES","FRUIT","BAKING","Electronics","Food"]
num_acts = size(a_strings,1)
a_vec = collect(1:num_acts)
#set up uniform p(w)
p_w = ones(num_obs)/num_obs
#define utility function
#(everything is hardcoded here, which is a bit hacky but will do the job)
#the function expects integer indices
function U(a::Integer,w::Integer)
u_correct_w = 3;
u_correct_category = 2.2;
u_correct_supercategory = 1.6;
#correct item
if a<14 && a==w
return u_correct_w
end
#flour is also fine for o=muffin cups
if w==13 && a==12
return u_correct_w
end
#For pancake mix both FRUIT and BAKING is fine
if w==10 && a==16
return u_correct_category
end
#extra if-clause is required for muffin cups
if w==13 && a==17
return u_correct_category
end
#correct category
if a<18
cat = ceil(w/3)
if (a-13) == cat
return u_correct_category
end
end
#correct supercategory
supcat = ceil(w/6)
if (a-17) == supcat
return u_correct_supercategory
end
#separate case for a==19
if a==19 && w==13
return u_correct_supercategory
end
#incorrect action
return 0
end
return w_vec, w_strings, a_vec, a_strings, p_w, U
end
function setuptaxonomy_animals_plants()
#set up taxonomy example
#observations
w_strings = ["Persian","Siamese","British Shorthair", #CATS
"German Shepherd","Rottweiler","Dachshund", #DOGS
"Oak","Birch","Pine", #TREES
"Rose","Dandelion","Sunflower", #FLOWERS
"Hibiscus" #Tree and flower (to break symmetry)
]
num_obs = size(w_strings,1)
w_vec = collect(1:num_obs)
#actions are observations + categories + supercategories
a_strings = [w_strings; "CAT";"DOG";"TREE";"FLOWER";"Animal";"Plant"]
num_acts = size(a_strings,1)
a_vec = collect(1:num_acts)
#set up uniform p(w)
p_w = ones(num_obs)/num_obs
#define utility function
#(everything is hardcoded here, which is a bit hacky but will do the job)
function U(a,w)
u_correct_w = 3;
u_correct_category = 2.2;
u_correct_supercategory = 1.6;
#correct observation
if w==a
return u_correct_w
end
#correct category
if w < 13
cat = ceil(w/3)
if (a-13) == cat
return u_correct_category
end
end
if w == 13 #hibiscus case
if (a==16 || a==17)
return u_correct_category
end
end
#correct supercategory
supcat = ceil(w/6)
if (a-17) == supcat
return u_correct_supercategory
end
if w == 13 #hibiscus case
if a==19
return u_correct_supercategory
end
end
#incorrect action
return 0
end
return w_vec, w_strings, a_vec, a_strings, p_w, U
end