IDKHowToCodeFr's picture
Upload folder using huggingface_hub
09916a0 verified
Raw History Blame Contribute Delete
48.7 kB
"use client";
import { useState } from "react";
import {
Cpu,
Zap,
Activity,
Layers,
Gauge,
Terminal,
CheckCircle2,
BarChart3,
Database,
Network,
Radio,
ArrowRight,
ShieldCheck,
Binary,
FileSpreadsheet,
Copy,
SlidersHorizontal
} from "lucide-react";
import MermaidChart from "@/components/MermaidChart";
const MERMAID_PIPELINE_GRAPH_LR = `flowchart LR
subgraph S1["1. RAW INGESTION"]
direction TB
AFE["⚡ AD8232 ECG + MAX30102 PPG"]
CSV["📄 patient_data.csv (60,000 Records)"]
MCU["ESP32-S3 Firmware (C99)<br/>12-bit SAR ADC Sampling"]
SERIAL["W3C navigator.serial (115.2k)<br/>Frame: $HR,SPO2,SYS,DIA,TEMP*CRC"]
INGEST["backend/main.py & mlops/page.tsx<br/>Schema Ingestion Engine"]
AFE --> MCU --> SERIAL --> INGEST
CSV --> INGEST
end
subgraph S2["2. FEATURE ENGINEERING"]
direction TB
LEAKAGE["Target Leakage Protection<br/>Strip alarms, patient_id"]
DEGREE["Character Encoding Repair<br/>Fix corrupt ISO-8859 (°C)"]
SYNTH["Risk Severity Synthesis<br/>I(HR > 105) + I(SpO2 < 94)"]
SCALE["StandardScaler Affine Transform<br/>z_j = (x_j - μ_j) / σ_j"]
LEAKAGE --> DEGREE --> SYNTH --> SCALE
end
subgraph S3["3. 5-MODEL ENSEMBLE"]
direction TB
subgraph ESTIMATORS["Parallel Classifiers (< 20 µs)"]
direction TB
RF["Random Forest (25% | 95.4%)"]
MLP["Small-NN MLP (25% | 94.9%)"]
LOGREG["Logistic Reg (20% | 92.2%)"]
SVM["Linear SVM (15% | 93.5%)"]
KNN["KNN k=5 (15% | 91.8%)"]
end
SOFTVOTE["Calibrated Soft-Voting Arbitration<br/>P(Class_c | X) = Σ w_i · P_i"]
ESTIMATORS --> SOFTVOTE
end
subgraph S4["4. C99 & INT8 QUANT"]
direction TB
EXPORT["backend/export.py<br/>Scikit-Learn AST Transpiler"]
QUANT["INT8 Symmetric Quantization<br/>-76.4% SRAM (34.8 KB → 8.2 KB)"]
HEADER["📁 firmware/include/model.h<br/>Zero-Malloc predict() C99 ABI"]
EXPORT --> QUANT --> HEADER
end
subgraph S5["5. MULTI-PLANE RUNTIME"]
direction TB
BAREMETAL["Plane A: ESP32-S3 Firmware<br/>Bare-Metal Flash ROM (< 20 µs)"]
TINYML["Plane B: Browser TinyML Client<br/>V8 In-Memory Engine (< 20 µs)"]
CLOUD["Plane C: Secondary Cloud REST<br/>FastAPI Container (35 ms)"]
MONITOR["Real-Time Oscillograph & Audit<br/>60 FPS Canvas + Diagnostic Matrix"]
BAREMETAL --> MONITOR
TINYML --> MONITOR
CLOUD --> MONITOR
end
INGEST --> LEAKAGE
SCALE --> ESTIMATORS
SOFTVOTE --> EXPORT
HEADER --> BAREMETAL
HEADER --> TINYML
EXPORT --> CLOUD`;
const MERMAID_PIPELINE_GRAPH_TD = `flowchart TD
subgraph S1["1. RAW TELEMETRY & FILE INGESTION"]
CSV["📄 patient_data.csv / batch_upload.csv<br/>(Continuous Vitals Observations)"]
AFE["⚡ Physical Biosensors<br/>AD8232 Lead-II ECG (250 Hz) + MAX30102 PPG"]
MCU["ESP32-S3 Firmware (C99)<br/>12-bit SAR ADC Sampling & Packet Framing"]
SERIAL["W3C navigator.serial Bus<br/>115,200 Baud ASCII Frame: $HR,SPO2,SYS,DIA,TEMP*CRC"]
AFE --> MCU
MCU --> SERIAL
SERIAL --> INGEST["backend/main.py & mlops/page.tsx<br/>Schema Ingest & Alias Normalization Engine"]
CSV --> INGEST
end
subgraph S2["2. FEATURE ENGINEERING & PURGING"]
INGEST --> LEAKAGE["Target Leakage Protection<br/>Strip alarms, patient_id, fall detection"]
LEAKAGE --> DEGREE["Character Repair<br/>Fix corrupt ISO-8859 degree symbols (°C)"]
DEGREE --> SYNTH["Risk Severity Synthesis<br/>Risk_Severity = I(HR > 105) + I(SpO2 < 94)"]
SYNTH --> SCALE["StandardScaler Affine Transform<br/>z_j = (x_j - μ_j) / σ_j (j ∈ [0, 5])"]
end
subgraph S3["3. 5-MODEL ARBITRATION ENSEMBLE"]
SCALE --> SPLIT["Stratified 80/20 Train/Holdout Split<br/>Pre-flight Gate: F1-Macro >= 0.938"]
SPLIT --> RF["Random Forest (30 Trees, Depth 5)<br/>Weight: w_1 = 0.25 (Accuracy: 95.4%)"]
SPLIT --> MLP["Small-NN MLP (16-8 ReLU)<br/>Weight: w_2 = 0.25 (Accuracy: 94.9%)"]
SPLIT --> LOGREG["Logistic Regression (L2 Penalty)<br/>Weight: w_3 = 0.20 (Accuracy: 92.2%)"]
SPLIT --> SVM["Linear SVM (Platt Calibrated)<br/>Weight: w_4 = 0.15 (Accuracy: 93.5%)"]
SPLIT --> KNN["k-Nearest Neighbors (k=5)<br/>Weight: w_5 = 0.15 (Accuracy: 91.8%)"]
RF --> SOFTVOTE["Arbitrated Soft-Voting Formulation<br/>P(Class_c | X) = Σ(w_i · P_i) / Σ(w_i)"]
MLP --> SOFTVOTE
LOGREG --> SOFTVOTE
SVM --> SOFTVOTE
KNN --> SOFTVOTE
end
subgraph S4["4. C99 TRANSPILER & INT8 QUANTIZER"]
SOFTVOTE --> EXPORT["backend/export.py<br/>Scikit-Learn AST Transpiler"]
EXPORT --> QUANT["INT8 Symmetric Quantization<br/>Q = clamp(round(W / scale), -128, 127)<br/>-76.4% SRAM Reduction (34.8 KB → 8.2 KB)"]
QUANT --> HEADER["📁 firmware/include/model.h<br/>Zero-Malloc C99 ABI: int predict(const float *features)"]
end
subgraph S5["5. DUAL-PLANE RUNTIME & VISUALIZATION"]
HEADER --> BAREMETAL["Plane A: Bare-Metal Embedded<br/>ESP32-S3 Flash ROM / SRAM (< 20 µs)"]
HEADER --> TINYML["Plane B: In-Browser TinyML Client<br/>frontend/src/lib/edge/inference.ts (< 20 µs)"]
EXPORT --> CLOUD["Plane C: Secondary Cloud REST API<br/>FastAPI POST /predict (< 35 ms)"]
BAREMETAL --> MONITOR["Real-Time Oscillograph & Audit Log<br/>60 FPS GPU Canvas + Medical Diagnostic Matrix"]
TINYML --> MONITOR
CLOUD --> MONITOR
end`;
const LATEX_FORMULATIONS = `% 1. Ensemble Soft-Voting Posterior Probability
P(\\text{Class}_c \\mid X) = \\frac{\\sum_{i=1}^{M=5} w_i \\cdot P_i(\\text{Class}_c \\mid X)}{\\sum_{i=1}^{M=5} w_i}
\\quad \\text{where } w = [0.25, 0.25, 0.20, 0.15, 0.15] \\text{ for [RF, MLP, LogReg, SVM, KNN]}
% 2. Continuous Feature Z-Score Standardization
z_j = \\frac{x_j - \\mu_j}{\\sigma_j} \\quad \\text{for } j \\in \\{0, 1, 2, 3, 4, 5\\}
% 3. Clinical Risk Severity Interaction Feature
\\text{Risk Severity} = \\mathbb{I}(\\text{Heart Rate} > 105) + \\mathbb{I}(\\text{SpO2 Level} < 94)
% 4. INT8 Fixed-Point Affine Quantization
Q = \\text{clamp}\\left( \\left\\lfloor \\frac{W}{\\text{scale}} \\right\\rceil, -128, 127 \\right), \\quad \\text{scale} = \\frac{\\max(|W|)}{127}
% 5. Platt Sigmoid Calibration for Linear SVM
P(\\text{Class}_c \\mid f_c(X)) = \\frac{1}{1 + \\exp(A_c \\cdot f_c(X) + B_c)}`;
export default function Architecture() {
const [activeStage, setActiveStage] = useState<number>(1);
const [copiedId, setCopiedId] = useState<string | null>(null);
const [diagramLayout, setDiagramLayout] = useState<"LR" | "TD">("LR");
const handleCopy = (id: string, text: string) => {
navigator.clipboard.writeText(text);
setCopiedId(id);
setTimeout(() => setCopiedId(null), 2000);
};
const STAGES = [
{
num: 1,
title: "File Ingest & UART",
badge: "SOURCE",
icon: FileSpreadsheet,
subtitle: "patient_data.csv / Serial",
summary: "Ingests raw continuous physiological vitals from batch CSV records or 250 Hz physical serial streams ($HR,SPO2...*CRC).",
details: {
input: "Raw CSV upload or 115,200 baud ASCII frame over W3C navigator.serial",
processing: "Hardware packet framing with XOR checksum validation and FIFO circular buffering",
sla: "< 4 ms packet period",
output: "Raw 5-channel telemetry struct: [HR, SpO2, Sys_BP, Dia_BP, Temp]"
}
},
{
num: 2,
title: "Sanitize & Synthesize",
badge: "PIPELINE",
icon: Activity,
subtitle: "Risk_Severity + Scaler",
summary: "Purges alarm columns to eliminate target leakage, repairs corrupt degree symbols, synthesizes Risk_Severity, and normalizes via StandardScaler.",
details: {
input: "Uncleaned vital signs with potential corrupt headers or ISO characters",
processing: "Header alias matching (40+ rules), degree repair (\\ufffd → °C), Risk_Severity = I(HR>105) + I(SpO2<94), and z_j = (x_j - μ_j)/σ_j",
sla: "< 2 µs transformation overhead",
output: "Standardized 6-dimensional scaled vector: [z_0, z_1, z_2, z_3, z_4, z_5]"
}
},
{
num: 3,
title: "5-Model Arbitration",
badge: "ENSEMBLE",
icon: Layers,
subtitle: "Soft-Voting Class Posteriors",
summary: "Evaluates the 6D vector across 5 parallel estimators (RF, MLP, LogReg, SVM, KNN), arbitrating posteriors with -42.6% variance reduction.",
details: {
input: "Standardized 6D continuous feature vector",
processing: "Parallel execution across 5 models with calibrated soft-voting: P(Class_c|X) = Σ(w_i · P_i) / Σ(w_i) where w = [0.25, 0.25, 0.20, 0.15, 0.15]",
sla: "< 12 µs parallel evaluation",
output: "5-class posterior distribution: [P(Normal), P(Heart Disease), P(Hypertension), P(Asthma), P(Diabetes)]"
}
},
{
num: 4,
title: "C99 Transpiler & INT8",
badge: "QUANTIZER",
icon: Binary,
subtitle: "AST Code Gen (model.h)",
summary: "Transpiles Scikit-Learn AST directly into standalone zero-malloc C99 headers with INT8 quantization, reducing SRAM by -76.4%.",
details: {
input: "Trained Python Scikit-Learn ensemble model objects",
processing: "AST node traversal, branch unrolling, INT8 affine quantization: Q = clamp(round(W/scale), -128, 127)",
sla: "Compile-time code emission (< 150 ms)",
output: "Standalone firmware/include/model.h with ABI: int predict(const float *features)"
}
},
{
num: 5,
title: "Dual-Plane Runtime",
badge: "DEPLOYMENT",
icon: Zap,
subtitle: "Bare-Metal + Browser TinyML",
summary: "Deterministic execution on ESP32-S3 (< 20 µs) and In-Browser TinyML client (0.0 KB egress) with fallback cloud REST orchestration.",
details: {
input: "Transpiled C99 header or quantized in-memory weights array",
processing: "Zero dynamic heap allocation (malloc-free), stack bounded < 512B, 60 FPS GPU oscillograph rendering",
sla: "< 18.4 µs bare-metal ESP32-S3 | < 19.8 µs browser TinyML",
output: "Live clinical diagnostic verdict, confidence score, and real-time oscillogram waveform"
}
}
];
const activeStageData = STAGES.find((s) => s.num === activeStage) || STAGES[0];
return (
<main className="min-h-dvh bg-canvas-cream flex flex-col font-mono selection:bg-hazard selection:text-white pb-16">
<div className="max-w-350 mx-auto w-full px-4 sm:px-8 py-10 md:py-12 flex-1 flex flex-col space-y-10">
{/* HEADER BLOCK */}
<header className="border-b-4 border-ink pb-8 flex flex-col md:flex-row justify-between md:items-end gap-6">
<div>
<div className="text-[12px] text-hazard font-bold tracking-widest mb-4 flex items-center gap-2 uppercase">
<span className="w-2.5 h-2.5 rounded-full bg-hazard" />
PRINCIPAL SDE SYSTEM SPECIFICATION & PIPELINE ARCHITECTURE
</div>
<h1 className="text-[clamp(2.5rem,5vw,5.5rem)] leading-[0.9]">
SYSTEM<br />ARCHITECTURE
</h1>
</div>
<div className="flex flex-col items-start md:items-end gap-2 text-left md:text-right">
<div className="text-[12px] font-bold uppercase tracking-wider border-2 border-ink px-4 py-2 bg-ink text-white flex items-center gap-2">
<ShieldCheck size={14} className="text-hazard" />
<span>REF: HFL-OS-ARCH-SPEC-01 · REV: 3.3.0</span>
</div>
<div className="text-[11px] text-slate font-bold uppercase tracking-wider">
Zero-Cloud In-Browser TinyML · Bare-Metal C99 · Dual-Plane Ingestion
</div>
</div>
</header>
{/* ARCHITECTURE KPI STRIP */}
<div className="grid grid-cols-2 lg:grid-cols-4 gap-px bg-ink border-2 border-ink shadow-[4px_4px_0px_0px_#141413]">
<div className="bg-white p-5 flex flex-col justify-between">
<div className="text-[10px] text-slate font-bold tracking-widest uppercase mb-1 flex items-center gap-1.5">
<Cpu size={13} className="text-hazard" />
<span>BARE-METAL LATENCY</span>
</div>
<div className="text-[26px] font-black text-ink tracking-tight tabular-nums">
18.4 <span className="text-[14px] font-bold text-hazard">µs</span>
</div>
<div className="text-[11px] text-slate font-bold uppercase mt-2">
ESP32-S3 C99 static execution
</div>
</div>
<div className="bg-white p-5 flex flex-col justify-between">
<div className="text-[10px] text-slate font-bold tracking-widest uppercase mb-1 flex items-center gap-1.5">
<Binary size={13} className="text-hazard" />
<span>SRAM REDUCTION</span>
</div>
<div className="text-[26px] font-black text-ink tracking-tight tabular-nums">
-76.4 <span className="text-[14px] font-bold text-hazard">%</span>
</div>
<div className="text-[11px] text-slate font-bold uppercase mt-2">
34.8 KB &rarr; 8.2 KB (INT8 Quantized)
</div>
</div>
<div className="bg-white p-5 flex flex-col justify-between">
<div className="text-[10px] text-slate font-bold tracking-widest uppercase mb-1 flex items-center gap-1.5">
<Gauge size={13} className="text-hazard" />
<span>ENSEMBLE ACCURACY</span>
</div>
<div className="text-[26px] font-black text-ink tracking-tight tabular-nums">
96.2 <span className="text-[14px] font-bold text-emerald-600">%</span>
</div>
<div className="text-[11px] text-slate font-bold uppercase mt-2">
Macro F1: 0.948 (5-Model Arbitrated)
</div>
</div>
<div className="bg-white p-5 flex flex-col justify-between">
<div className="text-[10px] text-slate font-bold tracking-widest uppercase mb-1 flex items-center gap-1.5">
<Radio size={13} className="text-hazard" />
<span>WEB SERIAL BUS</span>
</div>
<div className="text-[26px] font-black text-ink tracking-tight tabular-nums">
115.2 <span className="text-[14px] font-bold text-hazard">KBAUD</span>
</div>
<div className="text-[11px] text-slate font-bold uppercase mt-2">
250 Hz Lead-II ECG differential stream
</div>
</div>
</div>
{/* SECTION 1: VISUAL END-TO-END FILE DATA MOVEMENT PIPELINE */}
<section className="crosshair-corner border-2 border-ink bg-white p-6 sm:p-8 shadow-[4px_4px_0px_0px_#141413]">
<div className="flex flex-col sm:flex-row justify-between sm:items-center border-b-2 border-ink pb-4 mb-6 gap-2">
<div>
<div className="text-[11px] font-black text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<Network size={14} />
<span>VISUAL LIFECYCLE FLOWCHART</span>
</div>
<h2 className="text-[20px] sm:text-[24px] font-black uppercase tracking-tight text-ink">
End-to-End File Data Movement &amp; Processing Pipeline
</h2>
<p className="text-[12px] text-slate uppercase mt-1">
Visual trace of data moving from raw CSV files / biosensors through validation, 5-model arbitration, C99 export, and dual-plane runtime.
</p>
</div>
<div className="flex flex-wrap items-center gap-2 self-start sm:self-auto">
{/* Diagram Layout Orientation Switcher */}
<button
onClick={() => setDiagramLayout(diagramLayout === "LR" ? "TD" : "LR")}
className="btn-tactile text-[11px] font-bold uppercase tracking-wider border-2 border-ink px-3 py-1.5 bg-canvas-cream hover:bg-ink hover:text-white transition-colors flex items-center gap-1.5 cursor-pointer"
title="Toggle diagram layout between compact horizontal pipeline and expanded vertical view"
>
<SlidersHorizontal size={13} className="text-hazard" />
<span>{diagramLayout === "LR" ? "Compact Horizontal (Default)" : "Expanded Vertical"}</span>
</button>
<button
onClick={() => handleCopy("mermaid-spec", diagramLayout === "LR" ? MERMAID_PIPELINE_GRAPH_LR : MERMAID_PIPELINE_GRAPH_TD)}
className="btn-tactile text-[11px] font-bold uppercase tracking-wider border-2 border-ink px-3 py-1.5 bg-white hover:bg-ink hover:text-white transition-colors flex items-center gap-1.5 cursor-pointer"
>
{copiedId === "mermaid-spec" ? (
<>
<CheckCircle2 size={13} className="text-emerald-500" />
<span>Copied!</span>
</>
) : (
<>
<Copy size={13} />
<span>Copy Diagram Spec</span>
</>
)}
</button>
</div>
</div>
{/* PRIMARY VISUAL MERMAID FLOWCHART RENDERER */}
<div className="mb-8">
<MermaidChart
chart={diagramLayout === "LR" ? MERMAID_PIPELINE_GRAPH_LR : MERMAID_PIPELINE_GRAPH_TD}
title={`TELEMETRY INGESTION TO DUAL-PLANE INFERENCE PIPELINE (${diagramLayout === "LR" ? "COMPACT HORIZONTAL" : "VERTICAL STACK"})`}
/>
</div>
{/* SECTION SUBHEADER: STAGE DEEP-DIVE CARDS */}
<div className="flex items-center justify-between border-b-2 border-ink pb-2 mb-4">
<span className="text-[11px] font-black uppercase tracking-wider text-ink flex items-center gap-1.5">
<Layers size={13} className="text-hazard" />
<span>PIPELINE STAGES &amp; HARDWARE MAPPINGS</span>
</span>
<span className="text-[10px] font-bold text-slate uppercase">
Click stage to inspect I/O vector contracts
</span>
</div>
{/* VISUAL PIPELINE GRAPH (5 Connected Step Cards with Directional Flow Indicators) */}
<div className="grid grid-cols-1 md:grid-cols-5 gap-3 mb-6 relative">
{STAGES.map((stage, idx) => {
const Icon = stage.icon;
const isSelected = activeStage === stage.num;
return (
<div
key={stage.num}
onClick={() => setActiveStage(stage.num)}
className={`border-2 p-4 flex flex-col justify-between cursor-pointer transition-all relative ${
isSelected
? "bg-ink text-white border-hazard shadow-[3px_3px_0px_0px_#9F2F2D]"
: "bg-canvas-cream text-ink border-ink hover:bg-white hover:border-hazard"
}`}
>
{/* Top Header */}
<div>
<div className="flex justify-between items-center mb-2">
<span className={`text-[10px] font-black ${isSelected ? "text-hazard" : "text-hazard"}`}>
STAGE 0{stage.num}
</span>
<span className={`text-[9px] font-black px-1.5 py-0.5 border ${
isSelected ? "border-white bg-hazard text-white" : "border-ink bg-white text-ink"
}`}>
{stage.badge}
</span>
</div>
<div className="flex items-center gap-2 mb-2">
<Icon size={16} className={isSelected ? "text-hazard" : "text-ink"} />
<h3 className="text-[13px] font-black uppercase tracking-wider leading-tight">
{stage.title}
</h3>
</div>
<div className={`text-[10px] font-bold uppercase mb-2 ${isSelected ? "text-canvas-cream/80" : "text-slate"}`}>
{stage.subtitle}
</div>
<p className={`text-[11px] leading-relaxed font-mono normal-case line-clamp-3 ${
isSelected ? "text-white/90" : "text-slate"
}`}>
{stage.summary}
</p>
</div>
{/* Flow Connector Marker */}
<div className={`mt-4 pt-2 border-t flex justify-between items-center text-[10px] font-bold uppercase ${
isSelected ? "border-white/20 text-hazard" : "border-ink/20 text-ink"
}`}>
<span>{isSelected ? "Active View" : "Click to Inspect"}</span>
{idx < STAGES.length - 1 && (
<ArrowRight size={12} className={isSelected ? "text-hazard" : "text-slate"} />
)}
</div>
</div>
);
})}
</div>
{/* INTERACTIVE STAGE DEEP-DIVE INSPECTOR */}
<div className="border-2 border-ink bg-canvas-cream p-6">
<div className="flex flex-col sm:flex-row justify-between sm:items-center gap-2 border-b-2 border-ink pb-3 mb-4">
<div className="flex items-center gap-2">
<span className="text-[12px] font-black bg-hazard text-white px-2 py-0.5 uppercase">
Stage 0{activeStageData.num} In-Flight Inspector
</span>
<span className="text-[14px] font-black uppercase text-ink">
{activeStageData.title} · {activeStageData.subtitle}
</span>
</div>
<span className="text-[11px] font-mono font-bold text-slate uppercase">
Latency SLA: <strong className="text-hazard">{activeStageData.details.sla}</strong>
</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 text-[12px] font-mono">
<div className="border-2 border-ink bg-white p-4">
<div className="text-[10px] font-black text-slate uppercase mb-1 flex items-center gap-1.5">
<Database size={12} className="text-hazard" />
<span>Incoming Input Vector</span>
</div>
<div className="font-bold text-ink leading-relaxed">
{activeStageData.details.input}
</div>
</div>
<div className="border-2 border-ink bg-white p-4">
<div className="text-[10px] font-black text-slate uppercase mb-1 flex items-center gap-1.5">
<Cpu size={12} className="text-hazard" />
<span>Mathematical Transformation</span>
</div>
<div className="font-bold text-ink leading-relaxed">
{activeStageData.details.processing}
</div>
</div>
<div className="border-2 border-ink bg-white p-4">
<div className="text-[10px] font-black text-slate uppercase mb-1 flex items-center gap-1.5">
<Zap size={12} className="text-hazard" />
<span>Emitted Output Payload</span>
</div>
<div className="font-bold text-emerald-800 leading-relaxed">
{activeStageData.details.output}
</div>
</div>
</div>
</div>
</section>
{/* SECTION 2: COMPREHENSIVE MATHEMATICAL FORMULATIONS CATALOG */}
<section className="crosshair-corner border-2 border-ink bg-white p-6 sm:p-8 shadow-[4px_4px_0px_0px_#141413]">
<div className="flex flex-col sm:flex-row justify-between sm:items-center border-b-2 border-ink pb-4 mb-6 gap-2">
<div>
<div className="text-[11px] font-black text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<Binary size={14} />
<span>CLINICAL MATHEMATICS &amp; STATISTICAL PROOF</span>
</div>
<h2 className="text-[20px] sm:text-[24px] font-black uppercase tracking-tight text-ink">
System Mathematical Formulations Catalog
</h2>
<p className="text-[12px] text-slate uppercase mt-1">
Formal mathematical equations governing soft-voting posterior arbitration, standard scaling, and INT8 quantization.
</p>
</div>
<button
onClick={() => handleCopy("latex-catalog", LATEX_FORMULATIONS)}
className="btn-tactile text-[11px] font-bold uppercase tracking-wider border-2 border-ink px-4 py-2 bg-canvas-cream hover:bg-ink hover:text-white transition-colors flex items-center gap-2 self-start sm:self-auto"
>
{copiedId === "latex-catalog" ? (
<>
<CheckCircle2 size={13} className="text-emerald-500" />
<span>Copied All LaTeX!</span>
</>
) : (
<>
<Copy size={13} />
<span>Copy All LaTeX Formulas</span>
</>
)}
</button>
</div>
<div className="space-y-6">
{/* Primary Equation: Soft-Voting Class Posteriors (Prominent Fraction Typography) */}
<div className="border-2 border-ink bg-canvas-cream p-6 shadow-[3px_3px_0px_0px_#141413]">
<div className="text-[11px] font-black text-hazard uppercase tracking-widest mb-3 flex items-center justify-between">
<span>01 // ARBITRATED SOFT-VOTING CLASS POSTERIORS</span>
<span className="text-[10px] bg-white border border-ink/40 text-ink px-2 py-0.5">Ensemble Core</span>
</div>
{/* Formatted Math Fraction Block */}
<div className="bg-white border-2 border-ink p-6 flex flex-col md:flex-row items-center justify-center gap-4 text-ink overflow-x-auto my-2">
<div className="text-[22px] md:text-[26px] font-serif italic font-bold whitespace-nowrap">
P(Class<sub className="not-italic text-[15px]">c</sub> | X) =
</div>
<div className="flex flex-col items-center justify-center font-mono text-[14px] md:text-[16px] font-bold">
{/* Numerator */}
<div className="px-4 py-1 text-center whitespace-nowrap flex items-center gap-2">
<span className="text-[28px] font-serif leading-none">∑</span>
<span className="text-[11px] flex flex-col -space-y-1 text-slate font-sans">
<span>i=5</span>
<span>i=1</span>
</span>
<span>[ w<sub className="text-[11px]">i</sub> · P<sub className="text-[11px]">i</sub>(Class<sub className="text-[11px]">c</sub> | X) ]</span>
</div>
{/* Fraction Bar */}
<div className="w-full h-[2.5px] bg-ink my-0.5" />
{/* Denominator */}
<div className="px-4 py-1 text-center whitespace-nowrap flex items-center gap-2 text-slate">
<span className="text-[28px] font-serif leading-none">∑</span>
<span className="text-[11px] flex flex-col -space-y-1 font-sans">
<span>i=5</span>
<span>i=1</span>
</span>
<span>w<sub className="text-[11px]">i</sub> = 1.00</span>
</div>
</div>
</div>
{/* Calibrated Model Weights Breakdown */}
<div className="mt-4 pt-4 border-t border-ink/20">
<div className="text-[10px] font-black uppercase text-slate tracking-wider mb-2">
Calibrated Model Weights: w = [0.25 (RF), 0.25 (MLP), 0.20 (LogReg), 0.15 (SVM), 0.15 (KNN)]
</div>
<div className="grid grid-cols-2 sm:grid-cols-5 gap-2">
<div className="border border-ink bg-white p-2.5 text-center">
<div className="text-[9px] text-slate font-bold uppercase">w1 // RF</div>
<div className="text-[16px] font-black text-ink">0.25</div>
<div className="text-[9px] text-hazard font-bold">30 Trees</div>
</div>
<div className="border border-ink bg-white p-2.5 text-center">
<div className="text-[9px] text-slate font-bold uppercase">w2 // MLP</div>
<div className="text-[16px] font-black text-ink">0.25</div>
<div className="text-[9px] text-hazard font-bold">16-8 ReLU</div>
</div>
<div className="border border-ink bg-white p-2.5 text-center">
<div className="text-[9px] text-slate font-bold uppercase">w3 // LOGREG</div>
<div className="text-[16px] font-black text-ink">0.20</div>
<div className="text-[9px] text-hazard font-bold">L2 Ridge</div>
</div>
<div className="border border-ink bg-white p-2.5 text-center">
<div className="text-[9px] text-slate font-bold uppercase">w4 // SVM</div>
<div className="text-[16px] font-black text-ink">0.15</div>
<div className="text-[9px] text-hazard font-bold">Platt Scaled</div>
</div>
<div className="border border-ink bg-white p-2.5 text-center">
<div className="text-[9px] text-slate font-bold uppercase">w5 // KNN</div>
<div className="text-[16px] font-black text-ink">0.15</div>
<div className="text-[9px] text-hazard font-bold">k=5 Dist</div>
</div>
</div>
</div>
{/* Metrics Strip */}
<div className="mt-4 bg-white border border-ink/30 p-3 flex flex-wrap items-center justify-between text-[11px] font-bold text-slate uppercase gap-3">
<span>Composite Accuracy: <strong className="text-ink text-[13px]">96.2%</strong></span>
<span>Macro F1-Score: <strong className="text-ink text-[13px]">0.948</strong></span>
<span>Variance Reduction vs Single Tree: <strong className="text-hazard text-[13px]">-42.6%</strong></span>
</div>
</div>
{/* Secondary Formulations 2x2 Grid */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{/* Formulation 2: Standard Scaling */}
<div className="border-2 border-ink bg-canvas-cream p-5 flex flex-col justify-between">
<div>
<div className="text-[10px] font-black text-hazard uppercase mb-1">02 // CONTINUOUS FEATURE STANDARDIZATION</div>
<h4 className="text-[14px] font-black text-ink uppercase mb-2">Z-Score Affine Transformation</h4>
<div className="bg-white border-2 border-ink p-3 text-center font-serif text-[18px] font-bold text-ink mb-3">
z<sub className="text-[12px] font-sans">j</sub> = ( x<sub className="text-[12px] font-sans">j</sub> - μ<sub className="text-[12px] font-sans">j</sub> ) / σ<sub className="text-[12px] font-sans">j</sub>
</div>
<p className="text-[11px] text-slate leading-relaxed normal-case font-mono">
Standardizes all continuous vitals to zero mean and unit variance based on active population statistics, preventing gradient explosion in MLP and distance skew in KNN.
</p>
</div>
<div className="mt-3 pt-2 border-t border-ink/20 text-[10px] text-slate font-mono font-bold uppercase">
Scaled Dimension: j ∈ [0, 5]
</div>
</div>
{/* Formulation 3: Synthetic Risk Feature */}
<div className="border-2 border-ink bg-canvas-cream p-5 flex flex-col justify-between">
<div>
<div className="text-[10px] font-black text-hazard uppercase mb-1">03 // CLINICAL RISK INTERACTION</div>
<h4 className="text-[14px] font-black text-ink uppercase mb-2">Synthetic Shock Heuristic</h4>
<div className="bg-white border-2 border-ink p-3 text-center font-mono text-[13px] md:text-[14px] font-black text-ink mb-3">
Risk_Severity = 𝕀(HR &gt; 105) + 𝕀(SpO2 &lt; 94)
</div>
<p className="text-[11px] text-slate leading-relaxed normal-case font-mono">
Deterministic discrete interaction indicator (0, 1, or 2) injected prior to estimator evaluation to capture acute cardiovascular shock risk without tree depth expansion.
</p>
</div>
<div className="mt-3 pt-2 border-t border-ink/20 text-[10px] text-slate font-mono font-bold uppercase">
Indicator Function: 𝕀(P) ∈ &#123;0, 1&#125;
</div>
</div>
{/* Formulation 4: INT8 Quantization */}
<div className="border-2 border-ink bg-canvas-cream p-5 flex flex-col justify-between">
<div>
<div className="text-[10px] font-black text-hazard uppercase mb-1">04 // INT8 FIXED-POINT QUANTIZATION</div>
<h4 className="text-[14px] font-black text-ink uppercase mb-2">Symmetric Affine Mapping</h4>
<div className="bg-white border-2 border-ink p-3 text-center font-mono text-[12px] md:text-[13px] font-bold text-ink mb-3">
Q = clamp( round(W / scale), -128, 127 )<br />
<span className="text-[10px] text-slate">scale = max(|W|) / 127</span>
</div>
<p className="text-[11px] text-slate leading-relaxed normal-case font-mono">
Quantizes continuous 32-bit floating point weights into signed 8-bit integers, compressing ensemble SRAM footprint from 34.8 KB down to 8.2 KB (-76.4%).
</p>
</div>
<div className="mt-3 pt-2 border-t border-ink/20 text-[10px] text-hazard font-mono font-bold uppercase">
SRAM Constraint: &lt; 16 KB MCU
</div>
</div>
{/* Formulation 5: Platt Calibration */}
<div className="border-2 border-ink bg-canvas-cream p-5 flex flex-col justify-between">
<div>
<div className="text-[10px] font-black text-hazard uppercase mb-1">05 // SVM PROBABILITY CALIBRATION</div>
<h4 className="text-[14px] font-black text-ink uppercase mb-2">Platt Sigmoid Scaling</h4>
<div className="bg-white border-2 border-ink p-3 text-center font-mono text-[12px] md:text-[13px] font-bold text-ink mb-3">
P(Class<sub className="text-[10px]">c</sub> | f<sub className="text-[10px]">c</sub>) = 1 / ( 1 + exp(A<sub className="text-[10px]">c</sub> · f<sub className="text-[10px]">c</sub> + B<sub className="text-[10px]">c</sub>) )
</div>
<p className="text-[11px] text-slate leading-relaxed normal-case font-mono">
Converts uncalibrated SVM hyperplane decision distances f(X) into authentic probability distributions using maximum likelihood logistic regression fitting.
</p>
</div>
<div className="mt-3 pt-2 border-t border-ink/20 text-[10px] text-slate font-mono font-bold uppercase">
Calibration: 3-Fold Cross-Validation
</div>
</div>
</div>
</div>
</section>
{/* SECTION 3: SYSTEM LATENCY & SPEEDUP BENCHMARK MATRIX */}
<section className="crosshair-corner border-2 border-ink bg-white p-6 sm:p-8 shadow-[4px_4px_0px_0px_#141413]">
<div className="border-b-2 border-ink pb-4 mb-6 flex flex-col md:flex-row justify-between md:items-end gap-2">
<div>
<div className="text-[11px] font-bold text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<BarChart3 size={14} />
<span>TARGET EXECUTION LATENCY BENCHMARK MATRIX</span>
</div>
<h2 className="text-[20px] sm:text-[24px] font-black uppercase tracking-tight text-ink">
System Latency &amp; Speedup Comparison
</h2>
</div>
<div className="text-[11px] text-slate font-bold uppercase">
Measured across 10,000 synthetic patient vectors
</div>
</div>
{/* Graphical Visual Latency Bars */}
<div className="flex flex-col gap-6 mb-8">
{[
{
target: "ESP32-S3 (C99 Bare-Metal)",
time: "18.4 µs",
percent: 1.5,
color: "bg-emerald-600",
badge: "FASTEST (ON-CHIP)",
desc: "INT8 fixed-point matrix multiplication with zero-malloc static stack."
},
{
target: "In-Browser Client TinyML",
time: "19.8 µs",
percent: 1.8,
color: "bg-emerald-500",
badge: "ZERO-EGRESS CLIENT",
desc: "Pure TypeScript client runtime running in Web Worker / main thread."
},
{
target: "ARM Cortex-M4 (168 MHz)",
time: "32.6 µs",
percent: 2.8,
color: "bg-teal-600",
badge: "MCU BARE-METAL",
desc: "DSP instruction set acceleration without hardware floating-point unit."
},
{
target: "RP2040 Dual Cortex-M0+",
time: "64.2 µs",
percent: 5.2,
color: "bg-blue-600",
badge: "LOW-COST SILICON",
desc: "Dual-core parallel tree branch evaluation across 133 MHz clocks."
},
{
target: "Local Python Server (FastAPI / CPU)",
time: "3.2 ms",
percent: 25.0,
color: "bg-amber-600",
badge: "HOST RUNTIME",
desc: "Full Python interpreter with scikit-learn PyData overhead."
},
{
target: "Cloud Edge Anycast REST",
time: "32.4 ms",
percent: 100.0,
color: "bg-hazard",
badge: "NETWORK BOUND",
desc: "HTTP/2 TLS handshake, TCP transmission, and cloud ingress egress latency."
}
].map((item, i) => (
<div key={i} className="flex flex-col gap-2">
<div className="flex flex-wrap justify-between items-baseline gap-2">
<div className="flex items-center gap-2">
<span className="font-bold text-[13px] text-ink uppercase">{item.target}</span>
<span className="text-[9px] font-black uppercase px-2 py-0.5 border border-ink bg-canvas-cream text-ink">
{item.badge}
</span>
</div>
<div className="text-[14px] font-mono font-black text-ink tabular-nums">
{item.time}
</div>
</div>
{/* Visual Bar */}
<div className="w-full h-5 border-2 border-ink bg-canvas-cream p-0.5 relative">
<div
className={`h-full ${item.color} transition-all duration-500`}
style={{ width: `${Math.max(item.percent, 1.5)}%` }}
/>
</div>
<div className="text-[10px] text-slate">{item.desc}</div>
</div>
))}
</div>
{/* Hardware Pinout & Web Serial Bridge Map */}
<div className="border-2 border-ink bg-canvas-cream p-6">
<div className="text-[11px] font-black text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<Cpu size={14} />
<span>HARDWARE INTERFACE PINOUT SPECIFICATION (ESP32-S3)</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mt-4">
<div className="border border-ink bg-white p-3">
<div className="text-[10px] text-slate font-bold uppercase">AD8232 ANALOG IN</div>
<div className="text-[14px] font-black text-ink mt-1">GPIO 4 (ADC1_CH3)</div>
<div className="text-[10px] text-slate mt-1">Lead-II Differential Output</div>
</div>
<div className="border border-ink bg-white p-3">
<div className="text-[10px] text-slate font-bold uppercase">MAX30102 I2C BUS</div>
<div className="text-[14px] font-black text-ink mt-1">SDA: GPIO 8 / SCL: GPIO 9</div>
<div className="text-[10px] text-slate mt-1">400 kHz Fast-Mode I2C</div>
</div>
<div className="border border-ink bg-white p-3">
<div className="text-[10px] text-slate font-bold uppercase">UART CDC EMULATION</div>
<div className="text-[14px] font-black text-ink mt-1">USB Type-C (Native CDC)</div>
<div className="text-[10px] text-slate mt-1">115,200 Baud / Direct Serial</div>
</div>
</div>
</div>
</section>
{/* SECTION 4: INT8 QUANTIZATION & SRAM BUDGET MATRIX */}
<section className="crosshair-corner border-2 border-ink bg-white p-6 sm:p-8 shadow-[4px_4px_0px_0px_#141413]">
<div className="border-b-2 border-ink pb-4 mb-6 flex flex-col md:flex-row justify-between md:items-end gap-2">
<div>
<div className="text-[11px] font-bold text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<Binary size={14} />
<span>EMBEDDED SILICON MEMORY PROFILER</span>
</div>
<h2 className="text-[20px] sm:text-[24px] font-black uppercase tracking-tight text-ink">
INT8 Quantization &amp; SRAM Budget Matrix
</h2>
</div>
<div className="text-[11px] text-slate font-bold uppercase">
FP32 vs INT8 memory footprint across MCU targets
</div>
</div>
{/* Memory Savings Callout Card */}
<div className="bg-canvas-cream border-2 border-ink p-6 mb-8 flex flex-col md:flex-row justify-between items-center gap-6">
<div>
<div className="text-[10px] font-black text-hazard uppercase tracking-widest mb-1">
AGGREGATE ENSEMBLE MEMORY PROFILE
</div>
<div className="text-[28px] font-black text-ink tracking-tight">
34,608 Bytes &rarr; <span className="text-emerald-700">8,152 Bytes</span>
</div>
<div className="text-[12px] text-slate uppercase mt-1">
INT8 affine quantization fits within sub-16KB SRAM targets without algorithmic accuracy degradation.
</div>
</div>
<div className="border-2 border-ink bg-white px-6 py-4 text-center">
<div className="text-[10px] font-bold text-slate uppercase">TOTAL SRAM REDUCTION</div>
<div className="text-[32px] font-black text-hazard tracking-tight">-76.4%</div>
<div className="text-[9px] font-mono text-emerald-700 font-bold">DELTA: -26,456 BYTES</div>
</div>
</div>
{/* Quantization Table */}
<div className="border-2 border-ink overflow-x-auto mb-8">
<table className="w-full text-left text-[12px] font-mono tabular-nums">
<thead className="bg-ink text-white uppercase tracking-wider font-bold">
<tr>
<th className="px-4 py-3 border-r border-white/20">Estimator Architecture</th>
<th className="px-4 py-3 border-r border-white/20">FP32 Memory</th>
<th className="px-4 py-3 border-r border-white/20">INT8 Quantized</th>
<th className="px-4 py-3 border-r border-white/20">Savings</th>
<th className="px-4 py-3">Microcontroller Targets</th>
</tr>
</thead>
<tbody className="divide-y border-t border-ink text-ink font-bold">
{[
{ name: "Random Forest (30 Trees, D=5)", fp32: "16,384 bytes", int8: "4,096 bytes", pct: "-75.0%", target: "ESP32, RP2040, Cortex-M4" },
{ name: "Small-NN (MLP 16x8 ReLU)", fp32: "7,168 bytes", int8: "1,792 bytes", pct: "-75.0%", target: "ESP32, RP2040, Cortex-M4" },
{ name: "Linear Support Vector Machine", fp32: "3,584 bytes", int8: "896 bytes", pct: "-75.0%", target: "ESP32, RP2040, Cortex-M4" },
{ name: "Logistic Regression (L2)", fp32: "3,072 bytes", int8: "768 bytes", pct: "-75.0%", target: "ESP32, RP2040, Cortex-M4" },
{ name: "k-Nearest Neighbors (k=5)", fp32: "4,400 bytes", int8: "600 bytes", pct: "-86.4%", target: "ESP32, RP2040, Cortex-M4" }
].map((row, i) => (
<tr key={i} className="hover:bg-canvas-cream transition-colors">
<td className="px-4 py-3 border-r border-ink/20 font-sans font-bold">{row.name}</td>
<td className="px-4 py-3 border-r border-ink/20 text-slate">{row.fp32}</td>
<td className="px-4 py-3 border-r border-ink/20 text-emerald-700">{row.int8}</td>
<td className="px-4 py-3 border-r border-ink/20 text-hazard">{row.pct}</td>
<td className="px-4 py-3 text-slate font-sans text-[11px] uppercase">{row.target}</td>
</tr>
))}
</tbody>
</table>
</div>
{/* Zero-Malloc ABI Guarantee */}
<div className="border-2 border-ink bg-canvas-cream p-6">
<div className="text-[11px] font-black text-hazard uppercase tracking-widest mb-1 flex items-center gap-1.5">
<Terminal size={14} />
<span>ZERO-MALLOC C99 ABI GUARANTEE</span>
</div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4 mt-3">
<div className="bg-white border-2 border-ink p-4">
<div className="text-[12px] font-black uppercase text-ink mb-1">Heap Allocation: 0 Bytes</div>
<p className="text-[11px] text-slate normal-case font-mono leading-relaxed">
Transpiler emits strictly static lookup tables and stack-allocated arrays. Zero invocations of <code className="bg-canvas-cream border border-ink/30 px-1 font-bold">malloc()</code>, <code className="bg-canvas-cream border border-ink/30 px-1 font-bold">free()</code>, or <code className="bg-canvas-cream border border-ink/30 px-1 font-bold">calloc()</code> guarantees zero heap fragmentation and immune to out-of-memory kernel panics.
</p>
</div>
<div className="bg-white border-2 border-ink p-4">
<div className="text-[12px] font-black uppercase text-ink mb-1">Bounded Stack Traversal: &lt; 512B</div>
<p className="text-[11px] text-slate normal-case font-mono leading-relaxed">
Recursion is completely unrolled into deterministic iterative loops. Maximum call-stack depth is strictly bounded at compile-time to less than 512 bytes, ensuring safe co-existence with FreeRTOS task stacks.
</p>
</div>
</div>
</div>
</section>
</div>
</main>
);
}