diff --git a/index.html b/index.html index 3a5501d..5b7b9a1 100644 --- a/index.html +++ b/index.html @@ -699,15 +699,17 @@ NN.Network.Stochastic = function(inNetwork, inTrainingSet, inIterations) [ 0.99, 0.85], [ 1.2, 1.05] ]; + let goals = [ + [1, 1, 0], + [0, 0, 1] + ]; var layer1 = NN.Layer.Create(1, 1); layer1.Forward.Matrix = matrix1; - var layer2 = NN.Layer.Create(1, 1); - layer2.Forward.Matrix = matrix2; - let stage1 = NN.Layer.Forward(layer1, typeA); + let stage1Error = NN.Layer.Error(layer1, goals); - console.log(stage1); + console.log(stage1Error); \ No newline at end of file diff --git a/nn.test.js b/nn.test.js index f86af35..96de2aa 100644 --- a/nn.test.js +++ b/nn.test.js @@ -19,17 +19,14 @@ let typeB = [ Deno.test("check.forward", ()=> { - 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 matrix1 = [ + [-0.43662948305036675, -0.368590640707799, -0.23227179558890843], + [-0.004292653969505622, 0.38670055222186317, -0.2478421495365568], + [0.738181366836224, 0.3389203747353555, 0.4920200816404332] + ]; + + let matrix2 = [ + [0.5793881115472015, 0.9732593374796092, 0.15207639877016987, -0.5356575655337803] ]; let typeA = [ @@ -40,11 +37,14 @@ Deno.test("check.forward", ()=> [ 0.99, 0.85], [ 1.2, 1.05] ]; + let goals = [ + [1, 1, 0], + [0, 0, 1] + ]; - Label(training, typeA, [1]); - stages.push(training[0]); - Forward(stages, layers); - console.log(stages); + let layers = [matrix1]; + let stages = Forward(Methods.Mutate.Pad(typeA), layers); + Backward(stages, layers, goals, 0.1); }); /* diff --git a/nn.ts b/nn.ts index d902636..874b28f 100644 --- a/nn.ts +++ b/nn.ts @@ -16,22 +16,25 @@ const Label = (inSet:any, inData:Cloud.M, inLabel:Cloud.V):N => return inSet; }; -const Forward = (inStages:N, inLayers:N):Cloud.M => +const Forward = (inData:Cloud.M, inLayers:N):N => { let i:number; - let process = (index:number):Cloud.M => M.Batch.Sigmoid(M.Batch.Affine(inStages[index], inLayers[index])); + let stages = [inData]; + let process = (index:number):Cloud.M => M.Batch.Sigmoid(M.Batch.Affine(stages[index], inLayers[index])); for(i=0; i { let i:number; - let errorBack:Cloud.M = M.Batch.Subtract(Forward(inStages, inLayers), inGoals); + let errorBack:Cloud.M = M.Batch.Subtract(inStages[inStages.length-1], inGoals); + + console.log(errorBack); for(i=inLayers.length-1; i>=0; i--) {