diff --git a/nn.test.js b/nn.test.js index 0cda710..608fd61 100644 --- a/nn.test.js +++ b/nn.test.js @@ -2,16 +2,9 @@ import { assert, assertEquals } from "https://deno.land/std@0.102.0/testing/asse import { Label, Forward, Backward } from "./nn.ts"; import { default as M } from "./m.ts"; -const input = [ - [ 0.1, 0.05], - [ 0.0, -0.06] - [ 0.99, 0.85], - [ 1.2, 1.05] -]; - -const training = []; -const stages = []; -const layers = []; +let training = []; +let stages = []; +let layers = []; Deno.test("NN.Label", ()=> { @@ -38,19 +31,21 @@ Deno.test("NN.Label", ()=> Deno.test("NN.Backward", ()=> { - layers.push(M.Create.Box([0, 0, 0], [1, 1, 1], 4)); - layers.push(M.Create.Box([0, 0, 0, 0, 0], [1, 1, 1, 1, 1], 1)); + let layer1 = M.Create.Box([0, 0, 0], [1, 1, 1], 4); + let layer2 = M.Create.Box([0, 0, 0, 0, 0], [1, 1, 1, 1, 1], 1); + let copy1 = M.Create.Clone(layer1); + let copy2 = M.Create.Clone(layer2); - let copy1 = M.Create.Clone(layers[0]); - let copy2 = M.Create.Clone(layers[1]); + layers.push(layer1); + layers.push(layer2); - for(let i=0; i<1000; i++) + for(let i=0; i<100; i++) { - Backward(stages, layers, training[1], 0.1); + Backward(stages, layers, training[1], 0.01); } - - assert(layers[0][0][0] != copy1[0][0][0], "first matrix has changed"); - assert(layers[1][0][0] != copy2[0][0][0], "second matrix has changed"); + console.log(layer1, copy1); + assert(layer1[0][0] != copy1[0][0], "first matrix has changed"); + assert(layer1[1][0] != copy2[1][0], "second matrix has changed"); }); Deno.test("NN.Forward", ()=> diff --git a/nn.ts b/nn.ts index c08185d..62ec50b 100644 --- a/nn.ts +++ b/nn.ts @@ -38,7 +38,6 @@ const Backward = (inStages:N, inLayers:N, inGoals:Cloud.M, inRate:number):void = let layerMatrix:Cloud.M = inLayers[i]; let layerInput:Cloud.M = inStages[i]; let layerOutput:Cloud.M = inStages[i+1]; - let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, M.Batch.Derivative(layerOutput)); errorBack = M.Batch.Affine(errorScaled, M.Create.Transpose(layerMatrix));