From 351723d8e75c3ea38cfd9c6ddc808d4d2596cc66 Mon Sep 17 00:00:00 2001 From: EyobelG Date: Thu, 22 Oct 2026 18:30:01 -0400 Subject: [PATCH] Add optimizers, more activations, dropout, early stopping, model save/load, dark mode - nn.ts: pluggable optimizer (SGD/Momentum/RMSProp/Adam) with gradient clipping and learning-rate decay, replacing the plain SGD-only update step. Adds LeakyReLU/ELU/Swish activations, inverted dropout on hidden layers during training, an EarlyStopping helper, and JSON serialize/deserialize for a trained network's weights and biases. - state.ts/playground.ts/index.html: wire the above into the UI (optimizer dropdown, dropout slider, early-stopping checkbox, save/load model buttons using File/Blob APIs) and add a dark mode toggle persisted to localStorage. - styles.css: dark mode via a page-wide invert filter, with the classification/regression color-coded regions (heatmap, network diagram, dataset thumbnails, loss chart, color legend) counter-inverted so their colors keep their original meaning. Multi-class classification support and CSV/JSON dataset import were scoped out of this change: multi-class would require rebuilding the single-output network architecture, decision-boundary heatmap and dataset generators, and dataset import was dropped as an unnecessary file-handling attack surface for this pass. --- index.html | 40 ++++++++ src/nn.ts | 237 ++++++++++++++++++++++++++++++++++++++++++++-- src/playground.ts | 120 ++++++++++++++++++++++- src/state.ts | 33 ++++++- styles.css | 28 ++++++ 5 files changed, 445 insertions(+), 13 deletions(-) diff --git a/index.html b/index.html index 3f6060d6..f6a6ad3a 100644 --- a/index.html +++ b/index.html @@ -98,6 +98,20 @@

Tinker With a Neural Network R + + + + + + +
+ +
+
@@ -137,6 +151,20 @@

Tinker With a Neural Network R +
+ +
+
+ + + +
@@ -189,6 +217,18 @@

+ +
+ +

+ +

+
+
+