private void AdjustWeights(InputExpectedResult irp, int microBatchIndex) { ResetCurTimer(); double[] actual = Network.GetInputResult(irp.Input); double[] target = irp.Output; LogProcess("Load actual / target"); //Set output influence value for(int nodeIndex = 0; nodeIndex < Network.Nodes[Network.Nodes.Length - 1].Length; nodeIndex++) { double curTarget = target[nodeIndex]; double curActual = actual[nodeIndex]; Node curNode = Network.Nodes[Network.Nodes.Length - 1][nodeIndex]; foreach(Connection toOutputCon in curNode.GetIncommingConnections()) { double preCalc = CalcOutputInfuence(toOutputCon, curTarget, curActual); ConnectionInfluence[toOutputCon][microBatchIndex] = preCalc; } } LogProcess("Set output influence values"); //Fill ConnectionInfluence values foreach(Connection connection in AllConnections) { GetConnectionInfluence(connection, microBatchIndex); } LogProcess("Fill ConnectionInfluence values"); }
public void Train(InputExpectedResult[] expected) { for(int batchNr = 0; batchNr * MicroBatchSize < expected.Length; batchNr++) { //Reset influence values foreach(var key in AllConnections) { ConnectionInfluence[key] = new double?[MicroBatchSize]; } LogProcess("Reset influence values"); Parallel.For(0, MicroBatchSize, (batchIndex) => { if((batchNr * MicroBatchSize) + batchIndex < expected.Length) { AdjustWeights(expected[(batchNr * MicroBatchSize) + batchIndex], batchIndex); } }); //Update weights foreach(var con in AllConnections) { var conInfPair = ConnectionInfluence[con]; double outputInfluence = conInfPair.Sum(d => (d ?? 0) * con.FromNode.Output); double deltaWeight = -LearningRate * outputInfluence; con.Weight += deltaWeight; } LogProcess("Update weights"); } }