diff --git a/nn.test.js b/nn.test.js index 5a4c01e..145867b 100644 --- a/nn.test.js +++ b/nn.test.js @@ -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; diff --git a/nn.ts b/nn.ts index c2e8ff7..8c07f32 100644 --- a/nn.ts +++ b/nn.ts @@ -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 { 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)=> {