2021-07-28 12:04:00 -04:00
|
|
|
import { assert, assertEquals } from "https://deno.land/std@0.102.0/testing/asserts.ts";
|
2021-07-28 14:08:46 -04:00
|
|
|
import { Label, Forward, Backward } from "./nn.ts";
|
|
|
|
import { default as M } from "./m.ts";
|
2021-07-28 12:04:00 -04:00
|
|
|
|
2021-07-28 14:51:49 -04:00
|
|
|
let training = [];
|
|
|
|
let stages = [];
|
|
|
|
let layers = [];
|
2021-07-28 14:08:46 -04:00
|
|
|
|
|
|
|
Deno.test("NN.Label", ()=>
|
2021-07-28 12:04:00 -04:00
|
|
|
{
|
2021-07-28 14:08:46 -04:00
|
|
|
Label(training,
|
|
|
|
[
|
|
|
|
[ 0.1, 0.05],
|
|
|
|
[ 0.0, -0.06]
|
|
|
|
],
|
|
|
|
[1]);
|
|
|
|
Label(training,
|
|
|
|
[
|
|
|
|
[ 0.99, 0.85],
|
|
|
|
[ 1.2, 1.05]
|
|
|
|
],
|
|
|
|
[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");
|
2021-07-28 12:04:00 -04:00
|
|
|
});
|
2021-07-28 14:08:46 -04:00
|
|
|
|
|
|
|
Deno.test("NN.Backward", ()=>
|
2021-07-28 12:04:00 -04:00
|
|
|
{
|
2021-07-28 14:08:46 -04:00
|
|
|
|
2021-07-28 14:51:49 -04:00
|
|
|
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);
|
2021-07-28 14:08:46 -04:00
|
|
|
|
2021-07-28 14:51:49 -04:00
|
|
|
layers.push(layer1);
|
|
|
|
layers.push(layer2);
|
2021-07-28 14:08:46 -04:00
|
|
|
|
2021-07-28 14:51:49 -04:00
|
|
|
for(let i=0; i<100; i++)
|
2021-07-28 14:08:46 -04:00
|
|
|
{
|
2021-07-28 14:51:49 -04:00
|
|
|
Backward(stages, layers, training[1], 0.01);
|
2021-07-28 14:08:46 -04:00
|
|
|
}
|
2021-07-28 14:51:49 -04:00
|
|
|
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");
|
2021-07-28 12:04:00 -04:00
|
|
|
});
|
2021-07-28 14:08:46 -04:00
|
|
|
|
|
|
|
Deno.test("NN.Forward", ()=>
|
|
|
|
{
|
|
|
|
console.log(Forward(stages, layers));
|
|
|
|
console.log(training[1]);
|
|
|
|
});
|
|
|
|
|