import { assert, assertEquals } from "https://deno.land/std@0.102.0/testing/asserts.ts"; import { Split, 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/backward", ()=> { let matrix1 = [ [-0.43662948305036675, -0.368590640707799, -0.23227179558890843], [-0.004292653969505622, 0.38670055222186317, -0.2478421495365568], [0.738181366836224, 0.3389203747353555, 0.4920200816404332] ]; let matrix2 = [ [0.7098703863463034, 0.35485944251238033, 0.7642849892333241, 0.03046174288491077], [-0.30655426258144347, 0.45509633551425077, -0.5013795222004322, -0.3421292736637427] ]; let input = [ [ 0.1, 0.05], [ 0.0, -0.06], [ 0.99, 0.85], [ 1.2, 1.05] ]; let output = [ [1, 0], [1, 0], [0, 1], [0, 1] ]; let layers = [matrix1, matrix2]; let stages = []; for(let i=0; i<1000; i++) { stages = Forward(Methods.Mutate.Pad(input), layers); Backward(stages, layers, output, 0.1); } stages = Forward(input, layers); console.log(stages[stages.length-1]); }); Deno.test("NN.Split", ()=> { let data = [ [3, 2, 1, 0, 1], [6, 5, 4, 1, 0] ] let split = Split(data, [3, 4]); console.log(split); }); /* Deno.test("NN.Label", ()=> { Label(training, typeA, [1, 0]); Label(training, typeB, [0, 1]); 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, 2, "unchanged label vector"); }); Deno.test("NN.Forward", ()=> { let layer1 = M.Create.Box([-1, -1, -1], [1, 1, 1], 2); let layer2 = M.Create.Box([-1, -1, -1], [1, 1, 1], 1); layers.push(layer1); layers.push(layer2); console.log(training[0]); stages = Forward(training[0], layers); console.log(stages); }); Deno.test("NN.Backward", ()=> { let copy1 = M.Create.Clone(layers[0]); let copy2 = M.Create.Clone(layers[1]); 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.Label", ()=> { let stages = Forward(training[0], layers); console.log(stages[stages.length-1]); }); */