nn/nn.test.js

89 lines
2.2 KiB
JavaScript
Raw Normal View History

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 20:08:17 -04:00
import { default as Methods } 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
2021-07-28 20:08:17 -04:00
let typeA = [
[ 0.1, 0.05],
[ 0.0, -0.06]
];
let typeB = [
[ 0.99, 0.85],
[ 1.2, 1.05]
];
Deno.test("check.forward", ()=>
2021-07-28 12:04:00 -04:00
{
2021-07-28 20:08:17 -04:00
let training = [];
let stages = [];
let layers = [
[
[-0.43662948305036675, -0.368590640707799, -0.23227179558890843],
[-0.004292653969505622, 0.38670055222186317, -0.2478421495365568],
[0.738181366836224, 0.3389203747353555, 0.4920200816404332]
],
[
[0.5793881115472015, 0.9732593374796092, 0.15207639877016987, -0.5356575655337803]
]
];
let typeA = [
2021-07-28 14:08:46 -04:00
[ 0.1, 0.05],
[ 0.0, -0.06]
2021-07-28 20:08:17 -04:00
];
let typeB = [
2021-07-28 14:08:46 -04:00
[ 0.99, 0.85],
[ 1.2, 1.05]
2021-07-28 20:08:17 -04:00
];
Label(training, typeA, [1]);
stages.push(training[0]);
Forward(stages, layers);
console.log(stages);
});
/*
Deno.test("NN.Label", ()=>
{
Label(training, typeA, [1]);
Label(training, typeB, [0]);
2021-07-28 14:08:46 -04:00
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 20:08:17 -04:00
let layer1 = M.Create.Box([-1, -1, -1], [1, 1, 1], 2);
let layer2 = M.Create.Box([-1, -1, -1], [1, 1, 1], 1);
2021-07-28 14:51:49 -04:00
let copy1 = M.Create.Clone(layer1);
let copy2 = M.Create.Clone(layer2);
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 16:40:58 -04:00
Backward(stages, layers, training[1], 0.1);
2021-07-28 14:08:46 -04:00
}
2021-07-28 16:40:58 -04:00
assert(layers[0][0][0] != copy1[0][0], "first matrix has changed");
assert(layers[1][0][0] != copy2[0][0], "second matrix has changed");
2021-07-28 12:04:00 -04:00
});
2021-07-28 14:08:46 -04:00
2021-07-28 16:40:58 -04:00
2021-07-28 14:08:46 -04:00
Deno.test("NN.Forward", ()=>
{
console.log(Forward(stages, layers));
console.log(training[1]);
});
2021-07-28 16:40:58 -04:00
2021-07-28 20:08:17 -04:00
*/