relu-sig check added to passes

This commit is contained in:
TreetopFlyer 2021-07-30 23:28:25 -04:00
parent 3861d41c83
commit 44771715d3
2 changed files with 6 additions and 4 deletions

View File

@ -17,7 +17,6 @@ Deno.test("NN.Split", ()=>
assert(input);
assert(output);
assertEquals(input.length, output.length, "data split into equal input and output");
console.log(output);
assertEquals(input[0].length, 2, "unpadded input");
assertEquals(output[0].length, 2, "unpadded output");
@ -44,7 +43,8 @@ Deno.test("NN.Label", ()=>
Deno.test("NN.Learn", ()=>
{
let error = Learn(input, layers, output, 1000, 0.1);
let error = Learn(input, layers, output, 50, 0.2);
console.log(error);
assertEquals(error.length, output.length);
let total = 0;
let count = error.length*error[0].length;

6
nn.ts
View File

@ -5,7 +5,8 @@ const Forward = (inData:Cloud.M, inLayers:N):N =>
{
let i:number;
let stages:N = [inData];
let process = (index:number):Cloud.M => M.Batch.Sig(M.Batch.Affine(stages[index], inLayers[index]));
let nonLinear = (inIndex:number):any=> inIndex >= inLayers.length-1 ? M.Batch.Sig : M.Batch.Rec;
let process = (index:number):Cloud.M => nonLinear(index)(M.Batch.Affine(stages[index], inLayers[index]));
for(i=0; i<inLayers.length-1; i++){ stages[i+1] = M.Mutate.Pad(process(i)); }
stages[i+1] = process(i);
@ -15,10 +16,11 @@ const Backward = (inStages:N, inLayers:N, inGoals:Cloud.M, inRate:number):N =>
{
let i:number;
let errorBack:Cloud.M = M.Batch.Subtract(inStages[inStages.length-1], inGoals);
let nonLinear = (inIndex:number):any=> inIndex >= inLayers.length-1 ? M.Batch.SigDeriv : M.Batch.RecDeriv;
for(i=inLayers.length-1; i>=0; i--)
{
let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, M.Batch.SigDeriv(inStages[i+1]));
let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, nonLinear(i)(inStages[i+1]));
errorBack = M.Batch.Affine(errorScaled, M.Create.Transpose(inLayers[i]));
errorScaled.forEach((inScaledError:Cloud.V, inIndex:number)=>
{