import { default as M, Cloud } from "./m.ts"; export type N = Array>> const Label = (inSet:any, inData:Cloud.M, inLabel:Cloud.V):N => { if(!inSet){inSet = [[], []];} if(inSet.length == 0){inSet.push([]);} if(inSet.length == 1){inSet.push([]);} inData.forEach((row:Cloud.V) => { row.push(1); inSet[0].push(row); inSet[1].push(inLabel); }); return inSet; }; const Forward = (inData:Cloud.M, inLayers:N):N => { let i:number; 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(inStages[inStages.length-1], inGoals); for(i=inLayers.length-1; i>=0; i--) { let layerInput:Cloud.M = inStages[i]; let layerOutput:Cloud.M = inStages[i+1]; let errorScaled:Cloud.M = M.Batch.Multiply(errorBack, M.Batch.Derivative(layerOutput)); errorBack = M.Batch.Affine(errorScaled, M.Create.Transpose(inLayers[i])); console.log("matrix before:", inLayers[i]); errorScaled.forEach((inScaledError:Cloud.V, inIndex:number)=> { const deltas = M.Batch.Scale(M.Create.Outer(layerInput[inIndex], inScaledError), inRate); inLayers[i] = M.Batch.Subtract(inLayers[i], deltas); }); console.log("matrix after:", inLayers[i]); } return inLayers; }; export { Label, Forward, Backward }; export type { Cloud };