kuromi: optimize suboptimal code...
...as described by sparksammy.
This commit is contained in:
parent
13e2a4b8ee
commit
963996b06b
1 changed files with 7 additions and 1 deletions
|
@ -92,7 +92,6 @@ class NeuralNetwork {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Example usage:
|
// Example usage:
|
||||||
let nn = new NeuralNetwork(3, 4, 1); // Increased hidden nodes to 4
|
|
||||||
|
|
||||||
// Example dataset (XOR problem)
|
// Example dataset (XOR problem)
|
||||||
let strings = ["hello", "neural", "world"]
|
let strings = ["hello", "neural", "world"]
|
||||||
|
@ -103,6 +102,9 @@ let inputs = [
|
||||||
[1, 0, 1],
|
[1, 0, 1],
|
||||||
[1, 1, 1]
|
[1, 1, 1]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
let nn = new NeuralNetwork(strings.length, inputs.length, 1); // Increased hidden nodes to 4
|
||||||
|
|
||||||
let targets = [
|
let targets = [
|
||||||
[0],
|
[0],
|
||||||
[1],
|
[1],
|
||||||
|
@ -110,6 +112,10 @@ let targets = [
|
||||||
[3]
|
[3]
|
||||||
];
|
];
|
||||||
|
|
||||||
|
if (targets.length != inputs.length) {
|
||||||
|
throw new Error("You dummy, targets length should be equal to inputs length.")
|
||||||
|
}
|
||||||
|
|
||||||
// Training the neural network
|
// Training the neural network
|
||||||
for (let i = 0; i < 50000; i++) { // Increased training iterations
|
for (let i = 0; i < 50000; i++) { // Increased training iterations
|
||||||
let index = Math.floor(Math.random() * 4);
|
let index = Math.floor(Math.random() * 4);
|
||||||
|
|
Loading…
Reference in a new issue