| <!DOCTYPE html> |
| <html lang="en"> |
| <head> |
| <meta charset="UTF-8"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <title>CortexAI β Neurodynamical Computing Dashboard</title> |
| <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"> |
| <script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.js"></script> |
| <style> |
| *,*::before,*::after{box-sizing:border-box;margin:0;padding:0} |
| :root{ |
| --bg-950:#030712;--bg-900:#111827;--bg-800:#1f2937;--bg-700:#374151; |
| --bg-600:#4b5563;--bg-500:#6b7280;--bg-400:#9ca3af; |
| --cyan:#00bcd4;--amber:#ff9800;--purple:#9c27b0;--green:#4caf50;--red:#ef4444; |
| --blue:#2196f3;--white:#e0e0e0;--sidebar-w:256px; |
| } |
| html{font-family:'Consolas','Monaco',system-ui,-apple-system,BlinkMacSystemFont,sans-serif;color:var(--white);background:#0a0f1e;scroll-behavior:smooth} |
| body{display:flex;min-height:100vh;overflow-x:hidden} |
| a{color:var(--cyan);text-decoration:none} |
| button{cursor:pointer;font-family:inherit} |
| ::-webkit-scrollbar{width:6px} |
| ::-webkit-scrollbar-track{background:#0d1b2a} |
| ::-webkit-scrollbar-thumb{background:#1b2838;border-radius:3px} |
|
|
| /* ββ Sidebar ββ */ |
| .sidebar{position:fixed;left:0;top:0;bottom:0;width:var(--sidebar-w);background:#0d1b2a;border-right:1px solid #1b2838;display:flex;flex-direction:column;z-index:100;transition:transform .3s} |
| .sidebar-logo{display:flex;align-items:center;gap:10px;padding:20px 20px 16px;border-bottom:1px solid #1b2838} |
| .sidebar-logo img{height:36px;width:36px;border-radius:8px} |
| .sidebar-logo span{font-size:1.1rem;font-weight:700;letter-spacing:-.02em} |
| .sidebar-nav{flex:1;padding:12px 0;overflow-y:auto} |
| .nav-item{display:flex;align-items:center;gap:12px;padding:10px 20px;color:#78909c;font-size:.9rem;font-weight:500;transition:all .15s;border-left:3px solid transparent;font-family:Consolas,Monaco,monospace} |
| .nav-item:hover{color:var(--white);background:rgba(255,255,255,.04)} |
| .nav-item.active{color:var(--cyan);background:rgba(0,188,212,.08);border-left-color:var(--cyan)} |
| .nav-item svg{width:20px;height:20px;flex-shrink:0} |
| .sidebar-footer{padding:16px 20px;border-top:1px solid #1b2838;font-size:.75rem;color:#546e7a} |
|
|
| /* ββ Main ββ */ |
| .main{margin-left:var(--sidebar-w);flex:1;min-height:100vh;display:flex;flex-direction:column} |
| .topbar{position:sticky;top:0;z-index:50;height:56px;background:rgba(10,15,30,.92);backdrop-filter:blur(12px);border-bottom:1px solid #1b2838;display:flex;align-items:center;justify-content:space-between;padding:0 32px} |
| .topbar-left{display:flex;align-items:center;gap:12px} |
| .topbar-title{font-size:.95rem;font-weight:600} |
| .conn-dot{width:8px;height:8px;border-radius:50%;background:var(--green);animation:pulse 2s infinite} |
| .conn-label{font-size:.8rem;color:#78909c} |
| @keyframes pulse{0%,100%{opacity:1}50%{opacity:.4}} |
| .hamburger{display:none;background:none;border:none;color:var(--white);font-size:1.3rem} |
| .content{flex:1;padding:32px} |
|
|
| /* ββ Cards / Panels ββ */ |
| .card{background:#0d1b2a;border:1px solid #1b2838;border-radius:12px;padding:24px;position:relative;overflow:hidden} |
| .card-header{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px} |
| .card-title{font-size:1rem;font-weight:600} |
| .card-badge{font-size:.7rem;padding:3px 8px;border-radius:9999px;font-weight:600;text-transform:uppercase} |
| .badge-green{background:rgba(16,185,129,.15);color:var(--green)} |
| .badge-amber{background:rgba(245,158,11,.15);color:var(--amber)} |
| .badge-purple{background:rgba(168,85,247,.15);color:var(--purple)} |
| .badge-cyan{background:rgba(6,182,212,.15);color:var(--cyan)} |
| .badge-red{background:rgba(239,68,68,.15);color:var(--red)} |
| .math-box{background:#111d2e;border:1px solid #1b2838;border-radius:8px;padding:12px 16px;margin:12px 0;font-size:.85rem;overflow-x:auto} |
| .state-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(130px,1fr));gap:8px;margin-top:12px} |
| .state-item{background:#111d2e;border:1px solid #1b2838;border-radius:6px;padding:8px 10px} |
| .state-label{font-size:.7rem;color:#78909c;text-transform:uppercase;letter-spacing:.04em;font-family:Consolas,Monaco,monospace} |
| .state-value{font-size:1rem;font-weight:600;font-variant-numeric:tabular-nums;font-family:Consolas,Monaco,monospace;color:#e0e0e0} |
| canvas{display:block;width:100%;border-radius:8px;background:#16213e;border:1px solid var(--bg-700)} |
| .mini-panel{min-height:140px} |
|
|
| /* ββ Tabs ββ */ |
| .tabs{display:flex;gap:4px;margin-bottom:24px;flex-wrap:wrap} |
| .tab-btn{padding:8px 16px;border-radius:8px;border:1px solid transparent;background:transparent;color:#78909c;font-size:.85rem;font-weight:500;transition:all .15s;font-family:Consolas,Monaco,monospace} |
| .tab-btn:hover{color:var(--white);background:#111d2e} |
| .tab-btn.active{color:var(--cyan);background:rgba(6,182,212,.1);border-color:rgba(6,182,212,.3)} |
| .tab-panel{display:none} |
| .tab-panel.active{display:block} |
|
|
| /* ββ Grid layouts ββ */ |
| .grid-2{display:grid;grid-template-columns:1fr 1fr;gap:20px} |
| .grid-3{display:grid;grid-template-columns:repeat(3,1fr);gap:20px} |
| @media(max-width:1200px){.grid-3{grid-template-columns:1fr 1fr}} |
| @media(max-width:900px){.grid-2,.grid-3{grid-template-columns:1fr}.sidebar{transform:translateX(-100%)}.sidebar.open{transform:translateX(0)}.main{margin-left:0}.hamburger{display:block}} |
|
|
| /* ββ Landing / Home ββ */ |
| .hero{text-align:center;padding:64px 0 48px} |
| .hero h1{font-size:3rem;font-weight:800;letter-spacing:-.03em;line-height:1.1;background:linear-gradient(135deg,#00bcd4,#9c27b0);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text} |
| .hero p{margin-top:16px;font-size:1.15rem;color:#78909c;max-width:640px;margin-left:auto;margin-right:auto;line-height:1.6} |
| .hero-badge{display:inline-flex;align-items:center;gap:6px;padding:6px 14px;border-radius:9999px;background:rgba(0,188,212,.1);border:1px solid rgba(0,188,212,.2);font-size:.8rem;color:var(--cyan);font-weight:500;margin-bottom:20px} |
| .features{display:grid;grid-template-columns:repeat(auto-fit,minmax(280px,1fr));gap:20px;margin-top:40px} |
| .feature-card{background:#0d1b2a;border:1px solid #1b2838;border-radius:12px;padding:28px;transition:border-color .2s} |
| .feature-card:hover{border-color:var(--cyan)} |
| .feature-icon{font-size:1.8rem;margin-bottom:12px} |
| .feature-card h3{font-size:1rem;font-weight:600;margin-bottom:8px} |
| .feature-card p{font-size:.85rem;color:#78909c;line-height:1.5} |
| .module-list{margin-top:48px} |
| .module-list h2{font-size:1.5rem;font-weight:700;margin-bottom:24px;text-align:center} |
| .perf-grid{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:16px;margin-top:40px} |
| .perf-item{text-align:center;padding:20px;background:#0d1b2a;border:1px solid #1b2838;border-radius:10px} |
| .perf-num{font-size:2rem;font-weight:800;background:linear-gradient(135deg,#00bcd4,#4caf50);-webkit-background-clip:text;-webkit-text-fill-color:transparent;background-clip:text} |
| .perf-label{font-size:.8rem;color:#78909c;margin-top:4px} |
| .footer{text-align:center;padding:32px 0;color:#546e7a;font-size:.8rem;border-top:1px solid #1b2838;margin-top:48px} |
| .placeholder-page{display:flex;flex-direction:column;align-items:center;justify-content:center;min-height:40vh;text-align:center} |
| .placeholder-page h2{font-size:1.5rem;font-weight:700;margin-bottom:8px} |
| .placeholder-page p{color:#78909c} |
| .overview-grid{display:grid;grid-template-columns:1fr 1fr;gap:20px} |
| @media(max-width:1100px){.overview-grid{grid-template-columns:1fr}} |
| .mini-panel{height:220px} |
| </style> |
| </head> |
| <body> |
|
|
| |
| <aside class="sidebar" id="sidebar"> |
| <div class="sidebar-logo"> |
| <img src="/logo.png" alt="CortexAI" onerror="this.style.display='none'"> |
| <span>CortexAI</span> |
| </div> |
| <nav class="sidebar-nav" id="sidebarNav"> |
| <a class="nav-item active" href="/" data-route="home"> |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M3 9l9-7 9 7v11a2 2 0 01-2 2H5a2 2 0 01-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/></svg> |
| Home |
| </a> |
| <a class="nav-item" href="/dashboard" data-route="dashboard"> |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/></svg> |
| Dashboard |
| </a> |
| <a class="nav-item" href="/playground" data-route="playground"> |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><polygon points="5 3 19 12 5 21 5 3"/></svg> |
| Playground |
| </a> |
| <a class="nav-item" href="/settings" data-route="settings"> |
| <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 00.33 1.82l.06.06a2 2 0 01-2.83 2.83l-.06-.06a1.65 1.65 0 00-1.82-.33 1.65 1.65 0 00-1 1.51V21a2 2 0 01-4 0v-.09A1.65 1.65 0 009 19.4a1.65 1.65 0 00-1.82.33l-.06.06a2 2 0 01-2.83-2.83l.06-.06A1.65 1.65 0 004.68 15a1.65 1.65 0 00-1.51-1H3a2 2 0 010-4h.09A1.65 1.65 0 004.6 9a1.65 1.65 0 00-.33-1.82l-.06-.06a2 2 0 012.83-2.83l.06.06A1.65 1.65 0 009 4.68a1.65 1.65 0 001-1.51V3a2 2 0 014 0v.09a1.65 1.65 0 001 1.51 1.65 1.65 0 001.82-.33l.06-.06a2 2 0 012.83 2.83l-.06.06A1.65 1.65 0 0019.4 9a1.65 1.65 0 001.51 1H21a2 2 0 010 4h-.09a1.65 1.65 0 00-1.51 1z"/></svg> |
| Settings |
| </a> |
| </nav> |
| <div class="sidebar-footer">CortexAI v0.1.0 Β· Neurodynamical Computing</div> |
| </aside> |
|
|
| |
| <div class="main"> |
| <header class="topbar"> |
| <div class="topbar-left"> |
| <button class="hamburger" id="hamburger" onclick="document.getElementById('sidebar').classList.toggle('open')">β°</button> |
| <span class="topbar-title" id="topbarTitle">CortexAI</span> |
| </div> |
| <div style="display:flex;align-items:center;gap:8px"> |
| <div class="conn-dot"></div> |
| <span class="conn-label">Simulator Active</span> |
| </div> |
| </header> |
| <div class="content" id="app"></div> |
| </div> |
|
|
| <script> |
| (function(){ |
| "use strict"; |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| KaTeX helper |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| function renderMath(el){ |
| if(!window.katex) return; |
| el.querySelectorAll('.katex-render').forEach(span=>{ |
| try{ katex.render(span.getAttribute('data-tex'), span, {throwOnError:false, displayMode:span.hasAttribute('data-display')}); }catch(e){} |
| }); |
| } |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Navigation & Routing |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| let currentRoute = 'home'; |
| let currentDashTab = 'overview'; |
| const navItems = document.querySelectorAll('.nav-item'); |
| |
| function setActiveNav(route){ |
| navItems.forEach(n=>{ n.classList.toggle('active', n.dataset.route===route); }); |
| } |
| |
| function navigate(route, push){ |
| if(push!==false) history.pushState({route}, '', route==='home' ? '/' : '/'+route); |
| currentRoute = route; |
| setActiveNav(route); |
| document.getElementById('sidebar').classList.remove('open'); |
| render(); |
| } |
| |
| window.addEventListener('popstate', e=>{ |
| const r = (e.state && e.state.route) || location.pathname.replace('/','') || 'home'; |
| navigate(r, false); |
| }); |
| |
| navItems.forEach(n=>n.addEventListener('click', e=>{ |
| e.preventDefault(); |
| navigate(n.dataset.route); |
| })); |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Neural Simulation Engine |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| const N_OSC = 10; |
| const sim = { |
| kuramoto: { |
| phi: Array.from({length:N_OSC},()=>Math.random()*Math.PI*2), |
| omega: Array.from({length:N_OSC},(_,i)=>0.8+0.4*i/(N_OSC-1)), |
| K: 1.0, dt: 0.02, r: 0, meanPhase: 0 |
| }, |
| wilsonCowan: { |
| E: 0.1, I: 0.1, W_ee:10, W_ei:-4, W_ie:8, W_ii:-2, I_ext:1.5, |
| tau_E:1, tau_I:1, dt:0.01, histE:[], histI:[], maxHist:300 |
| }, |
| izhikevich: { |
| v: -65, u: -65*0.2, a:0.02, b:0.2, c:-65, d:8, I:10, |
| history: new Float32Array(200), spikes: [], tick: 0 |
| }, |
| lyapunov: { value: -0.5, history: new Float32Array(100), tick:0 }, |
| dopamine: { |
| V: 0, alpha:0.1, gamma:0.99, R:0, delta:0, |
| historyDA: new Float32Array(200), |
| historyRPE: new Float32Array(200), |
| historyPred: new Float32Array(200), |
| tick: 0, rewardTimer: 0 |
| } |
| }; |
| |
| function sigmoid(x){ return 1/(1+Math.exp(-x)); } |
| |
| function stepKuramoto(){ |
| const k = sim.kuramoto; |
| const newPhi = new Array(N_OSC); |
| for(let i=0;i<N_OSC;i++){ |
| let sum = 0; |
| for(let j=0;j<N_OSC;j++) sum += Math.sin(k.phi[j]-k.phi[i]); |
| newPhi[i] = k.phi[i] + k.dt*(k.omega[i] + k.K/N_OSC*sum); |
| } |
| k.phi = newPhi; |
| // order parameter |
| let sx=0, sy=0; |
| for(let i=0;i<N_OSC;i++){ sx+=Math.cos(k.phi[i]); sy+=Math.sin(k.phi[i]); } |
| k.r = Math.sqrt(sx*sx+sy*sy)/N_OSC; |
| k.meanPhase = Math.atan2(sy,sx); |
| } |
| |
| function stepWilsonCowan(){ |
| const w = sim.wilsonCowan; |
| const noise = ()=>(Math.random()-0.5)*0.1; |
| const dE = (-w.E + sigmoid(w.W_ee*w.E + w.W_ei*w.I + w.I_ext)) / w.tau_E + noise(); |
| const dI = (-w.I + sigmoid(w.W_ie*w.E + w.W_ii*w.I)) / w.tau_I + noise(); |
| w.E = Math.max(0, Math.min(1, w.E + w.dt*dE)); |
| w.I = Math.max(0, Math.min(1, w.I + w.dt*dI)); |
| w.histE.push(w.E); w.histI.push(w.I); |
| if(w.histE.length>w.maxHist){ w.histE.shift(); w.histI.shift(); } |
| } |
| |
| function stepIzhikevich(){ |
| const iz = sim.izhikevich; |
| iz.I = 10 + 5*Math.sin(iz.tick*0.03); |
| const dv = 0.04*iz.v*iz.v + 5*iz.v + 140 - iz.u + iz.I; |
| const du = iz.a*(iz.b*iz.v - iz.u); |
| iz.v += dv * 0.5; |
| iz.u += du * 0.5; |
| // second Euler step for stability |
| const dv2 = 0.04*iz.v*iz.v + 5*iz.v + 140 - iz.u + iz.I; |
| iz.v += dv2 * 0.5; |
| iz.u += du * 0.5; |
| let spiked = false; |
| if(iz.v >= 30){ |
| iz.history[iz.tick % 200] = 30; |
| iz.v = iz.c; |
| iz.u += iz.d; |
| spiked = true; |
| iz.spikes.push(iz.tick % 200); |
| if(iz.spikes.length > 30) iz.spikes.shift(); |
| } else { |
| iz.history[iz.tick % 200] = iz.v; |
| } |
| iz.tick++; |
| } |
| |
| function stepLyapunov(){ |
| const ly = sim.lyapunov; |
| ly.value += (Math.random()-0.5)*0.08 - 0.01*(ly.value+0.5); |
| ly.value = Math.max(-2, Math.min(1, ly.value)); |
| ly.history[ly.tick % 100] = ly.value; |
| ly.tick++; |
| } |
| |
| function stepDopamine(){ |
| const d = sim.dopamine; |
| d.rewardTimer++; |
| d.R = (d.rewardTimer % 120 < 5) ? 1.0 : 0.0; |
| d.V = d.V + d.alpha*(d.R - d.V); |
| d.delta = d.R - d.V; |
| const t = d.tick % 200; |
| d.historyDA[t] = d.V; |
| d.historyRPE[t] = d.delta; |
| d.historyPred[t] = d.V; |
| d.tick++; |
| } |
| |
| function stepAll(){ |
| stepKuramoto(); |
| stepWilsonCowan(); |
| stepIzhikevich(); |
| stepLyapunov(); |
| stepDopamine(); |
| } |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| MATLAB-Style Plot Utilities |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| const ML = { |
| panelBg: '#16213e', |
| gridMinor: 'rgba(100,120,160,0.10)', |
| gridMajor: 'rgba(100,120,160,0.22)', |
| axisColor: '#5a6a8a', |
| textColor: '#b0bec5', |
| titleColor: '#e0e0e0', |
| font: "'Consolas','Monaco','Courier New',monospace", |
| colors: ['#00bcd4','#e91e63','#ff9800','#4caf50','#9c27b0','#2196f3','#ff5722','#8bc34a','#ffc107','#03a9f4'], |
| ticks(min, max, n) { |
| const t = []; |
| for (let i = 0; i <= n; i++) { |
| const v = min + (max - min) * (i / n); |
| t.push({ v, norm: i / n, label: Math.abs(v) < 1e-6 ? '0' : (Number.isInteger(v) ? '' + v : v.toFixed(1)) }); |
| } |
| return t; |
| }, |
| axes(ctx, pad, pw, ph, w, h, o) { |
| const { yLabel, xLabel, title, yTicks, xTicks } = o; |
| // panel fill |
| ctx.fillStyle = ML.panelBg; |
| ctx.fillRect(pad.l, pad.t, pw, ph); |
| // minor grid |
| ctx.lineWidth = 0.5; |
| ctx.strokeStyle = ML.gridMinor; |
| (yTicks || []).forEach(t => { |
| const y = pad.t + ph * (1 - t.norm); |
| ctx.beginPath(); ctx.moveTo(pad.l, y); ctx.lineTo(pad.l + pw, y); ctx.stroke(); |
| }); |
| // major grid |
| ctx.lineWidth = 0.8; |
| ctx.strokeStyle = ML.gridMajor; |
| (yTicks || []).forEach(t => { |
| const y = pad.t + ph * (1 - t.norm); |
| ctx.beginPath(); ctx.moveTo(pad.l, y); ctx.lineTo(pad.l + pw, y); ctx.stroke(); |
| }); |
| // box |
| ctx.strokeStyle = ML.axisColor; ctx.lineWidth = 1.2; |
| ctx.strokeRect(pad.l, pad.t, pw, ph); |
| // tick marks + labels |
| ctx.lineWidth = 1.2; |
| (yTicks || []).forEach(t => { |
| const y = pad.t + ph * (1 - t.norm); |
| ctx.strokeStyle = ML.axisColor; |
| ctx.beginPath(); ctx.moveTo(pad.l - 4, y); ctx.lineTo(pad.l, y); ctx.stroke(); |
| ctx.fillStyle = ML.textColor; ctx.font = '10px ' + ML.font; ctx.textAlign = 'right'; |
| ctx.fillText(t.label, pad.l - 7, y + 3.5); |
| }); |
| (xTicks || []).forEach(t => { |
| const x = pad.l + t.norm * pw; |
| ctx.strokeStyle = ML.axisColor; |
| ctx.beginPath(); ctx.moveTo(x, pad.t + ph); ctx.lineTo(x, pad.t + ph + 4); ctx.stroke(); |
| ctx.fillStyle = ML.textColor; ctx.font = '10px ' + ML.font; ctx.textAlign = 'center'; |
| ctx.fillText(t.label, x, pad.t + ph + 14); |
| }); |
| // axis labels |
| if (yLabel) { |
| ctx.save(); ctx.fillStyle = ML.textColor; ctx.font = '11px ' + ML.font; ctx.textAlign = 'center'; |
| ctx.translate(12, pad.t + ph / 2); ctx.rotate(-Math.PI / 2); ctx.fillText(yLabel, 0, 0); ctx.restore(); |
| } |
| if (xLabel) { |
| ctx.fillStyle = ML.textColor; ctx.font = '11px ' + ML.font; ctx.textAlign = 'center'; |
| ctx.fillText(xLabel, pad.l + pw / 2, h - 4); |
| } |
| // title |
| if (title) { |
| ctx.fillStyle = ML.titleColor; ctx.font = 'bold 12px ' + ML.font; ctx.textAlign = 'left'; |
| ctx.fillText(title, pad.l, pad.t - 6); |
| } |
| }, |
| legend(ctx, items, x, y) { |
| const ll = 18, px = 8, py = 6, lh = 16; |
| const mw = Math.max(...items.map(it => { ctx.font = '10px ' + ML.font; return ctx.measureText(it.label).width; })); |
| const bw = px * 2 + ll + 6 + mw, bh = py * 2 + items.length * lh; |
| ctx.fillStyle = 'rgba(22,33,62,0.92)'; ctx.fillRect(x, y, bw, bh); |
| ctx.strokeStyle = ML.axisColor; ctx.lineWidth = 0.8; ctx.strokeRect(x, y, bw, bh); |
| items.forEach((it, i) => { |
| const iy = y + py + i * lh + lh / 2; |
| ctx.strokeStyle = it.color; ctx.lineWidth = 2; |
| ctx.beginPath(); ctx.moveTo(x + px, iy); ctx.lineTo(x + px + ll, iy); ctx.stroke(); |
| ctx.fillStyle = ML.textColor; ctx.font = '10px ' + ML.font; ctx.textAlign = 'left'; |
| ctx.fillText(it.label, x + px + ll + 6, iy + 3.5); |
| }); |
| }, |
| line(ctx, data, color, pad, pw, ph, yMin, yMax, o) { |
| const { fill, lw, dashed } = o || {}; |
| if (data.length < 2) return; |
| const vToY = v => pad.t + ph * (1 - (v - yMin) / (yMax - yMin)); |
| ctx.beginPath(); ctx.strokeStyle = color; ctx.lineWidth = lw || 1.8; |
| if (dashed) ctx.setLineDash([6, 4]); |
| data.forEach((v, i) => { |
| const x = pad.l + (i / (data.length - 1)) * pw; |
| const y = vToY(Math.max(yMin, Math.min(yMax, v))); |
| i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y); |
| }); |
| ctx.stroke(); ctx.setLineDash([]); |
| if (fill) { |
| ctx.lineTo(pad.l + pw, pad.t + ph); ctx.lineTo(pad.l, pad.t + ph); ctx.closePath(); |
| ctx.fillStyle = color; ctx.globalAlpha = 0.12; ctx.fill(); ctx.globalAlpha = 1; |
| } |
| } |
| }; |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Canvas Renderers (MATLAB Style) |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| |
| function renderKuramotoCanvas(canvas) { |
| if (!canvas) return; |
| const ctx = canvas.getContext('2d'); |
| const dpr = window.devicePixelRatio || 1; |
| canvas.width = canvas.clientWidth * dpr; |
| canvas.height = canvas.clientHeight * dpr; |
| ctx.scale(dpr, dpr); |
| const w = canvas.clientWidth, h = canvas.clientHeight; |
| const k = sim.kuramoto; |
| const cx = w / 2, cy = h / 2, R = Math.min(w, h) * 0.32; |
| |
| ctx.fillStyle = ML.panelBg; ctx.fillRect(0, 0, w, h); |
| |
| // unit circle |
| ctx.strokeStyle = ML.gridMajor; ctx.lineWidth = 1; |
| ctx.beginPath(); ctx.arc(cx, cy, R, 0, Math.PI * 2); ctx.stroke(); |
| // angle grid |
| ctx.strokeStyle = ML.gridMinor; ctx.lineWidth = 0.5; |
| for (let a = 0; a < Math.PI * 2; a += Math.PI / 4) { |
| ctx.beginPath(); ctx.moveTo(cx, cy); ctx.lineTo(cx + R * 1.1 * Math.cos(a), cy + R * 1.1 * Math.sin(a)); ctx.stroke(); |
| } |
| // connections |
| for (let i = 0; i < N_OSC; i++) { |
| for (let j = i + 1; j < N_OSC; j++) { |
| let diff = Math.abs(k.phi[i] - k.phi[j]); if (diff > Math.PI) diff = Math.PI * 2 - diff; |
| if (diff < 0.8) { |
| ctx.strokeStyle = `rgba(0,188,212,${0.15 + 0.35 * (1 - diff / 0.8)})`; |
| ctx.lineWidth = 1 + (1 - diff / 0.8); |
| ctx.beginPath(); |
| ctx.moveTo(cx + R * Math.cos(k.phi[i]), cy + R * Math.sin(k.phi[i])); |
| ctx.lineTo(cx + R * Math.cos(k.phi[j]), cy + R * Math.sin(k.phi[j])); |
| ctx.stroke(); |
| } |
| } |
| } |
| // oscillators |
| for (let i = 0; i < N_OSC; i++) { |
| const x = cx + R * Math.cos(k.phi[i]), y = cy + R * Math.sin(k.phi[i]); |
| const hue = ((k.phi[i] / (Math.PI * 2)) * 360 + 360) % 360; |
| const grad = ctx.createRadialGradient(x, y, 0, x, y, 14); |
| grad.addColorStop(0, `hsla(${hue},80%,60%,0.4)`); grad.addColorStop(1, `hsla(${hue},80%,60%,0)`); |
| ctx.fillStyle = grad; ctx.beginPath(); ctx.arc(x, y, 14, 0, Math.PI * 2); ctx.fill(); |
| ctx.beginPath(); ctx.arc(x, y, 7, 0, Math.PI * 2); |
| ctx.fillStyle = `hsl(${hue},80%,55%)`; ctx.fill(); |
| ctx.strokeStyle = `hsl(${hue},80%,75%)`; ctx.lineWidth = 1.5; ctx.stroke(); |
| ctx.fillStyle = '#fff'; ctx.font = 'bold 8px ' + ML.font; ctx.textAlign = 'center'; ctx.fillText(i + 1, x, y + 3); |
| } |
| // order arrow |
| const ax = cx + k.r * R * 0.85 * Math.cos(k.meanPhase), ay = cy + k.r * R * 0.85 * Math.sin(k.meanPhase); |
| ctx.beginPath(); ctx.moveTo(cx, cy); ctx.lineTo(ax, ay); ctx.strokeStyle = '#fff'; ctx.lineWidth = 2.5; ctx.stroke(); |
| ctx.beginPath(); ctx.arc(ax, ay, 5, 0, Math.PI * 2); ctx.fillStyle = '#fff'; ctx.fill(); |
| // info |
| ctx.fillStyle = ML.titleColor; ctx.font = 'bold 12px ' + ML.font; ctx.textAlign = 'left'; |
| ctx.fillText('Kuramoto Phase Synchronization', 12, 18); |
| ctx.fillStyle = ML.textColor; ctx.font = '11px ' + ML.font; |
| ctx.fillText('r = ' + k.r.toFixed(4) + ' | \u03C8 = ' + (k.meanPhase * 180 / Math.PI).toFixed(1) + '\u00B0', 12, 34); |
| // colorbar |
| const bx = w - 30, by = 40, bh = h - 80; |
| const bg = ctx.createLinearGradient(0, by, 0, by + bh); |
| for (let i = 0; i <= 10; i++) bg.addColorStop(i / 10, `hsl(${i / 10 * 360},80%,55%)`); |
| ctx.fillStyle = bg; ctx.fillRect(bx, by, 12, bh); |
| ctx.strokeStyle = ML.axisColor; ctx.lineWidth = 0.8; ctx.strokeRect(bx, by, 12, bh); |
| ctx.fillStyle = ML.textColor; ctx.font = '9px ' + ML.font; ctx.textAlign = 'left'; |
| ctx.fillText('2\u03C0', bx + 16, by + 8); ctx.fillText('0', bx + 16, by + bh); |
| } |
| |
| function renderWilsonCowanCanvas(canvas) { |
| if (!canvas) return; |
| const ctx = canvas.getContext('2d'); |
| const dpr = window.devicePixelRatio || 1; |
| canvas.width = canvas.clientWidth * dpr; canvas.height = canvas.clientHeight * dpr; |
| ctx.scale(dpr, dpr); |
| const w = canvas.clientWidth, h = canvas.clientHeight; |
| ctx.fillStyle = ML.panelBg; ctx.fillRect(0, 0, w, h); |
| const wc = sim.wilsonCowan; |
| const pad = { l: 52, r: 16, t: 28, b: 36 }; |
| const pw = w - pad.l - pad.r, ph = h - pad.t - pad.b; |
| const yMin = -0.1, yMax = 1.1; |
| ML.axes(ctx, pad, pw, ph, w, h, { |
| yLabel: 'Activation', xLabel: 'Time (samples)', title: 'Wilson-Cowan E/I Dynamics', |
| yTicks: ML.ticks(yMin, yMax, 5), |
| }); |
| ML.line(ctx, wc.histE, ML.colors[3], pad, pw, ph, yMin, yMax, { fill: true }); |
| ML.line(ctx, wc.histI, ML.colors[4], pad, pw, ph, yMin, yMax, { fill: true }); |
| ML.legend(ctx, [ |
| { color: ML.colors[3], label: 'E (Excitatory)' }, |
| { color: ML.colors[4], label: 'I (Inhibitory)' }, |
| ], pad.l + pw - 140, pad.t + 6); |
| // current markers |
| const vToY = v => pad.t + ph * (1 - (v - yMin) / (yMax - yMin)); |
| if (wc.histE.length) { |
| ctx.beginPath(); ctx.arc(pad.l + pw, vToY(Math.max(yMin, Math.min(yMax, wc.histE[wc.histE.length - 1]))), 4, 0, Math.PI * 2); |
| ctx.fillStyle = ML.colors[3]; ctx.fill(); |
| } |
| if (wc.histI.length) { |
| ctx.beginPath(); ctx.arc(pad.l + pw, vToY(Math.max(yMin, Math.min(yMax, wc.histI[wc.histI.length - 1]))), 4, 0, Math.PI * 2); |
| ctx.fillStyle = ML.colors[4]; ctx.fill(); |
| } |
| } |
| |
| function renderIzhikevichCanvas(canvas) { |
| if (!canvas) return; |
| const ctx = canvas.getContext('2d'); |
| const dpr = window.devicePixelRatio || 1; |
| canvas.width = canvas.clientWidth * dpr; canvas.height = canvas.clientHeight * dpr; |
| ctx.scale(dpr, dpr); |
| const w = canvas.clientWidth, h = canvas.clientHeight; |
| ctx.fillStyle = ML.panelBg; ctx.fillRect(0, 0, w, h); |
| const iz = sim.izhikevich; |
| const pad = { l: 52, r: 16, t: 28, b: 36 }; |
| const pw = w - pad.l - pad.r, ph = h - pad.t - pad.b; |
| const vMin = -90, vMax = 40; |
| ML.axes(ctx, pad, pw, ph, w, h, { |
| yLabel: 'Voltage (mV)', xLabel: 'Time (samples)', title: 'Izhikevich Membrane Potential', |
| yTicks: ML.ticks(vMin, vMax, 6), |
| }); |
| const vToY = v => pad.t + ph * (1 - (v - vMin) / (vMax - vMin)); |
| // threshold |
| ctx.strokeStyle = 'rgba(239,68,68,0.6)'; ctx.lineWidth = 1.2; ctx.setLineDash([8, 4]); |
| ctx.beginPath(); ctx.moveTo(pad.l, vToY(30)); ctx.lineTo(pad.l + pw, vToY(30)); ctx.stroke(); ctx.setLineDash([]); |
| ctx.fillStyle = '#ef4444'; ctx.font = '9px ' + ML.font; ctx.textAlign = 'right'; |
| ctx.fillText('threshold 30mV', pad.l + pw - 4, vToY(30) - 4); |
| // voltage trace |
| const step = pw / 199, startIdx = iz.tick % 200; |
| // fill under curve |
| const grad = ctx.createLinearGradient(0, pad.t, 0, pad.t + ph); |
| grad.addColorStop(0, 'rgba(0,188,212,0.2)'); grad.addColorStop(1, 'rgba(0,188,212,0)'); |
| ctx.fillStyle = grad; ctx.beginPath(); ctx.moveTo(pad.l, pad.t + ph); |
| for (let i = 0; i < 200; i++) { |
| const v = iz.history[(startIdx + i) % 200]; |
| ctx.lineTo(pad.l + i * step, vToY(Math.max(vMin, Math.min(vMax, v)))); |
| } |
| ctx.lineTo(pad.l + 199 * step, pad.t + ph); ctx.closePath(); ctx.fill(); |
| // line |
| ctx.beginPath(); ctx.strokeStyle = ML.colors[0]; ctx.lineWidth = 1.5; |
| for (let i = 0; i < 200; i++) { |
| const v = iz.history[(startIdx + i) % 200]; |
| const x = pad.l + i * step, y = vToY(Math.max(vMin, Math.min(vMax, v))); |
| i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y); |
| } |
| ctx.stroke(); |
| // spikes |
| iz.spikes.forEach(si => { |
| const rel = (si - startIdx + 200) % 200; |
| const x = pad.l + rel * step; |
| ctx.fillStyle = ML.colors[1]; |
| ctx.beginPath(); ctx.arc(x, vToY(30), 4, 0, Math.PI * 2); ctx.fill(); |
| ctx.strokeStyle = ML.colors[1]; ctx.lineWidth = 1.5; |
| ctx.beginPath(); ctx.moveTo(x, vToY(30)); ctx.lineTo(x, vToY(40)); ctx.stroke(); |
| }); |
| // current dot |
| ctx.beginPath(); ctx.arc(pad.l + pw, vToY(Math.max(vMin, Math.min(vMax, iz.v))), 4, 0, Math.PI * 2); |
| ctx.fillStyle = ML.colors[0]; ctx.fill(); |
| ML.legend(ctx, [ |
| { color: ML.colors[0], label: 'V(t) membrane' }, |
| { color: ML.colors[1], label: 'Spikes (v\u226530)' }, |
| ], pad.l + 6, pad.t + 6); |
| } |
| |
| function renderLyapunovGauge(canvas) { |
| if (!canvas) return; |
| const ctx = canvas.getContext('2d'); |
| const dpr = window.devicePixelRatio || 1; |
| canvas.width = canvas.clientWidth * dpr; canvas.height = canvas.clientHeight * dpr; |
| ctx.scale(dpr, dpr); |
| const w = canvas.clientWidth, h = canvas.clientHeight; |
| ctx.fillStyle = ML.panelBg; ctx.fillRect(0, 0, w, h); |
| const ly = sim.lyapunov; |
| const cx = w / 2, cy = h * 0.52, r = Math.min(w, h) * 0.34; |
| const startAngle = Math.PI * 0.82, endAngle = Math.PI * 0.18; |
| const totalArc = (2 * Math.PI - startAngle) + endAngle; |
| // arc bg |
| ctx.beginPath(); ctx.arc(cx, cy, r, startAngle, 2 * Math.PI + endAngle); |
| ctx.strokeStyle = '#374151'; ctx.lineWidth = 14; ctx.lineCap = 'round'; ctx.stroke(); |
| // tick marks on arc |
| for (let i = 0; i <= 10; i++) { |
| const a = startAngle + (i / 10) * totalArc; |
| ctx.beginPath(); |
| ctx.moveTo(cx + (r - 10) * Math.cos(a), cy + (r - 10) * Math.sin(a)); |
| ctx.lineTo(cx + (r + 10) * Math.cos(a), cy + (r + 10) * Math.sin(a)); |
| ctx.strokeStyle = i % 5 === 0 ? ML.axisColor : ML.gridMajor; |
| ctx.lineWidth = i % 5 === 0 ? 1.5 : 0.8; ctx.stroke(); |
| } |
| // filled arc |
| const t = (ly.value - (-2)) / 3; |
| const grad = ctx.createLinearGradient(cx - r, cy, cx + r, cy); |
| grad.addColorStop(0, '#ef4444'); grad.addColorStop(0.4, '#ff9800'); grad.addColorStop(0.6, '#ffeb3b'); grad.addColorStop(1, '#4caf50'); |
| ctx.beginPath(); ctx.arc(cx, cy, r, startAngle, Math.min(startAngle + t * totalArc, 2 * Math.PI + endAngle)); |
| ctx.strokeStyle = grad; ctx.lineWidth = 14; ctx.lineCap = 'round'; ctx.stroke(); |
| // needle |
| const na = startAngle + t * totalArc; |
| ctx.beginPath(); ctx.moveTo(cx + 10 * Math.cos(na), cy + 10 * Math.sin(na)); |
| ctx.lineTo(cx + (r - 18) * Math.cos(na), cy + (r - 18) * Math.sin(na)); |
| ctx.strokeStyle = '#fff'; ctx.lineWidth = 2.5; ctx.stroke(); |
| ctx.beginPath(); ctx.arc(cx, cy, 5, 0, Math.PI * 2); ctx.fillStyle = '#fff'; ctx.fill(); |
| // value |
| ctx.fillStyle = ly.value < 0 ? '#4caf50' : ly.value > 0 ? '#ef4444' : '#ff9800'; |
| ctx.font = 'bold 22px ' + ML.font; ctx.textAlign = 'center'; |
| ctx.fillText(ly.value.toFixed(4), cx, cy + r * 0.55); |
| ctx.fillStyle = ML.textColor; ctx.font = '11px ' + ML.font; |
| ctx.fillText('Lyapunov Exponent \u03BB', cx, cy + r * 0.55 + 16); |
| // scale |
| ctx.font = '10px ' + ML.font; ctx.fillStyle = ML.textColor; |
| ctx.fillText('-2', cx + (r + 18) * Math.cos(startAngle), cy + (r + 18) * Math.sin(startAngle)); |
| ctx.fillText('+1', cx + (r + 18) * Math.cos(2 * Math.PI + endAngle), cy + (r + 18) * Math.sin(2 * Math.PI + endAngle)); |
| ctx.fillText('0', cx + (r + 18) * Math.cos(startAngle + totalArc * 2 / 3), cy + (r + 18) * Math.sin(startAngle + totalArc * 2 / 3)); |
| // status badge |
| const st = ly.value < 0 ? 'STABLE \u2014 Convergent' : ly.value > 0 ? 'UNSTABLE \u2014 Divergent' : 'MARGINAL'; |
| ctx.fillStyle = ly.value < 0 ? '#4caf50' : ly.value > 0 ? '#ef4444' : '#ff9800'; |
| ctx.font = 'bold 11px ' + ML.font; ctx.fillText(st, cx, cy + r * 0.55 + 34); |
| // sparkline |
| const sy = h - 18, sH = 30, sW = w - 60; |
| if (ly.tick > 2) { |
| ctx.strokeStyle = ML.gridMajor; ctx.lineWidth = 0.5; |
| ctx.beginPath(); ctx.moveTo(30, sy); ctx.lineTo(30 + sW, sy); ctx.stroke(); |
| ctx.beginPath(); |
| const hl = Math.min(ly.tick, 100), st2 = ly.tick - hl; |
| for (let i = 0; i < hl; i++) { |
| const v = ly.history[(st2 + i) % 100]; |
| const x = 30 + (i / (hl - 1)) * sW, y = sy - ((v + 2) / 3) * sH; |
| i === 0 ? ctx.moveTo(x, y) : ctx.lineTo(x, y); |
| } |
| ctx.strokeStyle = ML.colors[0]; ctx.lineWidth = 1; ctx.stroke(); |
| } |
| } |
| |
| function renderDopamineCanvas(canvas) { |
| if (!canvas) return; |
| const ctx = canvas.getContext('2d'); |
| const dpr = window.devicePixelRatio || 1; |
| canvas.width = canvas.clientWidth * dpr; canvas.height = canvas.clientHeight * dpr; |
| ctx.scale(dpr, dpr); |
| const w = canvas.clientWidth, h = canvas.clientHeight; |
| ctx.fillStyle = ML.panelBg; ctx.fillRect(0, 0, w, h); |
| const d = sim.dopamine; |
| const pad = { l: 52, r: 16, t: 28, b: 36 }; |
| const pw = w - pad.l - pad.r, ph = h - pad.t - pad.b; |
| const yMin = -0.5, yMax = 1.5; |
| ML.axes(ctx, pad, pw, ph, w, h, { |
| yLabel: 'Signal Level', xLabel: 'Time (samples)', |
| title: 'Dopamine Reward Prediction Error (Schultz 1997)', |
| yTicks: ML.ticks(yMin, yMax, 4), |
| }); |
| // zero line |
| ctx.strokeStyle = 'rgba(255,255,255,0.1)'; ctx.lineWidth = 1; |
| const zy = pad.t + ph * (1 - (0 - yMin) / (yMax - yMin)); |
| ctx.beginPath(); ctx.moveTo(pad.l, zy); ctx.lineTo(pad.l + pw, zy); ctx.stroke(); |
| ML.line(ctx, d.historyDA, ML.colors[0], pad, pw, ph, yMin, yMax, { lw: 2 }); |
| ML.line(ctx, d.historyRPE, ML.colors[1], pad, pw, ph, yMin, yMax, { lw: 2 }); |
| ML.line(ctx, d.historyPred, ML.colors[4], pad, pw, ph, yMin, yMax, { lw: 2, dashed: true }); |
| ML.legend(ctx, [ |
| { color: ML.colors[0], label: 'DA Level V(t)' }, |
| { color: ML.colors[1], label: 'RPE \u03B4(t)' }, |
| { color: ML.colors[4], label: 'Predicted V(t)' }, |
| ], pad.l + 6, pad.t + 6); |
| } |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Page Renderers |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| function tex(tex, display){ return `<span class="katex-render" data-tex="${tex.replace(/"/g,'"')}" ${display?'data-display':''}></span>`; } |
| |
| function renderHome(){ |
| document.getElementById('topbarTitle').textContent = 'CortexAI'; |
| return ` |
| <div class="hero"> |
| <div class="hero-badge">β‘ Neurodynamical Computing Platform</div> |
| <h1>CortexAI</h1> |
| <p>Real-time neurodynamical simulation dashboard. Explore coupled oscillators, spiking neurons, excitatory-inhibitory dynamics, stability analysis, and reward prediction β all in your browser.</p> |
| </div> |
| <div class="features"> |
| <div class="feature-card"> |
| <div class="feature-icon">π§ </div> |
| <h3>Real-Time Neural Simulation</h3> |
| <p>Run Kuramoto oscillators, Wilson-Cowan E/I networks, Izhikevich spiking neurons, and TD-learning dopamine models with live canvas visualization.</p> |
| </div> |
| <div class="feature-card"> |
| <div class="feature-icon">π</div> |
| <h3>Mathematical Rigor</h3> |
| <p>Every model includes its governing equations rendered with KaTeX, from Kuramoto (1975) to Schultz (1997) reward prediction error.</p> |
| </div> |
| <div class="feature-card"> |
| <div class="feature-icon">β‘</div> |
| <h3>Zero Dependencies</h3> |
| <p>Single self-contained HTML file. No build step, no framework β just open and run. Deploy anywhere.</p> |
| </div> |
| </div> |
| <div class="module-list"> |
| <h2>Computational Modules</h2> |
| <div class="grid-2"> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">Kuramoto Oscillators</span><span class="card-badge badge-cyan">Synchronization</span></div> |
| <div class="math-box">${tex('d\\phi_i/dt = \\omega_i + \\frac{K}{N} \\sum_{j=1}^{N} \\sin(\\phi_j - \\phi_i)', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Coupled phase oscillators exhibiting spontaneous synchronization. The order parameter <em>r</em> quantifies coherence.</p> |
| </div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">Wilson-Cowan</span><span class="card-badge badge-green">E/I Dynamics</span></div> |
| <div class="math-box">${tex('\\tau_E \\frac{dE}{dt} = -E + S(W_{EE} \\cdot E + W_{EI} \\cdot I + I_{ext})', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Excitatory-inhibitory population dynamics with sigmoidal activation, modeling cortical microcircuits.</p> |
| </div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">Izhikevich Neuron</span><span class="card-badge badge-amber">Spiking</span></div> |
| <div class="math-box">${tex('\\frac{dv}{dt} = 0.04v^2 + 5v + 140 - u + I', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Biologically plausible spiking neuron model reproducing cortical firing patterns with two variables.</p> |
| </div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">Lyapunov Stability</span><span class="card-badge badge-red">Analysis</span></div> |
| <div class="math-box">${tex('\\lambda = \\lim_{t \\to \\infty} \\frac{1}{t} \\ln \\frac{|\\delta Z(t)|}{|\\delta Z_0|}', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Maximum Lyapunov exponent measuring chaotic sensitivity. Negative values indicate stable fixed points.</p> |
| </div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">Dopamine RPE</span><span class="card-badge badge-purple">Reinforcement</span></div> |
| <div class="math-box">${tex('\\delta = R(t) - V(t)', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Temporal difference reward prediction error model of midbrain dopaminergic signaling (Schultz, 1997).</p> |
| </div> |
| </div> |
| </div> |
| <div class="perf-grid"> |
| <div class="perf-item"><div class="perf-num">60 FPS</div><div class="perf-label">Canvas Rendering</div></div> |
| <div class="perf-item"><div class="perf-num"><1ms</div><div class="perf-label">Euler Integration</div></div> |
| <div class="perf-item"><div class="perf-num">0 B</div><div class="perf-label">External JS</div></div> |
| <div class="perf-item"><div class="perf-num">10</div><div class="perf-label">Oscillators</div></div> |
| </div> |
| <div class="footer">CortexAI Β· Neurodynamical Computing Dashboard Β· Built with KaTeX</div>`; |
| } |
| |
| function renderDashboard(){ |
| document.getElementById('topbarTitle').textContent = 'Dashboard'; |
| const tabs = ['overview','kuramoto','wilsoncowan','izhikevich','dopamine']; |
| const labels = ['Overview','Kuramoto','Wilson-Cowan','Izhikevich','Dopamine']; |
| let html = `<div class="tabs">${tabs.map((t,i)=>`<button class="tab-btn ${currentDashTab===t?'active':''}" onclick="window.__dashTab('${t}')">${labels[i]}</button>`).join('')}</div>`; |
| |
| // Overview |
| html += `<div class="tab-panel ${currentDashTab==='overview'?'active':''}" data-tab="overview"> |
| <div class="overview-grid"> |
| <div class="card"><div class="card-header"><span class="card-title">Kuramoto Oscillators</span><span class="card-badge badge-cyan">LIVE</span></div><canvas id="cv-ov-kuramoto" class="mini-panel"></canvas><div class="state-grid"><div class="state-item"><div class="state-label">Order r</div><div class="state-value" id="ov-k-r">0.00</div></div><div class="state-item"><div class="state-label">Oscillators</div><div class="state-value">${N_OSC}</div></div></div></div> |
| <div class="card"><div class="card-header"><span class="card-title">Wilson-Cowan E/I</span><span class="card-badge badge-green">LIVE</span></div><canvas id="cv-ov-wc" class="mini-panel"></canvas><div class="state-grid"><div class="state-item"><div class="state-label">E</div><div class="state-value" id="ov-wc-e">0.00</div></div><div class="state-item"><div class="state-label">I</div><div class="state-value" id="ov-wc-i">0.00</div></div></div></div> |
| <div class="card"><div class="card-header"><span class="card-title">Izhikevich Neuron</span><span class="card-badge badge-amber">LIVE</span></div><canvas id="cv-ov-iz" class="mini-panel"></canvas><div class="state-grid"><div class="state-item"><div class="state-label">Voltage</div><div class="state-value" id="ov-iz-v">-65 mV</div></div><div class="state-item"><div class="state-label">Spikes</div><div class="state-value" id="ov-iz-sp">0</div></div></div></div> |
| <div class="card"><div class="card-header"><span class="card-title">Lyapunov Exponent</span><span class="card-badge badge-red">LIVE</span></div><canvas id="cv-ov-ly" class="mini-panel"></canvas><div class="state-grid"><div class="state-item"><div class="state-label">Ξ»</div><div class="state-value" id="ov-ly-val">0.00</div></div><div class="state-item"><div class="state-label">Stability</div><div class="state-value" id="ov-ly-stab">β</div></div></div></div> |
| <div class="card" style="grid-column:span 2"><div class="card-header"><span class="card-title">Dopamine Reward Prediction</span><span class="card-badge badge-purple">LIVE</span></div><canvas id="cv-ov-da" style="height:180px"></canvas><div class="state-grid"><div class="state-item"><div class="state-label">DA Level</div><div class="state-value" id="ov-da-v">0.00</div></div><div class="state-item"><div class="state-label">RPE Ξ΄</div><div class="state-value" id="ov-da-delta">0.00</div></div><div class="state-item"><div class="state-label">Predicted</div><div class="state-value" id="ov-da-pred">0.00</div></div></div></div> |
| </div></div>`; |
| |
| // Kuramoto detail |
| html += `<div class="tab-panel ${currentDashTab==='kuramoto'?'active':''}" data-tab="kuramoto"> |
| <div class="card" style="margin-bottom:20px"> |
| <div class="card-header"><span class="card-title">Kuramoto Model β Coupled Phase Oscillators</span><span class="card-badge badge-cyan">RUNNING</span></div> |
| <div class="math-box">${tex('d\\phi_i/dt = \\omega_i + \\frac{K}{N} \\sum_{j=1}^{N} \\sin(\\phi_j - \\phi_i)', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Kuramoto, 1975. Each oscillator i has natural frequency Οα΅’ and phase Οα΅’. Coupling strength K controls synchronization onset.</p> |
| </div> |
| <div class="grid-2"> |
| <div class="card"><div class="card-header"><span class="card-title">Phase Space</span></div><canvas id="cv-kuramoto" style="height:350px"></canvas></div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">State Variables</span></div> |
| <div class="state-grid" id="k-states"> |
| <div class="state-item"><div class="state-label">Order Param r</div><div class="state-value" id="k-r">0.00</div></div> |
| <div class="state-item"><div class="state-label">Mean Phase</div><div class="state-value" id="k-mp">0.00</div></div> |
| <div class="state-item"><div class="state-label">Coupling K</div><div class="state-value">1.0</div></div> |
| <div class="state-item"><div class="state-label">N Oscillators</div><div class="state-value">${N_OSC}</div></div> |
| </div> |
| <div style="margin-top:16px"> |
| <div class="card-header"><span class="card-title">Natural Frequencies</span></div> |
| <div id="k-freqs" style="display:flex;gap:4px;flex-wrap:wrap;margin-top:8px"></div> |
| </div> |
| </div> |
| </div></div>`; |
| |
| // Wilson-Cowan detail |
| html += `<div class="tab-panel ${currentDashTab==='wilsoncowan'?'active':''}" data-tab="wilsoncowan"> |
| <div class="card" style="margin-bottom:20px"> |
| <div class="card-header"><span class="card-title">Wilson-Cowan β Excitatory/Inhibitory Dynamics</span><span class="card-badge badge-green">RUNNING</span></div> |
| <div class="math-box">${tex('\\tau_E \\frac{dE}{dt} = -E + S(W_{EE} \\cdot E + W_{EI} \\cdot I + I_{ext})', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Wilson & Cowan, 1972. Two coupled populations: excitatory (E) and inhibitory (I), with sigmoidal gain function S(x) = 1/(1+eβ»Λ£).</p> |
| </div> |
| <div class="grid-2"> |
| <div class="card"><div class="card-header"><span class="card-title">E/I Time Series</span></div><canvas id="cv-wc" style="height:350px"></canvas></div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">State Variables</span></div> |
| <div class="state-grid"> |
| <div class="state-item"><div class="state-label">E (Excitatory)</div><div class="state-value" id="wc-e">0.10</div></div> |
| <div class="state-item"><div class="state-label">I (Inhibitory)</div><div class="state-value" id="wc-i">0.10</div></div> |
| <div class="state-item"><div class="state-label">W_ee</div><div class="state-value">10</div></div> |
| <div class="state-item"><div class="state-label">W_ei</div><div class="state-value">-4</div></div> |
| <div class="state-item"><div class="state-label">W_ie</div><div class="state-value">8</div></div> |
| <div class="state-item"><div class="state-label">W_ii</div><div class="state-value">-2</div></div> |
| <div class="state-item"><div class="state-label">I_ext</div><div class="state-value">1.5</div></div> |
| <div class="state-item"><div class="state-label">Ο_E / Ο_I</div><div class="state-value">1 / 1</div></div> |
| </div> |
| </div> |
| </div></div>`; |
| |
| // Izhikevich detail |
| html += `<div class="tab-panel ${currentDashTab==='izhikevich'?'active':''}" data-tab="izhikevich"> |
| <div class="card" style="margin-bottom:20px"> |
| <div class="card-header"><span class="card-title">Izhikevich Spiking Neuron</span><span class="card-badge badge-amber">RUNNING</span></div> |
| <div class="math-box">${tex('\\frac{dv}{dt} = 0.04v^2 + 5v + 140 - u + I', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Izhikevich, 2003. A two-variable neuron model: v is membrane potential, u is recovery variable. When v β₯ 30mV, the neuron spikes and resets to (c, u+d).</p> |
| </div> |
| <div class="grid-2"> |
| <div class="card"><div class="card-header"><span class="card-title">Voltage Trace</span></div><canvas id="cv-iz" style="height:350px"></canvas></div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">State Variables</span></div> |
| <div class="state-grid"> |
| <div class="state-item"><div class="state-label">Voltage v</div><div class="state-value" id="iz-v">-65 mV</div></div> |
| <div class="state-item"><div class="state-label">Recovery u</div><div class="state-value" id="iz-u">-13.00</div></div> |
| <div class="state-item"><div class="state-label">Input I</div><div class="state-value" id="iz-i">10.0</div></div> |
| <div class="state-item"><div class="state-label">a</div><div class="state-value">0.02</div></div> |
| <div class="state-item"><div class="state-label">b</div><div class="state-value">0.2</div></div> |
| <div class="state-item"><div class="state-label">c</div><div class="state-value">-65</div></div> |
| <div class="state-item"><div class="state-label">d</div><div class="state-value">8</div></div> |
| <div class="state-item"><div class="state-label">Spikes</div><div class="state-value" id="iz-sp">0</div></div> |
| </div> |
| </div> |
| </div></div>`; |
| |
| // Dopamine detail |
| html += `<div class="tab-panel ${currentDashTab==='dopamine'?'active':''}" data-tab="dopamine"> |
| <div class="card" style="margin-bottom:20px"> |
| <div class="card-header"><span class="card-title">Dopamine Reward Prediction Error</span><span class="card-badge badge-purple">RUNNING</span></div> |
| <div class="math-box">${tex('\\delta = R(t) - V(t)', true)}</div> |
| <p style="color:var(--bg-400);font-size:.85rem;margin-top:8px">Schultz, 1997. Temporal difference learning: Ξ΄ is the reward prediction error, V(t) is the predicted value, R(t) is actual reward. Positive Ξ΄ = unexpected reward (dopamine burst). Negative Ξ΄ = reward omission (dip).</p> |
| </div> |
| <div class="grid-2"> |
| <div class="card"><div class="card-header"><span class="card-title">DA / RPE / Prediction</span></div><canvas id="cv-da" style="height:350px"></canvas></div> |
| <div class="card"> |
| <div class="card-header"><span class="card-title">State Variables</span></div> |
| <div class="state-grid"> |
| <div class="state-item"><div class="state-label">DA Level V</div><div class="state-value" id="da-v">0.00</div></div> |
| <div class="state-item"><div class="state-label">RPE Ξ΄</div><div class="state-value" id="da-delta">0.00</div></div> |
| <div class="state-item"><div class="state-label">Reward R</div><div class="state-value" id="da-r">0</div></div> |
| <div class="state-item"><div class="state-label">Ξ± (lr)</div><div class="state-value">0.1</div></div> |
| <div class="state-item"><div class="state-label">Ξ³ (discount)</div><div class="state-value">0.99</div></div> |
| </div> |
| <div style="margin-top:16px"> |
| <div class="card-header"><span class="card-title">Legend</span></div> |
| <div style="display:flex;gap:16px;margin-top:8px"> |
| <span style="display:flex;align-items:center;gap:6px;font-size:.85rem"><span style="width:12px;height:3px;background:#06b6d4;border-radius:2px"></span> DA Level</span> |
| <span style="display:flex;align-items:center;gap:6px;font-size:.85rem"><span style="width:12px;height:3px;background:#f59e0b;border-radius:2px"></span> RPE Ξ΄</span> |
| <span style="display:flex;align-items:center;gap:6px;font-size:.85rem"><span style="width:12px;height:3px;background:#a855f7;border-radius:2px"></span> Predicted V</span> |
| </div> |
| </div> |
| </div> |
| </div></div>`; |
| |
| return html; |
| } |
| |
| function renderPlayground(){ |
| document.getElementById('topbarTitle').textContent = 'Playground'; |
| return `<div class="placeholder-page"><h2>Playground</h2><p>Custom model builder and parameter tuning interface coming soon.</p><div style="margin-top:20px;padding:40px;border:2px dashed var(--bg-700);border-radius:12px;width:100%;max-width:600px"><p style="color:var(--bg-500);font-size:.9rem">Drag-and-drop model components here<br>or write custom ODEs with our DSL.</p></div></div>`; |
| } |
| |
| function renderSettings(){ |
| document.getElementById('topbarTitle').textContent = 'Settings'; |
| return `<div class="placeholder-page"><h2>Settings</h2><p>Configuration panel for simulation parameters, themes, and export options.</p><div style="margin-top:20px;text-align:left;max-width:480px;width:100%"> |
| <div class="card" style="margin-bottom:12px"><div class="card-header"><span class="card-title">Simulation</span></div><p style="color:var(--bg-400);font-size:.85rem">Time step, integration method, export data.</p></div> |
| <div class="card" style="margin-bottom:12px"><div class="card-header"><span class="card-title">Appearance</span></div><p style="color:var(--bg-400);font-size:.85rem">Theme, canvas resolution, layout preferences.</p></div> |
| <div class="card"><div class="card-header"><span class="card-title">About</span></div><p style="color:var(--bg-400);font-size:.85rem">CortexAI v0.1.0 β Neurodynamical Computing Dashboard</p></div> |
| </div></div>`; |
| } |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Main Render & Update Loop |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| function render(){ |
| const app = document.getElementById('app'); |
| switch(currentRoute){ |
| case 'dashboard': app.innerHTML = renderDashboard(); break; |
| case 'playground': app.innerHTML = renderPlayground(); break; |
| case 'settings': app.innerHTML = renderSettings(); break; |
| default: app.innerHTML = renderHome(); |
| } |
| renderMath(app); |
| updateCanvases(); |
| updateStateValues(); |
| } |
| |
| function updateCanvases(){ |
| renderKuramotoCanvas(document.getElementById('cv-kuramoto')); |
| renderKuramotoCanvas(document.getElementById('cv-ov-kuramoto')); |
| renderWilsonCowanCanvas(document.getElementById('cv-wc')); |
| renderWilsonCowanCanvas(document.getElementById('cv-ov-wc')); |
| renderIzhikevichCanvas(document.getElementById('cv-iz')); |
| renderIzhikevichCanvas(document.getElementById('cv-ov-iz')); |
| renderLyapunovGauge(document.getElementById('cv-ov-ly')); |
| renderDopamineCanvas(document.getElementById('cv-da')); |
| renderDopamineCanvas(document.getElementById('cv-ov-da')); |
| } |
| |
| function updateStateValues(){ |
| const k = sim.kuramoto, wc = sim.wilsonCowan, iz = sim.izhikevich, ly = sim.lyapunov, d = sim.dopamine; |
| const set = (id,v)=>{ const el=document.getElementById(id); if(el) el.textContent=v; }; |
| set('k-r', k.r.toFixed(3)); set('ov-k-r', k.r.toFixed(3)); |
| set('k-mp', (k.meanPhase*180/Math.PI).toFixed(1)+'Β°'); |
| set('wc-e', wc.E.toFixed(4)); set('wc-i', wc.I.toFixed(4)); |
| set('ov-wc-e', wc.E.toFixed(3)); set('ov-wc-i', wc.I.toFixed(3)); |
| set('iz-v', iz.v.toFixed(1)+' mV'); set('iz-u', iz.u.toFixed(2)); |
| set('iz-i', iz.I.toFixed(1)); set('iz-sp', iz.spikes.length); |
| set('ov-iz-v', iz.v.toFixed(1)+' mV'); set('ov-iz-sp', iz.spikes.length); |
| set('ly-val', ly.value.toFixed(3)); set('ov-ly-val', ly.value.toFixed(3)); |
| set('ov-ly-stab', ly.value < 0 ? 'Stable' : ly.value > 0 ? 'Chaotic' : 'Marginal'); |
| set('da-v', d.V.toFixed(4)); set('da-delta', d.delta.toFixed(4)); set('da-r', d.R>0?'1':'0'); |
| set('ov-da-v', d.V.toFixed(3)); set('ov-da-delta', d.delta.toFixed(3)); set('ov-da-pred', d.V.toFixed(3)); |
| // Kuramoto frequencies |
| const freqEl = document.getElementById('k-freqs'); |
| if(freqEl && !freqEl.children.length){ |
| freqEl.innerHTML = k.omega.map((w,i)=>`<span style="background:var(--bg-800);padding:2px 8px;border-radius:4px;font-size:.75rem;color:${CANVAS_COLORS[i%CANVAS_COLORS.length]}">Ο${i+1}=${w.toFixed(2)}</span>`).join(''); |
| } |
| } |
| |
| /* Tab switching */ |
| window.__dashTab = function(tab){ |
| currentDashTab = tab; |
| render(); |
| }; |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Animation Loop |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| let frameCount = 0; |
| function loop(){ |
| stepAll(); |
| frameCount++; |
| if(frameCount%2===0) updateCanvases(); |
| if(frameCount%3===0) updateStateValues(); |
| requestAnimationFrame(loop); |
| } |
| |
| /* βββββββββββββββββββββββββββββββββββββββββββ |
| Init |
| βββββββββββββββββββββββββββββββββββββββββββ */ |
| function init(){ |
| // handle initial route |
| const path = location.pathname.replace('/','') || 'home'; |
| navigate(path, false); |
| // start simulation |
| loop(); |
| } |
| |
| // KaTeX load callback |
| function waitForKatex(){ |
| if(window.katex) { init(); return; } |
| setTimeout(waitForKatex, 50); |
| } |
| if(document.readyState === 'loading'){ |
| document.addEventListener('DOMContentLoaded', waitForKatex); |
| } else { |
| waitForKatex(); |
| } |
| |
| })(); |
| </script> |
| </body> |
| </html> |
|
|