Spaces:
Runtime error
Runtime error
Update index.html
Browse files- index.html +191 -382
index.html
CHANGED
|
@@ -1,446 +1,255 @@
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
-
<meta charset="UTF-8">
|
| 5 |
-
<meta name="viewport" content="width=device-width,initial-scale=1">
|
| 6 |
-
<title>
|
| 7 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
-
<script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
|
| 9 |
-
<style>
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
.pt-avg {background:#1e2d4a;color:#60a5fa}
|
| 21 |
-
.pt-diff {background:#3a2a1e;color:#fb923c}
|
| 22 |
-
.pt-heavy_b{background:#3a1e1e;color:#f87171}
|
| 23 |
-
.ood{display:inline-block;padding:0 4px;border-radius:2px;font-size:7px;
|
| 24 |
-
font-weight:bold;background:#7c2d12;color:#fca5a5;margin-left:3px}
|
| 25 |
-
.seen{display:inline-block;padding:0 4px;border-radius:2px;font-size:7px;
|
| 26 |
-
font-weight:bold;background:#14532d;color:#86efac;margin-left:3px}
|
| 27 |
-
</style>
|
| 28 |
</head>
|
| 29 |
<body class="flex flex-col h-screen overflow-hidden">
|
| 30 |
|
| 31 |
<!-- HEADER -->
|
| 32 |
-
<header class="glass flex-shrink-0 px-2 py-1 flex justify-between items-center gap-1">
|
| 33 |
<div class="flex flex-wrap gap-1 items-center text-[8px] font-bold">
|
| 34 |
-
<span id="
|
| 35 |
-
<span id="
|
| 36 |
-
<span id="
|
| 37 |
-
<span id="bSpr" class="px-1.5 py-0.5 rounded bg-slate-900 text-slate-600 border border-slate-800">K:—</span>
|
| 38 |
-
<div class="flex items-center gap-0.5 px-1.5 py-0.5 rounded bg-slate-800 border border-slate-700">
|
| 39 |
-
<span class="text-slate-500 text-[8px]">n=</span>
|
| 40 |
-
<button class="lb" onclick="chN(-1)">−</button>
|
| 41 |
-
<span id="nDial" class="text-white w-3 text-center">1</span>
|
| 42 |
-
<button class="lb" onclick="chN(+1)">+</button>
|
| 43 |
-
</div>
|
| 44 |
</div>
|
| 45 |
<div class="flex items-center gap-1 flex-shrink-0">
|
| 46 |
-
<span id="
|
| 47 |
-
<div id="dot"
|
| 48 |
-
<button onclick="
|
| 49 |
-
<button onclick="
|
| 50 |
-
<button onclick="doInfer()" class="text-[9px] bg-green-800 hover:bg-green-700 px-2 py-1 rounded font-bold">▶INFER</button>
|
| 51 |
-
<button onclick="doHalt()" class="text-[9px] bg-red-900 hover:bg-red-800 px-2 py-1 rounded font-bold">■</button>
|
| 52 |
-
<button onclick="openD()" class="text-[9px] bg-slate-700 hover:bg-slate-600 px-2 py-1 rounded font-bold">⚙</button>
|
| 53 |
</div>
|
| 54 |
</header>
|
| 55 |
|
| 56 |
<!-- PLOTS -->
|
| 57 |
-
<div class="flex-grow flex flex-col min-h-
|
| 58 |
-
<div id="
|
| 59 |
-
<div id="
|
|
|
|
| 60 |
</div>
|
| 61 |
|
| 62 |
-
<!-- BOTTOM -->
|
| 63 |
-
<div class="glass flex-shrink-0 border-t border-slate-800
|
| 64 |
<div class="flex border-b border-slate-800 text-[10px]">
|
| 65 |
-
<button onclick="tab('nodes')"
|
| 66 |
-
<button onclick="tab('
|
| 67 |
-
<button onclick="tab('
|
| 68 |
-
<button onclick="tab('logs')" id="tLogs" class="flex-1 py-1 text-slate-500">LOGS</button>
|
| 69 |
</div>
|
| 70 |
<div class="flex h-full overflow-hidden">
|
| 71 |
-
<!-- Tension
|
| 72 |
-
<div class="w-
|
| 73 |
-
<div class="text-[7px] text-slate-600 uppercase">error</div>
|
| 74 |
-
<div id="
|
| 75 |
-
<div id="pVal" class="text-[8px] text-slate-500">P:—</div>
|
| 76 |
-
<div id="tVal" class="text-[8px] text-slate-600">T:—</div>
|
| 77 |
-
<div id="itLbl" class="text-[8px] text-slate-700">IT:0</div>
|
| 78 |
-
<div id="sLbl" class="text-[7px] text-slate-800">S:0</div>
|
| 79 |
</div>
|
| 80 |
<!-- Panes -->
|
| 81 |
-
<div class="flex-grow overflow-y-auto p-1.5 text-[10px]">
|
| 82 |
-
<div id="
|
| 83 |
-
<div id="
|
| 84 |
-
<div id="
|
| 85 |
-
<div id="pLogs" class="hidden text-[9px] text-slate-500 font-mono"></div>
|
| 86 |
</div>
|
| 87 |
</div>
|
| 88 |
</div>
|
| 89 |
|
| 90 |
<!-- DRAWER -->
|
| 91 |
-
<aside id="drawer" class="closed fixed inset-x-0 bottom-0 glass border-t border-slate-700 p-4 flex flex-col gap-3 max-h-[90vh] overflow-y-auto">
|
| 92 |
<div class="flex justify-between items-center">
|
| 93 |
-
<span class="text-orange-400 font-bold">
|
| 94 |
-
<button onclick="
|
| 95 |
-
</div>
|
| 96 |
-
|
| 97 |
-
<div class="bg-slate-900 rounded p-3 border border-blue-900/50 text-[9px] space-y-1">
|
| 98 |
-
<div class="text-blue-400 font-bold mb-1">ARCHITECTURE</div>
|
| 99 |
-
<div>• Nodes: <span class="text-white">scalar (1 float)</span></div>
|
| 100 |
-
<div>• Springs: <span class="text-white">scalar K (signed) per edge</span></div>
|
| 101 |
-
<div>• Topology: <span class="text-white">9-row triangulated hourglass, widths [n,n+1,n+2,n+1,n,…]</span></div>
|
| 102 |
-
<div>• Learning: <span class="text-white">LMS backprop on inter-row springs</span></div>
|
| 103 |
-
<div>• Inference: <span class="text-white">K update at inference time, EWC-protected</span></div>
|
| 104 |
</div>
|
| 105 |
|
| 106 |
-
<
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
class="
|
| 113 |
-
<
|
| 114 |
-
class="flex-1 bg-purple-800 hover:bg-purple-700 py-2 text-xs font-bold rounded">⚡ START</button>
|
| 115 |
</div>
|
| 116 |
-
<div class="text-[8px] text-slate-600 mt-1">LMS runs at CPU speed. EWC Fisher accumulates automatically.</div>
|
| 117 |
-
</div>
|
| 118 |
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
<button onclick="doInfer()"
|
| 127 |
-
class="flex-1 bg-green-800 hover:bg-green-700 py-2 text-xs font-bold rounded">▶ RUN</button>
|
| 128 |
</div>
|
| 129 |
-
<div class="text-[8px] text-slate-600 mt-1">Springs update in real-time during inference (EWC on).</div>
|
| 130 |
</div>
|
| 131 |
|
| 132 |
-
<div class="
|
| 133 |
-
<
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
</div>
|
| 138 |
</aside>
|
| 139 |
|
| 140 |
<script>
|
| 141 |
-
|
| 142 |
-
let curN = 1;
|
| 143 |
-
const KCLIP = 12.0;
|
| 144 |
|
| 145 |
-
function
|
| 146 |
-
function
|
| 147 |
|
| 148 |
-
async function
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
await fetch('/set_n', {method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({n:curN})});
|
| 152 |
-
meshReady = false;
|
| 153 |
}
|
| 154 |
|
| 155 |
async function doTrain() {
|
| 156 |
-
const ep = parseInt(document.getElementById('
|
| 157 |
-
await fetch('/
|
|
|
|
| 158 |
}
|
| 159 |
-
async function doViz() { await fetch('/train_visual',{method:'POST',headers:{'Content-Type':'application/json'},body:'{}'}); }
|
| 160 |
-
async function doInfer() {
|
| 161 |
-
const n = parseInt(document.getElementById('infN').value);
|
| 162 |
-
await fetch('/infer',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({n})});
|
| 163 |
-
closeD();
|
| 164 |
-
}
|
| 165 |
-
async function doHalt() { await fetch('/halt',{method:'POST'}); }
|
| 166 |
-
async function doReset() { await fetch('/reset',{method:'POST'}); meshReady=false; }
|
| 167 |
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
const btn = document.getElementById('t'+t.charAt(0).toUpperCase()+t.slice(1));
|
| 173 |
-
btn.className = t===name
|
| 174 |
-
? 'flex-1 py-1 bg-blue-900/40 text-blue-300 font-bold text-[10px]'
|
| 175 |
-
: 'flex-1 py-1 text-slate-500 text-[10px]';
|
| 176 |
-
});
|
| 177 |
}
|
| 178 |
|
| 179 |
-
|
| 180 |
-
|
| 181 |
-
const
|
| 182 |
-
const
|
| 183 |
-
|
| 184 |
-
|
| 185 |
-
|
| 186 |
-
const t = Math.min(Math.abs(k)/KCLIP, 1);
|
| 187 |
-
if (k < 0) return [`rgba(30,${Math.round(80+t*120)},${Math.round(140+t*115)},${0.4+t*0.5})`, 0.5+t*2.5];
|
| 188 |
-
return [`rgba(${Math.round(80+t*160)},${Math.round(60+t*120)},20,${0.35+t*0.55})`, 0.5+t*2.5];
|
| 189 |
}
|
| 190 |
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
const pys = Object.values(nodes).map(n=>n.py);
|
| 195 |
-
const maxx = Math.max(...pxs.map(Math.abs)) || 1;
|
| 196 |
-
const sx = margin / maxx;
|
| 197 |
-
return {sx, sy:4.0}; // y already in [-1,1], scale to [-4,4]
|
| 198 |
}
|
| 199 |
|
| 200 |
-
function
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
for (const tri of triangles) {
|
| 207 |
-
const [p0,p1,p2] = tri.pos;
|
| 208 |
-
const s = tri.stress;
|
| 209 |
-
const b = s < 0.05 ? 'low' : s < 0.2 ? 'mid' : 'high';
|
| 210 |
-
buckets[b].xs.push(p0[0]*sx, p1[0]*sx, p2[0]*sx, p0[0]*sx, null);
|
| 211 |
-
buckets[b].ys.push(p0[1]*sy, p1[1]*sy, p2[1]*sy, p0[1]*sy, null);
|
| 212 |
-
}
|
| 213 |
-
const fills = {
|
| 214 |
-
low: ['rgba(56,189,248,0.04)','rgba(56,189,248,0.18)'],
|
| 215 |
-
mid: ['rgba(251,146,60,0.07)','rgba(251,146,60,0.28)'],
|
| 216 |
-
high: ['rgba(239,68,68,0.11)', 'rgba(239,68,68,0.42)'],
|
| 217 |
-
};
|
| 218 |
-
for (const [bk,td] of Object.entries(buckets)) {
|
| 219 |
-
if (!td.xs.length) continue;
|
| 220 |
-
traces.push({
|
| 221 |
-
type:'scatter', mode:'lines',
|
| 222 |
-
x:td.xs, y:td.ys,
|
| 223 |
-
fill:'toself', fillcolor:fills[bk][0],
|
| 224 |
-
line:{color:fills[bk][1], width:0.7},
|
| 225 |
-
hoverinfo:'none', showlegend:false
|
| 226 |
-
});
|
| 227 |
-
}
|
| 228 |
-
|
| 229 |
-
// ── Edges: vertical (colored by K) and horizontal (faint) ────────────────
|
| 230 |
-
const vertX=[], vertY=[], horzX=[], horzY=[];
|
| 231 |
-
for (const [, s] of Object.entries(springs)) {
|
| 232 |
-
const lx = [s.u_px*sx, s.v_px*sx, null];
|
| 233 |
-
const ly = [s.u_py*sy, s.v_py*sy, null];
|
| 234 |
-
if (s.vert) { vertX.push(...lx); vertY.push(...ly); }
|
| 235 |
-
else { horzX.push(...lx); horzY.push(...ly); }
|
| 236 |
-
}
|
| 237 |
-
// Horizontal springs: static faint lines (no per-spring coloring needed)
|
| 238 |
-
if (horzX.length) traces.push({
|
| 239 |
-
type:'scatter', mode:'lines',
|
| 240 |
-
x:horzX, y:horzY,
|
| 241 |
-
line:{color:'rgba(51,65,85,0.5)', width:0.6},
|
| 242 |
-
hoverinfo:'none', showlegend:false
|
| 243 |
-
});
|
| 244 |
-
// Vertical springs: color by K (group into pos/neg buckets for speed)
|
| 245 |
-
const vBuckets = {};
|
| 246 |
-
for (const [, s] of Object.entries(springs)) {
|
| 247 |
-
if (!s.vert) continue;
|
| 248 |
-
const bk = s.k >= 0 ? Math.floor(s.k/3) : `n${Math.floor(-s.k/3)}`;
|
| 249 |
-
if (!vBuckets[bk]) vBuckets[bk] = {k:s.k, xs:[], ys:[]};
|
| 250 |
-
vBuckets[bk].xs.push(s.u_px*sx, s.v_px*sx, null);
|
| 251 |
-
vBuckets[bk].ys.push(s.u_py*sy, s.v_py*sy, null);
|
| 252 |
-
}
|
| 253 |
-
for (const [, b] of Object.entries(vBuckets)) {
|
| 254 |
-
const [col, wd] = edgeCol(b.k);
|
| 255 |
-
traces.push({type:'scatter', mode:'lines', x:b.xs, y:b.ys,
|
| 256 |
-
line:{color:col, width:wd}, hoverinfo:'none', showlegend:false});
|
| 257 |
-
}
|
| 258 |
-
|
| 259 |
-
// ── Nodes ─────────────────────────────────────��───────────────────────────
|
| 260 |
-
const ns = Object.entries(nodes);
|
| 261 |
-
traces.push({
|
| 262 |
-
type:'scatter', mode:'markers+text',
|
| 263 |
-
x: ns.map(([,n]) => n.px*sx),
|
| 264 |
-
y: ns.map(([,n]) => n.py*sy),
|
| 265 |
-
text: ns.map(([,n]) => {
|
| 266 |
-
if (n.kind==='H') return '';
|
| 267 |
-
return `${n.kind}\n${n.x.toFixed(2)}`;
|
| 268 |
-
}),
|
| 269 |
-
textposition: ns.map(([,n]) => n.py>0 ? 'top center' : 'bottom center'),
|
| 270 |
-
textfont:{size:8, color: ns.map(([,n])=>KIND_COL[n.kind])},
|
| 271 |
-
marker:{
|
| 272 |
-
size: ns.map(([,n]) => KIND_SIZE[n.kind] + Math.min(n.vel*25, 6)),
|
| 273 |
-
color: ns.map(([,n]) => KIND_COL[n.kind]),
|
| 274 |
-
opacity:ns.map(([,n]) => 0.72 + Math.min(n.vel*2, 0.28)),
|
| 275 |
-
line:{
|
| 276 |
-
width:2,
|
| 277 |
-
color: ns.map(([,n]) => n.anchored ? '#ef4444' : '#22c55e')
|
| 278 |
-
}
|
| 279 |
-
},
|
| 280 |
-
hoverinfo:'none', showlegend:false
|
| 281 |
});
|
| 282 |
-
|
| 283 |
-
return traces;
|
| 284 |
}
|
| 285 |
|
| 286 |
-
const MESH_LAYOUT = {
|
| 287 |
-
margin:{l:4,r:4,t:4,b:4},
|
| 288 |
-
paper_bgcolor:'transparent', plot_bgcolor:'transparent',
|
| 289 |
-
xaxis:{visible:false, range:[-5,5]},
|
| 290 |
-
yaxis:{visible:false, range:[-5,5]},
|
| 291 |
-
showlegend:false,
|
| 292 |
-
};
|
| 293 |
-
const ERR_LAYOUT = {
|
| 294 |
-
margin:{l:26,r:4,t:2,b:8},
|
| 295 |
-
paper_bgcolor:'transparent', plot_bgcolor:'transparent',
|
| 296 |
-
xaxis:{visible:false},
|
| 297 |
-
yaxis:{color:'#334155',gridcolor:'#0f172a',
|
| 298 |
-
zeroline:true,zerolinecolor:'#22c55e',zerolinewidth:1},
|
| 299 |
-
showlegend:false,
|
| 300 |
-
};
|
| 301 |
-
|
| 302 |
-
let meshReady=false, errReady=false, lastW='';
|
| 303 |
-
|
| 304 |
-
// ── POLL ──────────────────────────────────────────────────────────────────────
|
| 305 |
setInterval(async () => {
|
| 306 |
try {
|
| 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 |
-
Progress: <span class="text-white font-bold">${done}</span> / ${d.test_size||'?'}</div>`;
|
| 383 |
-
if (Object.keys(acc).length) {
|
| 384 |
-
const seen=Object.entries(acc).filter(([,v])=>!v.ood);
|
| 385 |
-
const ood =Object.entries(acc).filter(([,v])=> v.ood);
|
| 386 |
-
const row=([t,v])=>{
|
| 387 |
-
const ac=v.acc>=80?'text-green-400':v.acc>=50?'text-yellow-400':'text-red-400';
|
| 388 |
-
const b=v.ood?'<span class="ood">OOD</span>':'<span class="seen">SEEN</span>';
|
| 389 |
-
return `<tr class="border-b border-slate-900/60">
|
| 390 |
-
<td class="py-0.5"><span class="pt pt-${t}">${t}</span>${b}</td>
|
| 391 |
-
<td class="text-right text-slate-400">${v.n}</td>
|
| 392 |
-
<td class="text-right ${ac} font-bold">${v.acc}%</td>
|
| 393 |
-
<td class="text-right text-slate-400">${v.avg_err}</td>
|
| 394 |
-
<td class="text-right text-slate-600">${v.avg_steps}</td>
|
| 395 |
-
</tr>`;
|
| 396 |
};
|
| 397 |
-
ah+=`<table class="w-full text-[9px] border-collapse">
|
| 398 |
-
<tr class="text-slate-600 border-b border-slate-800 text-[8px]">
|
| 399 |
-
<th class="text-left">Type</th><th class="text-right">N</th>
|
| 400 |
-
<th class="text-right">Acc%</th><th class="text-right">Avg|e|</th><th class="text-right">Steps</th>
|
| 401 |
-
</tr>${seen.map(row).join('')}
|
| 402 |
-
${ood.length?`<tr><td colspan="5" class="pt-1 text-[8px] text-slate-600">── OOD (never seen) ──</td></tr>`:'' }
|
| 403 |
-
${ood.map(row).join('')}</table>`;
|
| 404 |
-
if (done>20) {
|
| 405 |
-
const oa=ood.reduce((s,[,v])=>s+v.acc*v.n,0)/Math.max(ood.reduce((s,[,v])=>s+v.n,0),1);
|
| 406 |
-
const sa=seen.reduce((s,[,v])=>s+v.acc*v.n,0)/Math.max(seen.reduce((s,[,v])=>s+v.n,0),1);
|
| 407 |
-
const vc=oa>=80?'text-green-400':oa>=50?'text-yellow-400':'text-red-400';
|
| 408 |
-
ah+=`<div class="mt-2 p-2 bg-slate-900 rounded text-[9px]">
|
| 409 |
-
<span class="${vc} font-bold">${oa>=80?'✓ Generalises OOD':'~ Partial generalisation'}</span>
|
| 410 |
-
<span class="text-slate-500 ml-2">seen:${sa.toFixed(0)}% OOD:${oa.toFixed(0)}%</span>
|
| 411 |
-
</div>`;
|
| 412 |
-
}
|
| 413 |
-
} else ah+='<div class="text-slate-700 text-[9px]">Run inference to see accuracy.</div>';
|
| 414 |
-
document.getElementById('pAcc').innerHTML=ah;
|
| 415 |
|
| 416 |
-
|
| 417 |
-
|
| 418 |
-
d.logs.map(l=>`<div class="py-0.5 border-b border-slate-900/40">${l}</div>`).join('');
|
| 419 |
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
} else {
|
| 427 |
-
Plotly.react('meshPlot', traces, MESH_LAYOUT);
|
| 428 |
-
}
|
| 429 |
|
| 430 |
-
|
| 431 |
-
|
| 432 |
-
const et={type:'scatter',mode:'lines',
|
| 433 |
-
x:hist.map((_,i)=>i),y:hist,
|
| 434 |
-
line:{color:'#f97316',width:1.5},
|
| 435 |
-
fill:'tozeroy',fillcolor:'rgba(249,115,22,0.07)'};
|
| 436 |
-
if (!errReady) {
|
| 437 |
-
Plotly.newPlot('errPlot',[et],ERR_LAYOUT,{displayModeBar:false,responsive:true});
|
| 438 |
-
errReady=true;
|
| 439 |
-
} else {
|
| 440 |
-
Plotly.react('errPlot',[et],ERR_LAYOUT);
|
| 441 |
-
}
|
| 442 |
-
} catch(_){}
|
| 443 |
-
}, 220);
|
| 444 |
</script>
|
| 445 |
</body>
|
| 446 |
</html>
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>N-Dim Lattice Mesh</title>
|
| 7 |
+
<script src="https://cdn.tailwindcss.com"></script>
|
| 8 |
+
<script src="https://cdn.plot.ly/plotly-2.24.1.min.js"></script>
|
| 9 |
+
<style>
|
| 10 |
+
body { background:#06090e; color:#cbd5e1; font-family:'Courier New',monospace; }
|
| 11 |
+
.glass { background:rgba(10,18,35,0.98); border:1px solid #1e2d40; }
|
| 12 |
+
#drawer { transition:transform .3s ease; z-index:200; }
|
| 13 |
+
.drawer-closed { transform:translateY(100%); }
|
| 14 |
+
.ptype { display:inline-block; padding:1px 5px; border-radius:3px; font-size:9px; font-weight:bold; }
|
| 15 |
+
.pt-blend { background:#1e3a2f; color:#4ade80; }
|
| 16 |
+
.pt-diff { background:#1e2d4a; color:#60a5fa; }
|
| 17 |
+
.pt-route { background:#3a1e3a; color:#e879f9; }
|
| 18 |
+
.pt-manual{ background:#3a2a1e; color:#fb923c; }
|
| 19 |
+
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
</head>
|
| 21 |
<body class="flex flex-col h-screen overflow-hidden">
|
| 22 |
|
| 23 |
<!-- HEADER -->
|
| 24 |
+
<header class="glass flex-shrink-0 px-2 py-1.5 flex justify-between items-center gap-1">
|
| 25 |
<div class="flex flex-wrap gap-1 items-center text-[8px] font-bold">
|
| 26 |
+
<span id="b-mode" class="px-1.5 py-0.5 rounded bg-slate-800 text-slate-400 border border-slate-700">IDLE</span>
|
| 27 |
+
<span id="b-type" class="ptype pt-blend">—</span>
|
| 28 |
+
<span id="b-dim" class="px-1.5 py-0.5 rounded bg-slate-900 text-slate-600 border border-slate-800">D:8</span>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
</div>
|
| 30 |
<div class="flex items-center gap-1 flex-shrink-0">
|
| 31 |
+
<span id="q-lbl" class="text-[8px] text-slate-600">Q:0</span>
|
| 32 |
+
<div id="run-dot" class="w-2 h-2 rounded-full bg-slate-700"></div>
|
| 33 |
+
<button onclick="postAct('/halt')" class="text-[9px] bg-red-900 hover:bg-red-800 px-2 py-1 rounded font-bold shadow">■ HALT</button>
|
| 34 |
+
<button onclick="openDrawer()" class="text-[9px] bg-slate-700 hover:bg-slate-600 px-2 py-1 rounded font-bold shadow">⚙ CONTROLS</button>
|
|
|
|
|
|
|
|
|
|
| 35 |
</div>
|
| 36 |
</header>
|
| 37 |
|
| 38 |
<!-- PLOTS -->
|
| 39 |
+
<div class="flex-grow flex flex-col min-h-[30vh] overflow-hidden relative">
|
| 40 |
+
<div id="error-box" class="hidden absolute top-0 w-full bg-red-900 text-white p-2 text-xs font-bold z-50"></div>
|
| 41 |
+
<div id="mesh-plot" class="flex-grow w-full"></div>
|
| 42 |
+
<div id="err-plot" style="height:56px" class="flex-shrink-0 border-t border-slate-900 hidden md:block"></div>
|
| 43 |
</div>
|
| 44 |
|
| 45 |
+
<!-- BOTTOM PANEL -->
|
| 46 |
+
<div class="glass flex-shrink-0 border-t border-slate-800 h-48">
|
| 47 |
<div class="flex border-b border-slate-800 text-[10px]">
|
| 48 |
+
<button onclick="tab('nodes')" id="tab-nodes" class="flex-1 py-1 bg-blue-900/40 text-blue-300 font-bold">NODES</button>
|
| 49 |
+
<button onclick="tab('accuracy')" id="tab-accuracy" class="flex-1 py-1 text-slate-500">ACCURACY</button>
|
| 50 |
+
<button onclick="tab('logs')" id="tab-logs" class="flex-1 py-1 text-slate-500">LOGS</button>
|
|
|
|
| 51 |
</div>
|
| 52 |
<div class="flex h-full overflow-hidden">
|
| 53 |
+
<!-- Tension Meter -->
|
| 54 |
+
<div class="w-24 flex-shrink-0 border-r border-slate-800 flex flex-col items-center justify-center p-1 gap-0.5">
|
| 55 |
+
<div class="text-[7px] text-slate-600 uppercase">mean error</div>
|
| 56 |
+
<div id="err-big" class="text-xl font-bold text-red-400 leading-none">0.00</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
</div>
|
| 58 |
<!-- Panes -->
|
| 59 |
+
<div class="flex-grow overflow-y-auto p-1.5 text-[10px] pb-6">
|
| 60 |
+
<div id="pane-nodes"></div>
|
| 61 |
+
<div id="pane-accuracy" class="hidden"></div>
|
| 62 |
+
<div id="pane-logs" class="hidden text-[9px] text-slate-500"></div>
|
|
|
|
| 63 |
</div>
|
| 64 |
</div>
|
| 65 |
</div>
|
| 66 |
|
| 67 |
<!-- DRAWER -->
|
| 68 |
+
<aside id="drawer" class="drawer-closed fixed inset-x-0 bottom-0 glass border-t border-slate-700 p-4 flex flex-col gap-3 max-h-[90vh] overflow-y-auto pb-10 shadow-2xl">
|
| 69 |
<div class="flex justify-between items-center">
|
| 70 |
+
<span class="text-orange-400 font-bold">CONTROL PANEL</span>
|
| 71 |
+
<button onclick="closeDrawer()" class="text-slate-400 text-2xl leading-none">✕</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
</div>
|
| 73 |
|
| 74 |
+
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
| 75 |
+
<div class="bg-slate-900 rounded p-3 border border-purple-900/50">
|
| 76 |
+
<div class="text-purple-400 text-[9px] font-bold mb-2">OFFLINE TRAINING</div>
|
| 77 |
+
<div class="flex gap-2 items-center">
|
| 78 |
+
<input id="ep-n" type="number" value="10" class="w-16 bg-black border border-slate-700 p-1 text-white text-sm text-center rounded">
|
| 79 |
+
<label class="text-[9px] text-slate-500 flex-1">Epochs</label>
|
| 80 |
+
<button onclick="doTrain()" class="bg-purple-800 hover:bg-purple-700 px-4 py-2 text-xs font-bold rounded">⚡ TRAIN</button>
|
| 81 |
+
</div>
|
|
|
|
| 82 |
</div>
|
|
|
|
|
|
|
| 83 |
|
| 84 |
+
<div class="bg-slate-900 rounded p-3 border border-green-900/50">
|
| 85 |
+
<div class="text-green-400 text-[9px] font-bold mb-2">BATCH INFERENCE (EWC)</div>
|
| 86 |
+
<div class="flex gap-2 items-center">
|
| 87 |
+
<input id="inf-n" type="number" value="200" class="w-16 bg-black border border-slate-700 p-1 text-white text-sm text-center rounded">
|
| 88 |
+
<label class="text-[9px] text-slate-500 flex-1">Samples</label>
|
| 89 |
+
<button onclick="doInfer()" class="bg-green-800 hover:bg-green-700 px-4 py-2 text-xs font-bold rounded">▶ RUN</button>
|
| 90 |
+
</div>
|
|
|
|
|
|
|
| 91 |
</div>
|
|
|
|
| 92 |
</div>
|
| 93 |
|
| 94 |
+
<div class="bg-slate-900 rounded p-3 border border-orange-900/50">
|
| 95 |
+
<div class="text-orange-400 text-[9px] font-bold mb-2">MANUAL INJECTION (D:8)</div>
|
| 96 |
+
<div class="space-y-2">
|
| 97 |
+
<div>
|
| 98 |
+
<label class="text-[8px] text-slate-500 block mb-0.5">Input A</label>
|
| 99 |
+
<input id="man-a" type="text" value="0.9, 0.1, 0.5, 0.2, 0.8, 0.3, 0.7, 0.4" class="w-full bg-black border border-slate-700 p-1.5 text-orange-200 text-xs rounded font-mono">
|
| 100 |
+
</div>
|
| 101 |
+
<div>
|
| 102 |
+
<label class="text-[8px] text-slate-500 block mb-0.5">Input B</label>
|
| 103 |
+
<input id="man-b" type="text" value="0.1, 0.9, 0.5, 0.8, 0.2, 0.7, 0.3, 0.6" class="w-full bg-black border border-slate-700 p-1.5 text-cyan-200 text-xs rounded font-mono">
|
| 104 |
+
</div>
|
| 105 |
+
<button onclick="doManual()" class="w-full bg-orange-900 hover:bg-orange-800 py-2 text-xs font-bold rounded mt-1">INJECT MANUAL ARRAYS</button>
|
| 106 |
+
</div>
|
| 107 |
</div>
|
| 108 |
</aside>
|
| 109 |
|
| 110 |
<script>
|
| 111 |
+
let plotted = false;
|
|
|
|
|
|
|
| 112 |
|
| 113 |
+
function openDrawer() { document.getElementById('drawer').classList.remove('drawer-closed'); }
|
| 114 |
+
function closeDrawer() { document.getElementById('drawer').classList.add('drawer-closed'); }
|
| 115 |
|
| 116 |
+
async function postAct(route) {
|
| 117 |
+
try { await fetch(route, {method:'POST'}); }
|
| 118 |
+
catch(e) { showError("Connection lost: " + e.message); }
|
|
|
|
|
|
|
| 119 |
}
|
| 120 |
|
| 121 |
async function doTrain() {
|
| 122 |
+
const ep = parseInt(document.getElementById('ep-n').value);
|
| 123 |
+
await fetch('/train', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({epochs:ep})});
|
| 124 |
+
closeDrawer();
|
| 125 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 126 |
|
| 127 |
+
async function doInfer() {
|
| 128 |
+
const n = parseInt(document.getElementById('inf-n').value);
|
| 129 |
+
await fetch('/infer', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({n})});
|
| 130 |
+
closeDrawer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 131 |
}
|
| 132 |
|
| 133 |
+
async function doManual() {
|
| 134 |
+
const a = document.getElementById('man-a').value;
|
| 135 |
+
const b = document.getElementById('man-b').value;
|
| 136 |
+
const res = await fetch('/manual', {method:'POST', headers:{'Content-Type':'application/json'}, body: JSON.stringify({a:a, b:b})});
|
| 137 |
+
const data = await res.json();
|
| 138 |
+
if(!data.ok) alert(data.error);
|
| 139 |
+
else closeDrawer();
|
|
|
|
|
|
|
|
|
|
| 140 |
}
|
| 141 |
|
| 142 |
+
function showError(msg) {
|
| 143 |
+
const box = document.getElementById('error-box');
|
| 144 |
+
box.innerText = msg; box.classList.remove('hidden');
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}
|
| 146 |
|
| 147 |
+
function tab(name) {
|
| 148 |
+
['nodes','accuracy','logs'].forEach(t => {
|
| 149 |
+
document.getElementById(`pane-${t}`).classList.toggle('hidden', t !== name);
|
| 150 |
+
document.getElementById(`tab-${t}`).className = t === name
|
| 151 |
+
? 'flex-1 py-1 bg-blue-900/40 text-blue-300 font-bold text-[10px]'
|
| 152 |
+
: 'flex-1 py-1 text-slate-500 text-[10px]';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
});
|
|
|
|
|
|
|
| 154 |
}
|
| 155 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 156 |
setInterval(async () => {
|
| 157 |
try {
|
| 158 |
+
const res = await fetch('/state');
|
| 159 |
+
if (!res.ok) throw new Error("Server returned status " + res.status);
|
| 160 |
+
const d = await res.json();
|
| 161 |
+
|
| 162 |
+
document.getElementById('error-box').classList.add('hidden');
|
| 163 |
+
|
| 164 |
+
const mcolor = {train:'bg-yellow-700 text-yellow-100', infer:'bg-green-800 text-green-100', manual:'bg-orange-800 text-orange-100'}[d.mode] || 'bg-slate-800';
|
| 165 |
+
document.getElementById('b-mode').className = `px-1.5 py-0.5 rounded text-[8px] font-bold ${mcolor}`;
|
| 166 |
+
document.getElementById('b-mode').innerText = (d.mode || 'IDLE').toUpperCase();
|
| 167 |
+
document.getElementById('b-type').className = `ptype pt-${d.current_type || 'blend'}`;
|
| 168 |
+
document.getElementById('b-type').innerText = d.current_type || '—';
|
| 169 |
+
document.getElementById('run-dot').className = `w-2 h-2 rounded-full ${d.running?'bg-green-400':'bg-slate-700'}`;
|
| 170 |
+
document.getElementById('q-lbl').innerText = `Q:${d.queue_size || 0}`;
|
| 171 |
+
|
| 172 |
+
const err = d.error || 0.0;
|
| 173 |
+
const col = err < 0.05 ? 'text-green-400' : err < 0.15 ? 'text-yellow-400' : 'text-red-400';
|
| 174 |
+
document.getElementById('err-big').className = `text-xl font-bold ${col} leading-none`;
|
| 175 |
+
document.getElementById('err-big').innerText = err.toFixed(4);
|
| 176 |
+
|
| 177 |
+
document.getElementById('pane-logs').innerHTML = (d.logs || []).map(l => `<div>${l}</div>`).join('');
|
| 178 |
+
|
| 179 |
+
let ah = "";
|
| 180 |
+
if(d.type_acc && Object.keys(d.type_acc).length > 0) {
|
| 181 |
+
ah += `<table class="w-full text-left border-collapse">
|
| 182 |
+
<tr class="text-slate-600 border-b border-slate-800"><th>Type</th><th>N</th><th>Avg Err</th></tr>`;
|
| 183 |
+
for(const [t, v] of Object.entries(d.type_acc)) {
|
| 184 |
+
ah += `<tr class="border-b border-slate-900/60">
|
| 185 |
+
<td class="py-1 text-orange-300 font-bold">${t}</td>
|
| 186 |
+
<td class="text-slate-400">${v.n}</td>
|
| 187 |
+
<td class="text-white">${v.avg_err}</td>
|
| 188 |
+
</tr>`;
|
| 189 |
+
}
|
| 190 |
+
ah += `</table>`;
|
| 191 |
+
} else { ah = "No inference data yet. Run Batch Inference."; }
|
| 192 |
+
document.getElementById('pane-accuracy').innerHTML = ah;
|
| 193 |
+
|
| 194 |
+
let nh = "";
|
| 195 |
+
if (d.nodes) {
|
| 196 |
+
['A','C','B'].forEach(kind => {
|
| 197 |
+
const k_nodes = Object.values(d.nodes).filter(n => n.kind === kind).sort((a,b)=>a.col-b.col);
|
| 198 |
+
if(k_nodes.length === 0) return;
|
| 199 |
+
const vals = k_nodes.map(n => n.x.toFixed(2)).join(', ');
|
| 200 |
+
const color = kind==='A'?'text-orange-400':kind==='B'?'text-purple-400':'text-sky-400';
|
| 201 |
+
nh += `<div class="mb-1"><span class="${color} font-bold w-4 inline-block">${kind}:</span><span class="font-mono text-slate-300 tracking-wider">${vals}</span></div>`;
|
| 202 |
+
});
|
| 203 |
+
}
|
| 204 |
+
document.getElementById('pane-nodes').innerHTML = nh;
|
| 205 |
+
|
| 206 |
+
const traces = [];
|
| 207 |
+
if (d.nodes && d.springs) {
|
| 208 |
+
const nodes = Object.values(d.nodes);
|
| 209 |
+
|
| 210 |
+
for(const [key, K] of Object.entries(d.springs)) {
|
| 211 |
+
const parts = key.split('|');
|
| 212 |
+
if (parts.length !== 2) continue;
|
| 213 |
+
if(!d.nodes[parts[0]] || !d.nodes[parts[1]]) continue;
|
| 214 |
+
|
| 215 |
+
const pu = d.nodes[parts[0]].pos, pv = d.nodes[parts[1]].pos;
|
| 216 |
+
const color = K > 0 ? `rgba(217,119,6,${Math.min(K/1.5,1)})` : `rgba(6,182,212,${Math.min(Math.abs(K)/1.5,1)})`;
|
| 217 |
+
traces.push({
|
| 218 |
+
type:'scatter', mode:'lines', x:[pu[0], pv[0]], y:[pu[1], pv[1]],
|
| 219 |
+
line:{ color: color, width: 1.0 + Math.abs(K)*1.5 }, hoverinfo:'none', showlegend:false
|
| 220 |
+
});
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
traces.push({
|
| 224 |
+
type:'scatter', mode:'markers+text',
|
| 225 |
+
x: nodes.map(n => n.pos[0]), y: nodes.map(n => n.pos[1]),
|
| 226 |
+
text: nodes.map(n => n.x.toFixed(2)),
|
| 227 |
+
textposition: 'top center', textfont: {size: 10, color: '#9ca3af'},
|
| 228 |
+
marker: {
|
| 229 |
+
size: 14, color: nodes.map(n => n.x), colorscale: 'Viridis',
|
| 230 |
+
line: {color: nodes.map(n => ['A','B','C'].includes(n.kind)?'#ef4444':'#171717'), width: 2}
|
| 231 |
+
},
|
| 232 |
+
showlegend:false
|
| 233 |
+
});
|
| 234 |
+
}
|
| 235 |
|
| 236 |
+
const layout = {
|
| 237 |
+
margin:{l:5,r:5,t:5,b:5}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
|
| 238 |
+
xaxis:{visible:false}, yaxis:{visible:false, scaleanchor:'x'},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 240 |
|
| 241 |
+
if(!plotted) { Plotly.newPlot('mesh-plot', traces, layout, {responsive:true}); plotted = true; }
|
| 242 |
+
else { Plotly.react('mesh-plot', traces, layout); }
|
|
|
|
| 243 |
|
| 244 |
+
if(d.hist && document.getElementById('err-plot').offsetWidth > 0 && d.hist.length > 0) {
|
| 245 |
+
Plotly.react('err-plot', [{y: d.hist, type:'scatter', line:{color:'#22c55e'}}], {
|
| 246 |
+
margin:{l:30,r:10,t:10,b:15}, paper_bgcolor:'transparent', plot_bgcolor:'transparent',
|
| 247 |
+
xaxis:{visible:false}, yaxis:{gridcolor:'#262626'}
|
| 248 |
+
});
|
| 249 |
+
}
|
|
|
|
|
|
|
|
|
|
| 250 |
|
| 251 |
+
} catch (e) { showError("UI Error: " + e.message); }
|
| 252 |
+
}, 250);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 253 |
</script>
|
| 254 |
</body>
|
| 255 |
</html>
|