From 963996b06b9a6c285896126e00de3fc22ec2f3ae Mon Sep 17 00:00:00 2001 From: sneedgroup-holder Date: Tue, 3 Dec 2024 23:05:16 +0000 Subject: [PATCH] kuromi: optimize suboptimal code... ...as described by sparksammy. --- sam-neurons-words.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sam-neurons-words.js b/sam-neurons-words.js index fb4737b..1cf623a 100644 --- a/sam-neurons-words.js +++ b/sam-neurons-words.js @@ -92,7 +92,6 @@ class NeuralNetwork { } // Example usage: -let nn = new NeuralNetwork(3, 4, 1); // Increased hidden nodes to 4 // Example dataset (XOR problem) let strings = ["hello", "neural", "world"] @@ -103,6 +102,9 @@ let inputs = [ [1, 0, 1], [1, 1, 1] ]; + +let nn = new NeuralNetwork(strings.length, inputs.length, 1); // Increased hidden nodes to 4 + let targets = [ [0], [1], @@ -110,6 +112,10 @@ let targets = [ [3] ]; +if (targets.length != inputs.length) { + throw new Error("You dummy, targets length should be equal to inputs length.") +} + // Training the neural network for (let i = 0; i < 50000; i++) { // Increased training iterations let index = Math.floor(Math.random() * 4);