-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalibration-lab.html
More file actions
352 lines (345 loc) · 13.6 KB
/
calibration-lab.html
File metadata and controls
352 lines (345 loc) · 13.6 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>AgentBox - Agent Calibration Lab</title>
<meta name="description" content="Interactive demo showing AI agent confidence calibration. Visualize reliability diagrams, Brier scores, overconfidence detection, and calibration adjustment in real-time.">
<style>
:root {
--bg: #0a0a0a;
--surface: #141414;
--surface-2: #1e1e1e;
--surface-3: #252525;
--border: #2a2a2a;
--text: #e8e8e8;
--text-muted: #888;
--accent: #00d4ff;
--accent-light: #66e5ff;
--accent-bg: #00d4ff15;
--green: #00b894;
--green-bg: #00b89422;
--yellow: #fdcb6e;
--yellow-bg: #fdcb6e22;
--orange: #e17055;
--orange-bg: #e1705522;
--red: #d63031;
--red-bg: #d6303122;
--purple: #6c5ce7;
--purple-bg: #6c5ce722;
--radius: 12px;
--radius-sm: 8px;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
background: var(--bg);
color: var(--text);
line-height: 1.6;
min-height: 100vh;
}
.header {
padding: 16px 32px;
display: flex;
align-items: center;
gap: 16px;
border-bottom: 1px solid var(--border);
position: sticky;
top: 0;
background: var(--bg);
z-index: 100;
backdrop-filter: blur(12px);
}
.header a { color: var(--accent); text-decoration: none; font-size: 14px; }
.header h1 { font-size: 18px; font-weight: 600; }
.container {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 24px;
max-width: 1400px;
margin: 0 auto;
padding: 24px 32px;
}
@media (max-width: 900px) { .container { grid-template-columns: 1fr; } }
.full-width { grid-column: 1 / -1; }
.panel {
background: var(--surface);
border: 1px solid var(--border);
border-radius: var(--radius);
padding: 24px;
}
.panel h2 {
font-size: 16px;
font-weight: 600;
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 8px;
}
.btn {
padding: 8px 16px;
border: 1px solid var(--border);
border-radius: var(--radius-sm);
background: var(--surface-2);
color: var(--text);
cursor: pointer;
font-size: 13px;
transition: all 0.2s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.active { background: var(--accent-bg); border-color: var(--accent); color: var(--accent); }
.btn-primary {
background: var(--accent);
color: #000;
border-color: var(--accent);
font-weight: 600;
}
.btn-primary:hover { background: var(--accent-light); }
.controls {
display: flex;
gap: 8px;
flex-wrap: wrap;
margin-bottom: 16px;
}
canvas {
width: 100%;
height: 300px;
border-radius: var(--radius-sm);
background: var(--surface-2);
}
.metric-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
gap: 12px;
margin-bottom: 16px;
}
.metric-card {
background: var(--surface-2);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
padding: 12px;
text-align: center;
}
.metric-card .value {
font-size: 24px;
font-weight: 700;
color: var(--accent);
}
.metric-card .label {
font-size: 11px;
color: var(--text-muted);
text-transform: uppercase;
letter-spacing: 0.5px;
margin-top: 4px;
}
.prediction-feed {
max-height: 320px;
overflow-y: auto;
display: flex;
flex-direction: column;
gap: 8px;
}
.prediction-item {
display: flex;
align-items: center;
gap: 10px;
padding: 10px 12px;
background: var(--surface-2);
border: 1px solid var(--border);
border-radius: var(--radius-sm);
font-size: 13px;
}
.prediction-item .conf-bar {
width: 60px;
height: 8px;
border-radius: 4px;
background: var(--surface-3);
position: relative;
overflow: hidden;
}
.prediction-item .conf-bar .fill {
position: absolute;
left: 0;
top: 0;
height: 100%;
border-radius: 4px;
transition: width 0.3s;
}
.prediction-item .outcome {
width: 20px;
height: 20px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 11px;
}
.outcome-correct { background: var(--green-bg); color: var(--green); }
.outcome-wrong { background: var(--red-bg); color: var(--red); }
.calibration-gauge {
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
padding: 20px;
}
.gauge-ring {
width: 160px;
height: 160px;
border-radius: 50%;
border: 12px solid var(--surface-3);
position: relative;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.gauge-ring .score { font-size: 36px; font-weight: 700; }
.gauge-ring .sub { font-size: 11px; color: var(--text-muted); }
.insight-list {
list-style: none;
display: flex;
flex-direction: column;
gap: 8px;
}
.insight-list li {
padding: 10px 12px;
background: var(--surface-2);
border-radius: var(--radius-sm);
border-left: 3px solid var(--accent);
font-size: 13px;
}
.insight-list li.warn { border-left-color: var(--orange); }
.insight-list li.danger { border-left-color: var(--red); }
.insight-list li.good { border-left-color: var(--green); }
.tabs {
display: flex;
gap: 4px;
margin-bottom: 16px;
border-bottom: 1px solid var(--border);
padding-bottom: 8px;
}
.tab {
padding: 6px 12px;
font-size: 12px;
border: none;
background: none;
color: var(--text-muted);
cursor: pointer;
border-radius: var(--radius-sm);
}
.tab.active { background: var(--accent-bg); color: var(--accent); }
.slider-group { margin: 12px 0; }
.slider-group label {
display: flex;
justify-content: space-between;
font-size: 12px;
color: var(--text-muted);
margin-bottom: 4px;
}
.slider-group input[type="range"] {
width: 100%;
accent-color: var(--accent);
}
.hidden { display: none !important; }
</style>
</head>
<body>
<div class="header">
<a href="index.html">← AgentBox</a>
<h1>🎯 Agent Calibration Lab</h1>
</div>
<div class="container">
<!-- Top controls -->
<div class="panel full-width">
<h2>⚙️ Simulation Controls</h2>
<div class="controls">
<button class="btn btn-primary" id="btn-run">▶ Run Simulation</button>
<button class="btn" id="btn-pause">⏸ Pause</button>
<button class="btn" id="btn-reset">↺ Reset</button>
<span style="border-left:1px solid var(--border);margin:0 8px"></span>
<button class="btn active" data-preset="overconfident">Overconfident Agent</button>
<button class="btn" data-preset="underconfident">Underconfident Agent</button>
<button class="btn" data-preset="wellcalibrated">Well-Calibrated</button>
<button class="btn" data-preset="random">Random Agent</button>
<button class="btn" data-preset="adaptive">Self-Correcting</button>
</div>
<div class="metric-grid">
<div class="metric-card"><div class="value" id="m-brier">—</div><div class="label">Brier Score</div></div>
<div class="metric-card"><div class="value" id="m-ece">—</div><div class="label">ECE</div></div>
<div class="metric-card"><div class="value" id="m-accuracy">—</div><div class="label">Accuracy</div></div>
<div class="metric-card"><div class="value" id="m-confidence">—</div><div class="label">Avg Confidence</div></div>
<div class="metric-card"><div class="value" id="m-overconf">—</div><div class="label">Overconf. Rate</div></div>
<div class="metric-card"><div class="value" id="m-predictions">0</div><div class="label">Predictions</div></div>
</div>
</div>
<!-- Reliability Diagram -->
<div class="panel">
<h2>📊 Reliability Diagram</h2>
<canvas id="reliability-canvas"></canvas>
<p style="font-size:11px;color:var(--text-muted);margin-top:8px">Perfect calibration = diagonal line. Bars above = overconfident. Below = underconfident.</p>
</div>
<!-- Calibration Gauge & Insights -->
<div class="panel">
<h2>🎯 Calibration Score</h2>
<div class="calibration-gauge">
<div class="gauge-ring" id="gauge">
<div class="score" id="gauge-score">—</div>
<div class="sub">/ 100</div>
</div>
</div>
<h2 style="margin-top:16px">💡 Autonomous Insights</h2>
<ul class="insight-list" id="insights">
<li>Run a simulation to generate insights...</li>
</ul>
</div>
<!-- Prediction Feed -->
<div class="panel">
<h2>📡 Live Prediction Feed</h2>
<div class="prediction-feed" id="feed"></div>
</div>
<!-- Calibration Adjustment -->
<div class="panel">
<h2>🔧 Calibration Adjustment</h2>
<div class="tabs">
<button class="tab active" data-tab="platt">Platt Scaling</button>
<button class="tab" data-tab="isotonic">Isotonic Regression</button>
<button class="tab" data-tab="temperature">Temperature Scaling</button>
</div>
<div id="tab-platt">
<p style="font-size:13px;color:var(--text-muted);margin-bottom:12px">Logistic regression recalibration. Learns A and B to map: calibrated = σ(A·logit + B)</p>
<div class="slider-group">
<label><span>Temperature (A)</span><span id="platt-a-val">1.0</span></label>
<input type="range" id="platt-a" min="0.1" max="3" step="0.1" value="1.0">
</div>
<div class="slider-group">
<label><span>Bias (B)</span><span id="platt-b-val">0.0</span></label>
<input type="range" id="platt-b" min="-2" max="2" step="0.1" value="0.0">
</div>
<button class="btn btn-primary" id="btn-apply-cal" style="margin-top:12px">Apply Calibration</button>
<button class="btn" id="btn-auto-cal" style="margin-top:12px">🤖 Auto-Calibrate</button>
</div>
<div id="tab-isotonic" class="hidden">
<p style="font-size:13px;color:var(--text-muted);margin-bottom:12px">Non-parametric monotonic mapping from raw confidence to calibrated probability.</p>
<canvas id="isotonic-canvas" style="height:200px"></canvas>
<button class="btn btn-primary" id="btn-fit-isotonic" style="margin-top:12px">Fit Isotonic Model</button>
</div>
<div id="tab-temperature" class="hidden">
<p style="font-size:13px;color:var(--text-muted);margin-bottom:12px">Single-parameter temperature scaling: softmax(logits / T)</p>
<div class="slider-group">
<label><span>Temperature T</span><span id="temp-val">1.0</span></label>
<input type="range" id="temp-slider" min="0.1" max="5" step="0.1" value="1.0">
</div>
<button class="btn btn-primary" id="btn-apply-temp" style="margin-top:12px">Apply Temperature</button>
<button class="btn" id="btn-optimize-temp" style="margin-top:12px">🤖 Optimize Temperature</button>
</div>
</div>
<!-- Confidence Distribution -->
<div class="panel full-width">
<h2>📈 Confidence Distribution & Brier Score Over Time</h2>
<canvas id="distribution-canvas" style="height:200px"></canvas>
</div>
</div>
<script src="src/calibration-lab.js"></script>
</body>
</html>