-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
478 lines (419 loc) · 23.7 KB
/
Copy pathindex.html
File metadata and controls
478 lines (419 loc) · 23.7 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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LLM Stochastic Bias — Can LLMs Sample from Probability Distributions?</title>
<script src="https://cdn.jsdelivr.net/npm/chart.js@4"></script>
<script src="https://cdn.jsdelivr.net/npm/mermaid@11/dist/mermaid.min.js"></script>
<style>
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;700&family=Space+Grotesk:wght@400;600;700&display=swap');
:root {
--bg: #07090e; --surface: #0f1218; --surface2: #161c26;
--border: #1e2736; --border2: #2a3548;
--text: #e2e8f0; --muted: #64748b; --dim: #475569;
--blue: #3b82f6; --cyan: #06b6d4; --green: #10b981;
--orange: #f59e0b; --red: #ef4444; --purple: #a855f7;
}
* { margin:0; padding:0; box-sizing:border-box; }
body { font-family:'Space Grotesk',sans-serif; background:var(--bg); color:var(--text); line-height:1.6; }
.container { max-width:1400px; margin:0 auto; padding:2.5rem 2rem; }
header { text-align:center; margin-bottom:3rem; padding-bottom:2rem; border-bottom:1px solid var(--border); }
h1 { font-size:2.4rem; font-weight:700; letter-spacing:-0.03em; margin-bottom:0.4rem;
background:linear-gradient(135deg,var(--blue),var(--cyan),var(--purple)); -webkit-background-clip:text; -webkit-text-fill-color:transparent; }
.tagline { color:var(--muted); font-size:1rem; max-width:700px; margin:0 auto; }
.stat-row { display:flex; gap:1.5rem; justify-content:center; margin-top:1.5rem; flex-wrap:wrap; }
.stat-pill { background:var(--surface); border:1px solid var(--border); border-radius:100px; padding:0.4rem 1.2rem;
font-family:'JetBrains Mono',monospace; font-size:0.8rem; color:var(--muted); }
.stat-pill b { color:var(--text); }
h2 { font-size:1.3rem; font-weight:700; margin:2.5rem 0 0.75rem; letter-spacing:-0.01em; }
h3 { font-size:1.05rem; font-weight:600; margin:1.5rem 0 0.5rem; color:var(--cyan); }
p, li { color:var(--text); font-size:0.95rem; line-height:1.7; }
p { margin-bottom:0.75rem; }
ul { margin:0.5rem 0 1rem 1.5rem; }
li { margin-bottom:0.3rem; }
strong { color:var(--text); }
code { font-family:'JetBrains Mono',monospace; font-size:0.85em; background:var(--surface2); padding:0.15em 0.4em; border-radius:4px; color:var(--cyan); }
.section { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:1.5rem; margin-bottom:1.5rem; }
.section h2 { margin-top:0; font-size:1.15rem; }
.grid2 { display:grid; grid-template-columns:1fr 1fr; gap:1.5rem; margin-bottom:1.5rem; }
.trans-grid { display:grid; grid-template-columns:1fr 1fr; gap:1.5rem; }
.model-cards { display:grid; grid-template-columns:repeat(4,1fr); gap:1rem; margin-bottom:2rem; }
.model-card { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:1.25rem; text-align:center; position:relative; overflow:hidden; }
.model-card::before { content:''; position:absolute; top:0; left:0; right:0; height:3px; }
.model-card:nth-child(1)::before { background:var(--orange); }
.model-card:nth-child(2)::before { background:var(--blue); }
.model-card:nth-child(3)::before { background:var(--green); }
.model-card:nth-child(4)::before { background:var(--purple); }
.model-name { font-weight:700; font-size:1.05rem; margin-bottom:0.3rem; }
.model-type { font-size:0.75rem; color:var(--muted); text-transform:uppercase; letter-spacing:0.06em; margin-bottom:0.75rem; }
.model-stat { font-family:'JetBrains Mono',monospace; }
.model-stat .big { font-size:2rem; font-weight:700; line-height:1; }
.model-stat .label { font-size:0.7rem; color:var(--muted); margin-top:0.2rem; }
.model-card:nth-child(1) .big { color:var(--orange); }
.model-card:nth-child(2) .big { color:var(--blue); }
.model-card:nth-child(3) .big { color:var(--green); }
.model-card:nth-child(4) .big { color:var(--purple); }
.verdict { display:inline-block; font-size:0.7rem; font-weight:700; text-transform:uppercase; letter-spacing:0.08em; padding:0.2rem 0.6rem; border-radius:100px; margin-top:0.5rem; }
.verdict.collapse { background:rgba(239,68,68,0.15); color:var(--red); }
.verdict.spread { background:rgba(16,185,129,0.15); color:var(--green); }
.verdict.bleed { background:rgba(245,158,11,0.15); color:var(--orange); }
canvas { width:100%!important; }
.heatmap-table { width:100%; border-collapse:collapse; font-family:'JetBrains Mono',monospace; font-size:0.8rem; }
.heatmap-table th { padding:0.5rem 0.6rem; text-align:center; color:var(--muted); font-size:0.7rem; text-transform:uppercase; letter-spacing:0.04em; font-weight:600; border-bottom:2px solid var(--border); }
.heatmap-table th:first-child { text-align:left; }
.heatmap-table td { padding:0.45rem 0.6rem; text-align:center; border-bottom:1px solid var(--border); }
.heatmap-table td:first-child { text-align:left; color:var(--muted); font-size:0.75rem; }
.heatmap-table tr:hover td { background:var(--surface2); }
.divider { border:none; border-top:1px solid var(--border); margin:3rem 0; }
.mermaid, pre.mermaid { background:var(--surface); border:1px solid var(--border); border-radius:12px; padding:1.5rem; margin:1rem 0 1.5rem; text-align:center; font-family:inherit; }
.taxonomy-table { width:100%; border-collapse:collapse; font-size:0.9rem; margin:1rem 0; }
.taxonomy-table th { text-align:left; padding:0.6rem 0.75rem; border-bottom:2px solid var(--border); color:var(--muted); font-size:0.75rem; text-transform:uppercase; letter-spacing:0.04em; }
.taxonomy-table td { padding:0.55rem 0.75rem; border-bottom:1px solid var(--border); }
.taxonomy-table tr:hover td { background:var(--surface2); }
.footer { text-align:center; color:var(--dim); font-size:0.75rem; margin-top:2rem; padding-top:1.5rem; border-top:1px solid var(--border); }
@media(max-width:1000px) { .model-cards{grid-template-columns:1fr 1fr;} .grid2,.trans-grid{grid-template-columns:1fr;} }
@media(max-width:600px) { .model-cards{grid-template-columns:1fr;} }
</style>
</head>
<body>
<div class="container">
<header>
<h1>LLM Stochastic Bias</h1>
<p class="tagline">Testing whether LLMs can sample from probability distributions or just pick the most likely option. 5.6M API calls across 4 OpenAI models. Spoiler: they can't.</p>
<div class="stat-row">
<span class="stat-pill"><b>5,600,000</b> API calls</span>
<span class="stat-pill"><b>4</b> models</span>
<span class="stat-pill"><b>2</b> experiments</span>
<span class="stat-pill"><b>0</b> models pass</span>
</div>
</header>
<!-- ════════════ WRITEUP: WHAT & WHY ════════════ -->
<h2>The Question</h2>
<p>When you tell an LLM <em>"pick a state with 20% probability,"</em> does it actually produce that state ~20% of the time across many calls? Or does it just pick the most likely option every time?</p>
<p>This matters for any application using LLMs for decision-making, game AI, simulation, or agentic workflows where stochastic behavior is expected. We tested this with <strong>two experiments across four OpenAI models</strong>, making 5.6 million API calls total.</p>
<h2>Part 1: Flat Distribution (10 States)</h2>
<p>Each model is given a probability distribution over 10 states and asked to "pick one" per call. No code execution, no random library — just the model's own sense of probability. 1,000,000 independent calls per model, temperature=1.0.</p>
<h3>The Target Distribution</h3>
<pre class="mermaid">
graph LR
subgraph dist [Each call: pick one state according to these probabilities]
S1["S1\n3%"]
S2["S2\n5%"]
S3["S3\n8.5%"]
S4["S4\n11.5%"]
S5["S5\n15%"]
S6["S6\n20%"]
S7["S7\n15%"]
S8["S8\n10%"]
S9["S9\n7%"]
S10["S10\n5%"]
end
</pre>
<hr class="divider">
<!-- ════════════ MODEL CARDS ════════════ -->
<h2>Part 1 Results: Model Comparison</h2>
<p>The percentage shows how often each model picked State 6 (the 20% mode) out of 1,000,000 calls:</p>
<div class="model-cards">
<div class="model-card">
<div class="model-name">GPT-5.4-mini</div>
<div class="model-type">Fast · $0.75/1M in</div>
<div class="model-stat"><div class="big">99.94%</div><div class="label">State 6 (expected 20%)</div></div>
<span class="verdict bleed">Near-Collapse</span>
</div>
<div class="model-card">
<div class="model-name">GPT-5.4</div>
<div class="model-type">Flagship · $2.50/1M in</div>
<div class="model-stat"><div class="big">55.75%</div><div class="label">State 6 (expected 20%)</div></div>
<span class="verdict spread">Distributes</span>
</div>
<div class="model-card">
<div class="model-name">GPT-5-mini</div>
<div class="model-type">Reasoning · $0.25/1M in</div>
<div class="model-stat"><div class="big">100.0%</div><div class="label">State 6 (expected 20%)</div></div>
<span class="verdict collapse">Total Collapse</span>
</div>
<div class="model-card">
<div class="model-name">GPT-4.1</div>
<div class="model-type">Production · $2.00/1M in</div>
<div class="model-stat"><div class="big">100.0%</div><div class="label">State 6 (expected 20%)</div></div>
<span class="verdict collapse">Total Collapse</span>
</div>
</div>
<!-- Part 1: Bar chart -->
<div class="section">
<h2>Distribution Comparison (1M iterations each)</h2>
<canvas id="part1Bar" height="90"></canvas>
</div>
<!-- Part 1: Deviation heatmap -->
<div class="section">
<h2>Deviation from Expected (%)</h2>
<table class="heatmap-table" id="heatmapTable">
<thead><tr><th>State</th><th>Expected</th><th>GPT-5.4-mini</th><th>GPT-5.4</th><th>GPT-5-mini</th><th>GPT-4.1</th></tr></thead>
<tbody></tbody>
</table>
</div>
<!-- Part 1: Radar + GPT-5.4 detail -->
<div class="grid2">
<div class="section">
<h2>Distribution Shape (Radar)</h2>
<canvas id="radarChart"></canvas>
</div>
<div class="section">
<h2>GPT-5.4 Detail (only model with spread)</h2>
<canvas id="gpt54Detail"></canvas>
</div>
</div>
<!-- Part 1: Chi2 -->
<div class="section">
<h2>Statistical Divergence (lower = better)</h2>
<div style="position:relative; width:100%; height:250px;">
<canvas id="chi2Chart"></canvas>
</div>
</div>
<h3>Part 1 Key Findings</h3>
<ul>
<li><strong>GPT-5.4 is the only model with distributional spread.</strong> It picked all 10 states, with State 6 at 55.75%. Still heavily biased, but the shape is recognizable.</li>
<li><strong>Three models show total mode collapse.</strong> GPT-4.1 and GPT-5-mini picked State 6 in 100.00% of 1M calls. GPT-5.4-mini picked it 99.94%, with only 600 outliers to State 7.</li>
<li><strong>Understanding ≠ sampling.</strong> The models clearly <em>understand</em> the distribution (they identify the mode correctly). But understanding a distribution and sampling from one are fundamentally different capabilities.</li>
<li><strong>The PRNG baseline is perfect.</strong> Python's <code>random.choices()</code> deviates by <0.07% across all runs. The baseline is trustworthy.</li>
</ul>
<hr class="divider">
<!-- ════════════ PART 2 ════════════ -->
<h2>Part 2: Multi-Layer State Transitions</h2>
<p>Can the models follow <strong>conditional probability distributions</strong> across a 3-layer hierarchical state machine? Each iteration traces a path from root to leaf. Two modes: <strong>Chained</strong> (3 API calls, one per layer) and <strong>Single-shot</strong> (1 call, full tree shown). 100,000 paths per model per mode.</p>
<h3>The 3-Layer State Tree</h3>
<pre class="mermaid">
graph TD
Root((" "))
Root -->|"15%"| S1["S1 Input"]
Root -->|"30%"| S2["S2 Compute"]
Root -->|"25%"| S3["S3 Validate"]
Root -->|"20%"| S4["S4 Optimize"]
Root -->|"10%"| S5["S5 Output"]
S1 -->|"40%"| S11["S1.1 Tokenize"]
S1 -->|"35%"| S12["S1.2 Parse"]
S1 -->|"25%"| S13["S1.3 Normalize"]
S2 -->|"20%"| S21["S2.1 Arithmetic"]
S2 -->|"30%"| S22["S2.2 Logic"]
S2 -->|"35%"| S23["S2.3 Pattern Match"]
S2 -->|"15%"| S24["S2.4 Heuristic"]
S3 -->|"45%"| S31["S3.1 Type Check"]
S3 -->|"30%"| S32["S3.2 Bounds Check"]
S3 -->|"25%"| S33["S3.3 Constraints"]
S4 -->|"45%"| S41["S4.1 Cache"]
S4 -->|"25%"| S42["S4.2 Recompute"]
S4 -->|"18%"| S43["S4.3 Prune"]
S4 -->|"12%"| S44["S4.4 Parallelize"]
S5 -->|"55%"| S51["S5.1 Format"]
S5 -->|"45%"| S52["S5.2 Serialize"]
S11 -->|"..."| L3a["Layer 3\n2-4 leaves each"]
S23 -->|"..."| L3b["Layer 3\n2-4 leaves each"]
S41 -->|"..."| L3c["Layer 3\n2-4 leaves each"]
</pre>
<!-- Part 2: Bar charts -->
<div class="section">
<h2>Part 2 — Layer 1 Distribution (100K paths per model)</h2>
<div class="trans-grid">
<div>
<h2 style="font-size:0.9rem; color:var(--muted);">Chained Mode (3 API calls per path)</h2>
<canvas id="transChained" height="110"></canvas>
</div>
<div>
<h2 style="font-size:0.9rem; color:var(--muted);">Single-Shot Mode (1 API call per path)</h2>
<canvas id="transSingle" height="110"></canvas>
</div>
</div>
</div>
<!-- Part 2: Favorite state -->
<div class="section">
<h2>Each Model's "Favorite" State (highlights non-argmax bias)</h2>
<table class="heatmap-table" id="favTable">
<thead><tr><th>Model</th><th>Expected Argmax</th><th>Chained Favorite</th><th>Chained %</th><th>Single Favorite</th><th>Single %</th></tr></thead>
<tbody></tbody>
</table>
</div>
<!-- Part 2: Chi2 -->
<div class="section">
<h2>Part 2 — L1 Chi-Squared by Model & Mode (lower = better)</h2>
<div style="position:relative; width:100%; height:450px;">
<canvas id="transChi2"></canvas>
</div>
</div>
<h3>Part 2 Key Findings</h3>
<ul>
<li><strong>Models don't always pick the argmax.</strong> GPT-5.4-mini favored S3 (25%) over S2 (30%) in chained mode, and S4 (20%) in single-shot. The bias is label/position dependent, not purely probability-driven.</li>
<li><strong>Chained vs Single-shot produces completely different distributions from the same model.</strong> Prompt structure matters more than probability values.</li>
<li><strong>GPT-5.4 is again the best distributer</strong> (chi-squared 5-12x lower than others). It spreads across all 5 states in both modes.</li>
<li><strong>S5 "Output" (10%) is universally ignored.</strong> Probabilities below ~10% are treated as zero by all models — a consistent "probability floor" effect.</li>
</ul>
<hr class="divider">
<!-- ════════════ TAXONOMY ════════════ -->
<h2>Model Behavior Taxonomy</h2>
<p>Based on 5.6M API calls across both experiments:</p>
<table class="taxonomy-table">
<thead><tr><th>Model</th><th>Behavior</th><th>Description</th></tr></thead>
<tbody>
<tr><td style="color:var(--blue); font-weight:700;">GPT-5.4</td><td>Approximate distributer</td><td>Distributes across all states with heavy mode bias. Best probabilistic intuition of any model tested. Chi-squared 4.5x lower than others.</td></tr>
<tr><td style="color:var(--orange); font-weight:700;">GPT-5.4-mini</td><td>Non-argmax collapser</td><td>Collapses to a single state, but NOT always the highest-probability one. Bias is label and prompt-structure dependent.</td></tr>
<tr><td style="color:var(--purple); font-weight:700;">GPT-4.1</td><td>Strict argmax</td><td>Reliably picks the highest-probability option. 100% deterministic in flat distributions. Predictable but useless as a sampler.</td></tr>
<tr><td style="color:var(--green); font-weight:700;">GPT-5-mini</td><td>Strict argmax / variable</td><td>Argmax in chained mode, but single-shot shows unexpected variety. Reasoning tokens may give more deliberation.</td></tr>
</tbody>
</table>
<h2>Implications</h2>
<ul>
<li><strong>For agentic systems:</strong> Only the most capable models show any distributional awareness. Using smaller models as "random choice makers" in agent pipelines will produce deterministic behavior.</li>
<li><strong>For game AI / simulation:</strong> LLMs cannot substitute for PRNGs. Even GPT-5.4's best effort is off by 35.75% on its worst state.</li>
<li><strong>For benchmarking:</strong> "Probabilistic intuition" could serve as a novel benchmark dimension for evaluating model capabilities beyond reasoning and knowledge.</li>
</ul>
<div class="footer">
Data collected 2026-03-21 · ~5.6M API calls · Models: gpt-5.4-mini, gpt-5.4, gpt-5-mini, gpt-4.1<br>
Full analysis: <a href="docs/conclusions.md" style="color:var(--cyan);">docs/conclusions.md</a> ·
Source: <a href="https://github.com" style="color:var(--cyan);">GitHub</a>
</div>
</div><!-- /container -->
<script>
mermaid.initialize({ theme: 'dark', startOnLoad: true });
const MODELS = ['GPT-5.4-mini', 'GPT-5.4', 'GPT-5-mini', 'GPT-4.1'];
const MODEL_COLORS = ['#f59e0b', '#3b82f6', '#10b981', '#a855f7'];
const MODEL_COLORS_A = MODEL_COLORS.map(c => c + 'bb');
const P1_STATES = ['S1','S2','S3','S4','S5','S6','S7','S8','S9','S10'];
const P1_EXPECTED = [3.0, 5.0, 8.5, 11.5, 15.0, 20.0, 15.0, 10.0, 7.0, 5.0];
const P1 = {
'GPT-5.4-mini': [0, 0, 0, 0, 0, 99.94, 0.06, 0, 0, 0],
'GPT-5.4': [0, 1.77, 1.68, 7.11, 5.53, 55.75, 13.76, 10.59, 2.33, 1.49],
'GPT-5-mini': [0, 0, 0, 0, 0, 100, 0, 0, 0, 0],
'GPT-4.1': [0, 0, 0, 0, 0, 100, 0, 0, 0, 0],
};
const P2_STATES = ['S1 (15%)', 'S2 (30%)', 'S3 (25%)', 'S4 (20%)', 'S5 (10%)'];
const P2_EXPECTED = [15.0, 30.0, 25.0, 20.0, 10.0];
const P2_CH = {
'GPT-5.4-mini': [0, 21.99, 64.24, 13.77, 0],
'GPT-5.4': [5.40, 39.64, 23.31, 28.73, 2.93],
'GPT-5-mini': [0, 97.84, 2.12, 0.05, 0],
'GPT-4.1': [0, 99.14, 0.84, 0.02, 0],
};
const P2_SG = {
'GPT-5.4-mini': [0, 15.64, 6.94, 77.42, 0],
'GPT-5.4': [2.22, 35.61, 23.52, 38.66, 0],
'GPT-5-mini': [0.03, 31.92, 58.46, 9.59, 0],
'GPT-4.1': [4.21, 51.06, 21.90, 22.83, 0.01],
};
const P1_CHI2 = [3993864, 878295, 3999808, 4000000];
const defaults = {
responsive: true,
plugins: { legend: { labels: { color: '#94a3b8', font: { family: 'Space Grotesk', size: 11 } } } },
scales: {
x: { ticks: { color: '#64748b', font: { size: 10 } }, grid: { color: '#1e2736' } },
y: { ticks: { color: '#64748b', callback: function(v){return v+'%';} }, grid: { color: '#1e2736' } },
},
};
// Part 1 bar
new Chart(document.getElementById('part1Bar'), {
type: 'bar',
data: { labels: P1_STATES, datasets: [
{ label: 'Expected', data: P1_EXPECTED, backgroundColor: '#334155', borderColor: '#475569', borderWidth: 1 },
...MODELS.map((m, i) => ({ label: m, data: P1[m], backgroundColor: MODEL_COLORS_A[i], borderColor: MODEL_COLORS[i], borderWidth: 1 })),
]},
options: { ...defaults },
});
// Heatmap
(function() {
const tbody = document.querySelector('#heatmapTable tbody');
const labels = ['State 1 (3%)', 'State 2 (5%)', 'State 3 (8.5%)', 'State 4 (11.5%)', 'State 5 (15%)',
'State 6 (20%)', 'State 7 (15%)', 'State 8 (10%)', 'State 9 (7%)', 'State 10 (5%)'];
P1_STATES.forEach((s, i) => {
const tr = document.createElement('tr');
const vals = MODELS.map(m => P1[m][i] - P1_EXPECTED[i]);
let html = `<td>${labels[i]}</td><td style="color:#64748b">${P1_EXPECTED[i].toFixed(1)}%</td>`;
vals.forEach(v => {
const intensity = Math.min(Math.abs(v) / 40, 1);
const r = v > 0 ? 239 : 6, g = v > 0 ? 68 : 182, b = v > 0 ? 68 : 212;
html += `<td style="background:rgba(${r},${g},${b},${0.05 + intensity * 0.5}); color:${Math.abs(v) < 0.1 ? '#475569' : '#e2e8f0'}">${v >= 0 ? '+' : ''}${v.toFixed(2)}%</td>`;
});
tr.innerHTML = html; tbody.appendChild(tr);
});
})();
// Radar
new Chart(document.getElementById('radarChart'), {
type: 'radar',
data: { labels: P1_STATES, datasets: [
{ label: 'Expected', data: P1_EXPECTED, borderColor: '#475569', backgroundColor: 'rgba(71,85,105,0.1)', pointRadius: 2, borderWidth: 2 },
{ label: 'GPT-5.4', data: P1['GPT-5.4'], borderColor: '#3b82f6', backgroundColor: 'rgba(59,130,246,0.08)', pointRadius: 3, borderWidth: 2 },
]},
options: { responsive: true, plugins: { legend: { labels: { color: '#94a3b8', font: { family: 'Space Grotesk' } } } },
scales: { r: { ticks: { color: '#64748b', backdropColor: 'transparent' }, grid: { color: '#1e2736' }, pointLabels: { color: '#94a3b8', font: { size: 11 } } } } },
});
// GPT-5.4 detail
new Chart(document.getElementById('gpt54Detail'), {
type: 'bar',
data: { labels: P1_STATES, datasets: [
{ label: 'Expected', data: P1_EXPECTED, backgroundColor: '#33415599', borderColor: '#475569', borderWidth: 1 },
{ label: 'GPT-5.4', data: P1['GPT-5.4'], backgroundColor: '#3b82f6bb', borderColor: '#3b82f6', borderWidth: 1 },
]},
options: { ...defaults },
});
// Chi2
new Chart(document.getElementById('chi2Chart'), {
type: 'bar',
data: { labels: MODELS, datasets: [{ label: 'Chi-squared', data: P1_CHI2, backgroundColor: MODEL_COLORS_A, borderColor: MODEL_COLORS, borderWidth: 1.5 }] },
options: { responsive: true, maintainAspectRatio: false, indexAxis: 'y',
scales: {
x: { ticks: { color: '#64748b', callback: function(v){return (v/1e6).toFixed(1)+'M';} }, grid: { color: '#1e2736' },
title: { display: true, text: 'Chi-squared (lower = closer to expected)', color: '#64748b', font: { size: 11 } } },
y: { ticks: { color: '#94a3b8', font: { size: 12, family: 'Space Grotesk' } }, grid: { display: false } },
},
plugins: { legend: { display: false }, tooltip: { callbacks: { label: function(ctx){return 'Chi-squared: '+ctx.raw.toLocaleString();} } } },
},
});
// Part 2 charts
function makeTransChart(id, data) {
new Chart(document.getElementById(id), {
type: 'bar',
data: { labels: P2_STATES, datasets: [
{ label: 'Expected', data: P2_EXPECTED, backgroundColor: '#33415599', borderColor: '#475569', borderWidth: 1 },
...MODELS.map((m, i) => ({ label: m, data: data[m], backgroundColor: MODEL_COLORS_A[i], borderColor: MODEL_COLORS[i], borderWidth: 1 })),
]},
options: { ...defaults },
});
}
makeTransChart('transChained', P2_CH);
makeTransChart('transSingle', P2_SG);
// Favorite table
(function() {
const tbody = document.querySelector('#favTable tbody');
const sn = ['S1','S2','S3','S4','S5'];
MODELS.forEach((m, mi) => {
const chMax = Math.max(...P2_CH[m]), sgMax = Math.max(...P2_SG[m]);
const chIdx = P2_CH[m].indexOf(chMax), sgIdx = P2_SG[m].indexOf(sgMax);
const tr = document.createElement('tr');
tr.innerHTML = `<td style="color:${MODEL_COLORS[mi]}; font-weight:600;">${m}</td><td>S2 (30%)</td>
<td style="color:${chIdx===1?'#10b981':'#ef4444'}; font-weight:700;">${sn[chIdx]} ${chIdx===1?'':'(!)'}</td><td>${chMax.toFixed(2)}%</td>
<td style="color:${sgIdx===1?'#10b981':'#ef4444'}; font-weight:700;">${sn[sgIdx]} ${sgIdx===1?'':'(!)'}</td><td>${sgMax.toFixed(2)}%</td>`;
tbody.appendChild(tr);
});
})();
// Part 2 chi2
(function() {
new Chart(document.getElementById('transChi2'), {
type: 'bar',
data: { labels: ['GPT-5.4-mini','GPT-5.4','GPT-5-mini','GPT-4.1'], datasets: [
{ label: 'Chained (3 calls)', data: [90647, 18162, 219255, 227637], backgroundColor: 'rgba(245,158,11,0.7)', borderColor: '#f59e0b', borderWidth: 1.5 },
{ label: 'Single-Shot (1 call)', data: [209807, 39445, 67089, 33314], backgroundColor: 'rgba(6,182,212,0.7)', borderColor: '#06b6d4', borderWidth: 1.5 },
]},
options: { responsive: true, maintainAspectRatio: false,
scales: {
x: { ticks: { color: '#94a3b8', font: { size: 12, family: 'Space Grotesk' } }, grid: { color: '#1e2736' } },
y: { beginAtZero: true, suggestedMax: 250000,
ticks: { color: '#64748b', font: { size: 11 }, callback: function(v){return (v/1000).toFixed(0)+'K';} },
grid: { color: '#1e2736' },
title: { display: true, text: 'L1 Chi-squared (lower = closer to expected)', color: '#64748b', font: { size: 11, family: 'Space Grotesk' } } },
},
plugins: { legend: { labels: { color: '#94a3b8', font: { family: 'Space Grotesk', size: 12 } } },
tooltip: { callbacks: { label: function(ctx){return ctx.dataset.label+': '+ctx.raw.toLocaleString();} } } },
},
});
})();
</script>
</body>
</html>