-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbcc.html
More file actions
184 lines (141 loc) · 6.4 KB
/
bcc.html
File metadata and controls
184 lines (141 loc) · 6.4 KB
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
<!DOCTYPE html><html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Probability Calculator - jsFiddle demo</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.4/angular.min.js"></script><style type="text/css">@charset "UTF-8";[ng\:cloak],[ng-cloak],[data-ng-cloak],[x-ng-cloak],.ng-cloak,.x-ng-cloak{display:none;}ng\:form{display:block;}</style>
<script type="text/javascript" src="https://rawgithub.com/prajwalkman/angular-slider/master/angular-slider.min.js"></script><style type="text/css"></style>
<link rel="stylesheet" type="text/css" href="https://rawgithub.com/prajwalkman/angular-slider/master/angular-slider.min.css">
<script type="text/javascript" src="http://d3js.org/d3.v3.js"></script>
<link rel="stylesheet" type="text/css" href="http://twitter.github.io/bootstrap/assets/css/bootstrap.css">
<style type="text/css">
.axis path, .axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.line {
fill: none;
stroke: steelblue;
stroke-width: 1.5px;
}
.vertex {
fill: #1f77b4;
fill-opacity: 1;
stroke: #999;
stroke-opacity: .5;
}
</style>
<script type="text/javascript">//<![CDATA[
var app = angular.module('app', ['uiSlider']);
function km(days, day, prob) {
daily = 1 - Math.pow(1.0 - prob / 100, 1.0 / days);
bottom = Math.pow(1 - daily, days) / days;
top_terms = d3.range(1, days - day + 2).map(function (i) {
return daily * Math.pow(1 - daily, days - i) / (days + 1 - i);
});
top_sum = d3.sum(top_terms);
return (top_sum / (top_sum + bottom)) * 100;
};
function Controller($scope) {
$scope.probability = 75;
$scope.days = 10;
function refresh() {
days = parseInt($scope.days);
prob = parseInt($scope.probability);
data = d3.range(1, days + 1).map(function (i) {
return {
day: i,
prob: km(days, i, prob)
}
});
x.domain([1, days]);
d3x.call(xAxis);
svg.select("path.line")
.attr("d", line(data));
svg.selectAll("circle.vertex")
.remove();
svg.selectAll("circle.vertex")
.data(data)
.enter().append("circle")
.attr("cx", function (d, i) {return x(d.day)})
.attr("cy", function (d, i) {return y(d.prob)})
.attr("r", 2)
.attr("class", "vertex")
.append("title")
.text(function (d, i) {
return "Day " + d.day + " : " + Math.round(d.prob) + "%";
});
}
$scope.$watch('days', refresh, true);
$scope.$watch('probability', refresh, true);
}
//]]>
</script>
</head>
<body ng-app="app" class="ng-scope">
<div class="container">
<h1>Probability Calculator</h1>
<p>
This computes the "optimal" (as opposed to "honest") probability estimate that will minimize your averaged daily Brier score on a "contingent stopping" question, i.e. one which closes when an event is realized.
</p>
<p>
The calculator takes two inputs:</p>
<ol>
<li>the number of days until the event's deadline <b>when the question opened</b></li>
<li>your best estimate <b>at that time</b> of the overall probability over that entire period</li>
</ol>
<p>The calculator will assume that the event has equal and independent probability of happening on any given day, and will infer that daily probability from the overall probability you gave.
</p>
<p>
The calculator will then compute for all days until the deadline the probability forecast that minimizes your Brier score, at least "in theory" (that is, if a number of assumptions are verified, none of which will be spelled out here).
</p>
<div ng-controller="Controller" class="ng-scope">
<label for="prob">Starting probability</label>
<slider style="width:40%" floor="1" ceiling="99" step="1" precision="0" ng-model="probability" id="prob" class="ng-isolate-scope ng-scope ng-pristine ng-valid"><span class="bar"></span><span class="pointer" style="left: 117.040816326531px;"></span><span ng-bind-html-unsafe="translate({value: floor})" class="bubble limit ng-binding" style="opacity: 1;">1</span><span ng-bind-html-unsafe="translate({value: ceiling})" class="bubble limit ng-binding" style="left: 159px; opacity: 1;">99</span><span class="bubble ng-binding" ng-bind-html-unsafe="translate({value: ngModel})" style="left: 119px;">75</span></slider>
<label for="days">Total number of days</label>
<slider style="width:40%" floor="2" ceiling="365" step="1" precision="0" ng-model="days" id="days" class="ng-isolate-scope ng-scope ng-pristine ng-valid"><span class="bar"></span><span class="pointer" style="left: 3.41597796143251px;"></span><span ng-bind-html-unsafe="translate({value: floor})" class="bubble limit ng-binding" style="opacity: 0;">2</span><span ng-bind-html-unsafe="translate({value: ceiling})" class="bubble limit ng-binding" style="left: 152px; opacity: 1;">365</span><span class="bubble ng-binding" ng-bind-html-unsafe="translate({value: ngModel})" style="left: 5px;">10</span></slider>
</div>
<script>
var margin = {
top: 20,
right: 20,
bottom: 30,
left: 50
},
width = 760 - margin.left - margin.right,
height = 300 - margin.top - margin.bottom;
var parseDate = d3.time.format("%d-%b-%y").parse;
var x = d3.scale.linear()
.range([0, width]);
var y = d3.scale.linear()
.range([height, 0]);
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var yAxis = d3.svg.axis()
.scale(y)
.orient("left");
var line = d3.svg.line()
.x(function(d) {
return x(d.day);
})
.y(function(d) {
return y(d.prob);
});
var svg = d3.select("div.container").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom)
.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
x.domain([1, 2]);
y.domain([0, 100]);
var d3x = svg.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + height + ")")
.call(xAxis);
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
svg.append("path")
.attr("class", "line");
</script>
</body></html>