layers are not being adjusted
This commit is contained in:
parent
329c5f5f81
commit
6c186bc6e4
33
nn.test.js
33
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 { Label, Forward, Backward } from "./nn.ts";
|
||||||
import { default as M } from "./m.ts";
|
import { default as M } from "./m.ts";
|
||||||
|
|
||||||
const input = [
|
let training = [];
|
||||||
[ 0.1, 0.05],
|
let stages = [];
|
||||||
[ 0.0, -0.06]
|
let layers = [];
|
||||||
[ 0.99, 0.85],
|
|
||||||
[ 1.2, 1.05]
|
|
||||||
];
|
|
||||||
|
|
||||||
const training = [];
|
|
||||||
const stages = [];
|
|
||||||
const layers = [];
|
|
||||||
|
|
||||||
Deno.test("NN.Label", ()=>
|
Deno.test("NN.Label", ()=>
|
||||||
{
|
{
|
||||||
@ -38,19 +31,21 @@ Deno.test("NN.Label", ()=>
|
|||||||
Deno.test("NN.Backward", ()=>
|
Deno.test("NN.Backward", ()=>
|
||||||
{
|
{
|
||||||
|
|
||||||
layers.push(M.Create.Box([0, 0, 0], [1, 1, 1], 4));
|
let layer1 = 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 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]);
|
layers.push(layer1);
|
||||||
let copy2 = M.Create.Clone(layers[1]);
|
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);
|
||||||
}
|
}
|
||||||
|
console.log(layer1, copy1);
|
||||||
assert(layers[0][0][0] != copy1[0][0][0], "first matrix has changed");
|
assert(layer1[0][0] != copy1[0][0], "first matrix has changed");
|
||||||
assert(layers[1][0][0] != copy2[0][0][0], "second matrix has changed");
|
assert(layer1[1][0] != copy2[1][0], "second matrix has changed");
|
||||||
});
|
});
|
||||||
|
|
||||||
Deno.test("NN.Forward", ()=>
|
Deno.test("NN.Forward", ()=>
|
||||||
|
1
nn.ts
1
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 layerMatrix:Cloud.M = inLayers[i];
|
||||||
let layerInput:Cloud.M = inStages[i];
|
let layerInput:Cloud.M = inStages[i];
|
||||||
let layerOutput:Cloud.M = inStages[i+1];
|
let layerOutput:Cloud.M = inStages[i+1];
|
||||||
|
|
||||||
let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, M.Batch.Derivative(layerOutput));
|
let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, M.Batch.Derivative(layerOutput));
|
||||||
|
|
||||||
errorBack = M.Batch.Affine(errorScaled, M.Create.Transpose(layerMatrix));
|
errorBack = M.Batch.Affine(errorScaled, M.Create.Transpose(layerMatrix));
|
||||||
|
Loading…
Reference in New Issue
Block a user