Skip to content

Commit f52a622

Browse files
authored
Tests for default score, probability floor, and top score tie-breaking (#52)
* tests for default score, probability floor, and top score tie-breaking * actually add the test case * fix up banditReferences * add comments to new test cases * grammar tweak
1 parent 5034cc5 commit f52a622

File tree

3 files changed

+131
-2
lines changed

3 files changed

+131
-2
lines changed

ufc/bandit-flags-v1.json

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,31 @@
201201
}
202202
],
203203
"totalShards": 10000
204+
},
205+
"car_bandit_flag": {
206+
"key": "car_bandit",
207+
"enabled": true,
208+
"variationType": "STRING",
209+
"variations": {
210+
"car_bandit": {
211+
"key": "car_bandit",
212+
"value": "car_bandit"
213+
}
214+
},
215+
"allocations": [
216+
{
217+
"key": "all-traffic",
218+
"rules": [],
219+
"splits": [
220+
{
221+
"variationKey": "car_bandit",
222+
"shards": []
223+
}
224+
],
225+
"doLog": true
226+
}
227+
],
228+
"totalShards": 10000
204229
}
205230
},
206231
"bandits": {
@@ -218,6 +243,14 @@
218243
"variationValue": "banner_bandit"
219244
}
220245
],
246+
"car_bandit": [
247+
{
248+
"key": "car_bandit",
249+
"flagKey": "car_bandit_flag",
250+
"variationKey": "car_bandit",
251+
"variationValue": "car_bandit"
252+
}
253+
],
221254
"cold_start_bandit": [
222255
{
223256
"key": "cold_start_bandit",
@@ -233,20 +266,39 @@
233266
{
234267
"key": "banner_bandit",
235268
"flagKey": "banner_bandit_flag",
236-
"allocationKey": "banner_bandit_allocation",
269+
"allocationKey": "analysis",
270+
"variationKey": "banner_bandit",
271+
"variationValue": "banner_bandit"
272+
},
273+
{
274+
"key": "banner_bandit",
275+
"flagKey": "banner_bandit_flag",
276+
"allocationKey": "training",
237277
"variationKey": "banner_bandit",
238278
"variationValue": "banner_bandit"
239279
},
240280
{
241281
"key": "banner_bandit",
242282
"flagKey": "banner_bandit_flag_uk_only",
243-
"allocationKey": "banner_bandit_uk_allocation",
283+
"allocationKey": "training",
244284
"variationKey": "banner_bandit",
245285
"variationValue": "banner_bandit"
246286
}
247287
],
248288
"modelVersion": "v123"
249289
},
290+
"car_bandit": {
291+
"flagVariations": [
292+
{
293+
"key": "car_bandit",
294+
"flagKey": "car_bandit_flag",
295+
"allocationKey": "all-traffic",
296+
"variationKey": "car_bandit",
297+
"variationValue": "car_bandit"
298+
}
299+
],
300+
"modelVersion": "v456"
301+
},
250302
"cold_start_bandit": {
251303
"flagVariations": [
252304
{

ufc/bandit-models-v1.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,31 @@
106106
}
107107
}
108108
},
109+
"car_bandit": {
110+
"banditKey": "car_bandit",
111+
"modelName": "falcon",
112+
"updatedAt": "2023-09-13T04:52:06.462Z",
113+
"modelVersion": "v456",
114+
"modelData": {
115+
"gamma": 1.0,
116+
"defaultActionScore": 5.0,
117+
"actionProbabilityFloor": 0.2,
118+
"coefficients": {
119+
"toyota": {
120+
"actionKey": "toyota",
121+
"intercept": 1.0,
122+
"actionNumericCoefficients": [{
123+
"attributeKey": "speed",
124+
"coefficient": 1,
125+
"missingValueCoefficient": 0.0
126+
}],
127+
"actionCategoricalCoefficients": [],
128+
"subjectNumericCoefficients": [],
129+
"subjectCategoricalCoefficients": []
130+
}
131+
}
132+
}
133+
},
109134
"cold_start_bandit": {
110135
"banditKey": "cold_start_bandit",
111136
"modelName": "falcon",
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"flag": "car_bandit_flag",
3+
"defaultValue": "default",
4+
"subjects": [
5+
{
6+
"comment": "Tests that probability floor is applied. These actions shuffle to: Mercedes, Dodge, Toyota. Without minimum probability floors, Toyota gets most of the weight, and that's what gets assigned. However, with a probability floor, the other actions each get a non-trivial shard range, so it is not assigned. If the probability floor is not normalized (divided by the number of actions), then the first action, Mercedes, will be assigned too many shards and get assigned. Only when it's non-zero and normalized does Anastasia get correctly assigned the middle action: Dodge.",
7+
"subjectKey": "anastasia",
8+
"subjectAttributes": {},
9+
"actions": [
10+
{
11+
"actionKey": "dodge",
12+
"numericAttributes": {},
13+
"categoricalAttributes": {}
14+
},
15+
{
16+
"actionKey": "mercedes",
17+
"numericAttributes": {},
18+
"categoricalAttributes": {}
19+
},
20+
{
21+
"actionKey": "toyota",
22+
"numericAttributes": {"speed": 1000},
23+
"categoricalAttributes": {}
24+
}
25+
],
26+
"assignment": {"variation": "car_bandit", "action": "dodge"}
27+
},
28+
{
29+
"comment": "Tests that default action scores are applied and top-scoring actions are tie-broken by name. These actions shuffle to: Toyota, Honda, Ford. If the default action score is ignored and the unknown (non-Toyota) actions get scored 0, Toyota takes up too many shards and that is what is assigned. With the default score at play, the two unknown actions are top-scoring and get most of the shards. However, because of the top scoring action weight of 1 - all other action weights, the top scoring action gets the most. When not tie-broken, implementations like JavaScript that iterate over them in order would declare Honda the top-scoring action, and it would end up getting assigned. However, when breaking ties by action name, Ford takes the prize and gets assigned. Thus, for this test to pass with Ford being assigned to Bob, the default action scores need to be respected, and top-scoring actions need to be tie-broken by name.",
30+
"subjectKey": "bob",
31+
"subjectAttributes": {},
32+
"actions": [
33+
{
34+
"actionKey": "toyota",
35+
"numericAttributes": {"speed": 1},
36+
"categoricalAttributes": {}
37+
},
38+
{
39+
"actionKey": "honda",
40+
"numericAttributes": {},
41+
"categoricalAttributes": {}
42+
},
43+
{
44+
"actionKey": "ford",
45+
"numericAttributes": {},
46+
"categoricalAttributes": {}
47+
}
48+
],
49+
"assignment": {"variation": "car_bandit", "action": "ford"}
50+
}
51+
]
52+
}

0 commit comments

Comments
 (0)