network #1
10
index.html
10
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);
|
||||
|
||||
</script>
|
30
nn.test.js
30
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);
|
||||
});
|
||||
|
||||
/*
|
||||
|
15
nn.ts
15
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<inLayers.length-1; i++)
|
||||
{
|
||||
inStages[i+1] = M.Mutate.Pad(process(i));
|
||||
stages[i+1] = M.Mutate.Pad(process(i));
|
||||
}
|
||||
inStages[i+1] = process(i);
|
||||
return inStages[i+1];
|
||||
stages[i+1] = process(i);
|
||||
return stages;
|
||||
};
|
||||
const Backward = (inStages:N, inLayers:N, inGoals:Cloud.M, inRate:number):N =>
|
||||
{
|
||||
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--)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user