-
Notifications
You must be signed in to change notification settings - Fork 9
/
guide.html
507 lines (416 loc) · 21.2 KB
/
guide.html
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
<!DOCTYPE html>
<html>
<head>
<title>Decision Service Web API</title>
<meta charset="utf-8" />
<link href="bower_components/jsoneditor/dist/jsoneditor.min.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="bower_components/jsoneditor/dist/jsoneditor.min.js"></script>
<link rel="stylesheet" type="text/css" href="Content/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="Content/site.css" />
</head>
<body style="max-width:1400px; margin:0 auto">
<div class="navbar navbar-inverse navbar-fixed-top" style="background-color:black; color:white">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a href="/index.html">Guide</a></li>
<li><a href="/playground.html">Playground</a></li>
<li><a href="/game.html">Test Game</a></li>
</ul>
</div>
</div>
</div>
<br />
<div class="section" style="width:100%;">
<p align="center" class="lead">
Suppose we have a scenario where we need to choose from a set of actions
</p>
<p align="center" style="font-weight:100">
Let's say we have 4 news articles:
</p>
</div>
<br />
<div class="row" style="text-align: center; margin: 0 auto; max-width:1400px">
<div class="col-md-3">
<div class="thumbnail" style="overflow:hidden">
<div class="caption article">
<div style="width: 230px; height: 200px; overflow:hidden; margin:0 auto">
<img style="width: 230px; height: 316.8px;" src="https://upload.wikimedia.org/wikipedia/commons/4/42/Michael_R_Bloomberg.jpg" alt="...">
</div>
<p style="margin-bottom: 0px; margin-top: 10px;">Bloomberg says he will not enter presidential race</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="thumbnail" style="overflow:hidden">
<div class="caption">
<div style="width: 230px; height: 200px; overflow:hidden; margin:0 auto">
<img style="width: 260.7px; height: 200px; margin-left:-10px" src="https://upload.wikimedia.org/wikipedia/commons/2/28/Artificial-intelligence-elon-musk-hawking.jpg" alt="...">
</div>
<p style="margin-bottom: 0px; margin-top: 10px;">What counts as artificially intelligent? AI explained</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="thumbnail" style="overflow:hidden">
<div class="caption">
<div style="width: 230px; height: 200px; overflow:hidden; margin:0 auto">
<img style="width: 360px; height: 200px; overflow:hidden; margin-left:-60px" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg/1280px-Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg" alt="...">
</div>
<p style="margin-bottom: 0px; margin-top: 10px;">Why the Fed isn't out of options yet</p>
</div>
</div>
</div>
<div class="col-md-3">
<div class="thumbnail" style="overflow:hidden">
<div class="caption">
<div style="width: 230px; height: 200px; overflow:hidden; margin:0 auto">
<img style="width: 355px; height: 200px; overflow:hidden; margin-left:-60px; margin-bottom:-60px" src="https://c2.staticflickr.com/6/5571/15100639546_d1d29d8ee0_b.jpg" alt="...">
</div>
<p style="margin-bottom: 0px; margin-top: 10px;">12 great animated movies not made by Disney</p>
</div>
</div>
</div>
</div>
<br />
<p align="center" style="font-weight:100">
We will show how to use the decision service to decide on the best article based on the user's location
</p>
<br /><br /><br /><br /> <br />
<p class="lead" style="text-align:center;">1. Enter authorization token</p>
<div class="input-group" style="margin: 0 auto; width:300px">
<div class="input-group-addon" style="color:black">Authorization token: </div>
<input type="text" class="form-control" id="userToken" placeholder="Web service token">
</div>
<br /><br />
<div id="context">
<p class="lead" style="text-align:center">2. Make a Decision</p>
<p style="font-weight:100; text-align:center">
The decision service makes it easy to make smarter decisions using the context you have available.
<!--It might be information
about the user or simply an ID for the campaign. -->
</p>
<p style="font-weight:100; text-align:center">Let's apply the decision service to a smart news application. The first step is to use the context available to make a decision.</p>
<div class="row">
<div class="col-md-4">
<div class="thumbnail" style="text-align: center; margin: 0 auto; display: table; width:200px;">
<div class="caption">
<p>Location:</p>
<div class="radio" style="text-align:left">
<label><input type="radio" name="optradio" checked="checked" value="Seattle" id="contextDefaultRadio">Seattle</label>
</div>
<div class="radio" style="text-align:left">
<label><input type="radio" name="optradio" value="DC">Washington D.C.</label>
</div>
<div class="radio" style="text-align:left">
<label><input type="radio" name="optradio" value="NYC">New York City</label>
</div>
<button id="getDecision" type="button" class="btn btn-default">Decide</button>
</div>
</div>
</div>
<div class="col-md-8">
<div class="decisionRequest">
<div style="background-color:#e9f2ff; border-color:green; border-width:2px; border-style:solid; padding:10px 10px 10px 10px; border-radius:5px 5px;">
<code>
POST request URL:
<div class=" Field FieldName-fieldExampleRequest FieldType-textLong FieldLabel-hidden "><div class="Field-items"><div class="Field-items-item even "><pre>https://{hostname}/ranker</pre></div></div>
</div>
Request body:
<pre id="decisionRequestBody">{"Location":"Seattle"}</pre>
</code>
</div>
</div>
</div>
</div>
</div>
<br />
<br />
<div hidden id="decision">
<div id="decisionResponseDiv">
<p style="font-weight:100">The decision service returns an "action". In our example, this is a news article that was chosen based on the location.</p>
<div class="row">
<div class="col-md-4">
<div class="thumbnail" style="overflow:hidden; width:260px; margin:auto; text-align: center;">
<div class="caption">
<div style="width: 230px; height: 200px; overflow:hidden">
<img id="articleImage" style="width: 360px; height: 200px; margin-left:-60px" src="https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg/1280px-Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg" alt="...">
</div>
<p id="story" style="margin-bottom: 0px; margin-top: 10px;">Why the Fed isn't out of options</p>
</div>
</div>
</div>
<div class="col-md-8">
<div style="background-color:#e9f2ff; border-color:green; border-width:2px; border-style:solid; padding:10px 10px 10px 10px; border-radius:5px 5px;">
<code>
Response body:
<div class=" Field FieldName-fieldExampleRequest FieldType-textLong FieldLabel-hidden "><div class="Field-items"><div class="Field-items-item even "><pre id="decisionResponse">{"Action" : 1, "EventId" : "BLABLABLA", "Timestamp" : "Wednesday"}</pre></div></div>
</div>
</code>
</div>
</div>
</div>
</div>
<hr />
<div id="rewardDiv">
<p class="lead" style="text-align:center">3. Assign a Reward</p>
<p style="font-weight:100">We now need to report whether the action was successful or not so the decision service can learn to make better decisions. If this user clicks on the article, a reward of 1 is sent. Otherwise, a reward of 0 is sent.</p>
<div class="row">
<div class="col-md-4">
<div class="thumbnail" style="text-align: center; margin: 0 auto; display: table; width:200px;">
<div class="caption">
<p>Reward:</p>
<div class="radio" style="text-align:left">
<label><input type="radio" name="rewardRadio" checked="checked" value="Click" id="rewardDefaultRadio">1 - click</label>
</div>
<div class="radio" style="text-align:left">
<label><input type="radio" name="rewardRadio" value="NoClick">0 - no click</label>
</div>
<button id="submitReward" type="button" class="btn btn-default">Submit</button>
</div>
</div>
</div>
<div class="col-md-8">
<div style="background-color:#e9f2ff; border-color:green; border-width:2px; border-style:solid; padding:10px 10px 10px 10px; border-radius:5px 5px;">
<code>
POST request URL:
<div class=" Field FieldName-fieldExampleRequest FieldType-textLong FieldLabel-hidden "><div class="Field-items"><div class="Field-items-item even "><pre id="rewardRequest">https://{hostname}/api/reward?reward={float}&eventId={EventId}&timestamp={timestamp}</pre></div></div>
</div>
</code>
</div>
</div>
</div>
</div>
</div>
<div hidden id="training">
<hr />
<p class="lead" style="text-align:center">4. Repeat and make smarter decisions</p>
<p style="font-weight:100">
The decision service uses the information above to learn a model that maximizes reward. By collecting more and more data,
the service continuously improves upon the existing model."
</p>
<button id="resetButton" type="button" class="btn btn-default" style="text-align: center; margin: 0 auto; display: table; width:200px;">Next decision</button>
</div>
<script type="text/javascript" src="scripts/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="scripts/bootstrap.js"></script>
<script>
// create the editor
var container = document.getElementById("jsoneditor");
var options = {
mode: 'code',
modes: ['code', 'tree'], // allowed modes
};
var editor = new JSONEditor(container, options);
// set json
var json = {
"Age": 25,
"Location": "New York",
_multi: [
{"a":1},
{ "a": 2 }
]
};
editor.set(json);
var lastJson = "";
setInterval(function () {
var newJson = editor.getText();
if (lastJson == newJson)
return;
lastJson = newJson;
$.ajax({
method: "POST",
url: "/vowpalWabbitValidation",
data: newJson,
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": $("#userToken").val()
},
})
.done(function (data) {
$("#vwstr").html("<pre>" + data + "</pre>");
})
.fail(function (jqXHR, textStatus, errorThrown) {
$("#vwstr").html("<font color='red'>" + jqXHR.responseJSON.ExceptionMessage + "</font>");
});
}, 500);
setInterval(function () {
$(".authKeyText").text($("#userToken").val());
}, 500);
function Submit()
{
// Get Decision
$.ajax({
method: "POST",
url: "/ranker",
data: editor.getText(),
contentType: "application/json; charset=utf-8",
dataType: "json",
headers: {
"Authorization": $("#userToken").val()
},
})
.done(function (data) {
$("#statusDecision").text("Success");
$("#EventId").text(data.EventId);
$("#rewardEventId").text(data.EventId);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$("#status").text("Error: " + textStatus + " " + errorThrown);
});
}
function SubmitReward() {
$.ajax({
method: "POST",
url: "/reward/" + $("#EventId").text(),
data: $("#reward").val(),
headers: {
"Authorization": $("#userToken").val()
},
})
.done(function (data) {
$("#statusReward").text("Success");
$("#EventId").text(data.EventId);
$("#TimeStamp").text(data.TimeStamp);
})
.fail(function (jqXHR, textStatus, errorThrown) {
$("#status").text("Error: " + textStatus + " " + errorThrown);
});
}
var eventId;
var timestamp;
$(document).ready(function () {
// Set up radio button listeners to update the HTTP request examples
// Context radio buttons
$("input[name='optradio']").change(function () {
if ($("input[name='optradio']:checked").val() == 'Seattle')
$("#decisionRequestBody").text('{"Location":"Seattle"}');
else if ($("input[name='optradio']:checked").val() == 'DC')
$("#decisionRequestBody").text('{"Location":"DC"}');
else {
$("#decisionRequestBody").text('{"Location":"NYC"}');
}
});
// Reward radio buttons
$("input[name='rewardRadio']").change(function () {
// TODO: show reward as body
if ($("input[name='rewardRadio']:checked").val() == 'Click')
$("#rewardRequest").text("https://{hostname}/api/reward/" + eventId);
else {
$("#rewardRequest").text("https://{hostname}/api/reward/" + eventId);
}
});
$("#decision").hide();
var decision;
// Make decision request and show the response and reward sections
$("#getDecision").click(function () {
// Get Decision
$.ajax({
method: "POST",
url: "http://decisiondemo.azurewebsites.net/Home/Decide?location=" + $("input[name='optradio']:checked").val(),
headers: { "Content-Type": "application/json" }
})
.done(function (msg) {
decision = (JSON.parse(msg))["Action"];
eventId = (JSON.parse(msg))["EventId"];
timestamp = (JSON.parse(msg))["TimeStamp"];
$("#decisionResponse").text(msg);
showDecision(decision);
});
});
function showDecision(decision) {
// Show Decision
$("#decision").show();
switch (decision) {
case 1:
$("#articleImage").attr("src", "https://upload.wikimedia.org/wikipedia/commons/4/42/Michael_R_Bloomberg.jpg");
$("#articleImage").width(230);
$("#articleImage").height(316.8);
$("#articleImage").css("margin-left", "0px");
$("#articleImage").css("margin-bottom", "0px");
$("#articleImage").css("margin-top", "0px");
$("#story").text("Bloomberg says he will not enter presidential race");
break;
case 2:
$("#articleImage").attr("src", "https://upload.wikimedia.org/wikipedia/commons/2/28/Artificial-intelligence-elon-musk-hawking.jpg");
$("#articleImage").width(260.7);
$("#articleImage").height(200);
$("#articleImage").css("margin-left", "-10px");
$("#articleImage").css("margin-bottom", "0px");
$("#articleImage").css("margin-top", "0px");
$("#story").text("What counts as artificially intelligent? AI explained");
break;
case 3:
$("#articleImage").attr("src", "https://upload.wikimedia.org/wikipedia/commons/thumb/8/8d/Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg/1280px-Marriner_S._Eccles_Federal_Reserve_Board_Building.jpg");
$("#articleImage").width(360);
$("#articleImage").height(200);
$("#articleImage").css("margin-left", "-60px");
$("#articleImage").css("margin-bottom", "0px");
$("#articleImage").css("margin-top", "0px");
$("#story").text("Why the Fed isn't out of options");
break;
case 4:
$("#articleImage").attr("src", "https://c2.staticflickr.com/6/5571/15100639546_d1d29d8ee0_b.jpg");
$("#articleImage").width(355);
$("#articleImage").height(200);
$("#articleImage").css("margin-left", "-60px");
$("#articleImage").css("margin-bottom", "-60px");
$("#articleImage").css("margin-top", "0px");
$("#story").text("12 great animated movies not made by Disney");
break;
default:
$("#headline").text("Something went wrong!");
}
// Update reward request
// TODO: reward=1 needs to be passed as data
$("#rewardRequest").text("https://{hostname}/reward/" + eventId);
// Disable decide button
$("#getDecision").prop("disabled", true);
$('html, body').animate({
scrollTop: $(document).height() - $(window).height()
},
1000
);
}
// Submit reward
$("#submitReward").click(function () {
var rewardRequest = $("#rewardRequest").text();
var rewardRequestSplit = rewardRequest.split('/');
var rewardRequestParams = rewardRequestSplit[rewardRequestSplit.length - 1];
$.ajax({
method: "POST",
url: "http://decisiondemo.azurewebsites.net/Home/" + rewardRequestParams,
headers: { "Content-Type": "application/json" }
})
.done(function (msg) {
$("#training").show();
$('html, body').animate({
scrollTop: $(document).height() - $(window).height()
},
1000
);
});
});
$("#resetButton").click(function () {
// Hide decision and enable decision button
$("#getDecision").prop("disabled", false);
$("#storyClick").prop("disabled", false);
$("#storyNoClick").prop("disabled", false);
$("#decision").hide();
$("#training").hide();
$("input:radio").prop("checked", false);
$("#contextDefaultRadio").prop("checked", true);
$("#rewardDefaultRadio").prop("checked", true);
$("#decisionRequestBody").text("{\"Location\": \"Seattle\"}");
});
});
</script>
</body>
</html>