import { assert, assertEquals } from "https://deno.land/std@0.102.0/testing/asserts.ts"; import { Label, Forward, Backward } from "./nn.ts"; import { default as M } from "./m.ts"; import { default as Methods } from "./m.ts"; let training = []; let stages = []; let layers = []; let typeA = [ [ 0.1, 0.05], [ 0.0, -0.06] ]; let typeB = [ [ 0.99, 0.85], [ 1.2, 1.05] ]; Deno.test("check.forward", ()=> { let matrix1 = [ [-0.43662948305036675, -0.368590640707799, -0.23227179558890843], [-0.004292653969505622, 0.38670055222186317, -0.2478421495365568], [0.738181366836224, 0.3389203747353555, 0.4920200816404332] ]; let matrix2 = [ [0.5793881115472015, 0.9732593374796092, 0.15207639877016987, -0.5356575655337803] ]; let typeA = [ [ 0.1, 0.05], [ 0.0, -0.06] ]; let typeB = [ [ 0.99, 0.85], [ 1.2, 1.05] ]; let goals = [ [1, 1, 0], [0, 0, 1] ]; let layers = [matrix1]; let stages = Forward(Methods.Mutate.Pad(typeA), layers); Backward(stages, layers, goals, 0.1); }); /* Deno.test("NN.Label", ()=> { Label(training, typeA, [1]); Label(training, typeB, [0]); stages.push(training[0]); console.log(training); assertEquals(training.length, 2, "input and output sets created"); assertEquals(training[0].length, training[1].length, "both sets have same length"); assertEquals(training[0][0].length, 3, "padded input component"); assertEquals(training[1][0].length, 1, "unchanged label vector"); }); Deno.test("NN.Backward", ()=> { let layer1 = M.Create.Box([-1, -1, -1], [1, 1, 1], 2); let layer2 = M.Create.Box([-1, -1, -1], [1, 1, 1], 1); let copy1 = M.Create.Clone(layer1); let copy2 = M.Create.Clone(layer2); layers.push(layer1); layers.push(layer2); for(let i=0; i<100; i++) { Backward(stages, layers, training[1], 0.1); } assert(layers[0][0][0] != copy1[0][0], "first matrix has changed"); assert(layers[1][0][0] != copy2[0][0], "second matrix has changed"); }); Deno.test("NN.Forward", ()=> { console.log(Forward(stages, layers)); console.log(training[1]); }); */