protected override void NoErrorAtCurrentIteration(VectorComputationContext context) { var ctx = (NeuralComputationContext)context; if (savedErrorVectors != null) // aka BPTT { // Push null vector: savedErrorVectors.PushNull(ctx); } else if (GCAlgo == GradientComputingAlgorithm.RTLR) { // Compute P Values: Network.PropagatePValues(ctx, null); } }
protected override void DoExecuteVectorFlow(VectorComputationContext context, VectorBuffer<float> vectorBuffer, Core.Vectors.VectorFlow<float> vectorFlow) { var ctx = (NeuralComputationContext)context; if (Network.IsRecurrent) Network.Reset(ctx, NeuralNetworkResetTarget.Outputs); base.DoExecuteVectorFlow(context, vectorBuffer, vectorFlow); }
protected override void ComputeError(VectorComputationContext context, BufferedVector<float> desiredOutputVector, int entryIndex, int entryCount) { var ctx = (NeuralComputationContext)context; base.ComputeError(context, desiredOutputVector, entryIndex, entryCount); // ErrorBuffer contains the error vector bool callAlgo = true; if ((Network.StructuralElementFlags & NNStructuralElement.BackwardImplementation) != 0) // aka BP or BPTT { callAlgo = BP_ErrorBasedComputed(ctx, entryIndex, entryCount); } else if (GCAlgo == GradientComputingAlgorithm.RTLR) { RTLR_ErrorBasedComputed(ctx); } if (callAlgo) CallErrorBasedStochasticLearningAlgorithms(ctx); }
// Each vector iteration: protected override void Iteration(VectorComputationContext context) { var ctx = (NeuralComputationContext)context; if (savedErrorVectors != null) // aka BPTT { Network.CallBeforeIterationLearningAlgorithms(ctx, ctx.Training_BeginOfBatch); Network.Iteration(ctx, true, ctx.Training_BPTTEllapsedForwardIterationCount++); } else { Network.CallBeforeIterationLearningAlgorithms(ctx, ctx.Training_BeginOfBatch); Network.Iteration(ctx, true); } }
// A Flow: protected override void DoExecuteVectorFlow(VectorComputationContext context, VectorBuffer<float> vectorBuffer, VectorFlow<float> vectorFlow) { var ctx = (NeuralComputationContext)context; if (Mode == TrainingMode.Unordered) { // Reset forward values: ResetNetworkValues(ctx); // Reset backward errors and gradients: // If beginOfBatch == true, // backward errors and gradients already reseted by a ResetBackwardValues() call if (!ctx.Training_BeginOfBatch) { ResetPartialGradientComputingValues(ctx); } } // Begin of recurrent flow: ctx.Training_BPTTEllapsedForwardIterationCount = 0; base.DoExecuteVectorFlow(context, vectorBuffer, vectorFlow); ctx.Training_BeginOfBatch = false; }
// Batch Iteration: protected override void ExecuteBatchIteration(VectorComputationContext context, VectorBuffer<float> vectorBuffer, VectorFlowBatch<float> batch) { var ctx = (NeuralComputationContext)context; // Begin of batch: ctx.Training_BeginOfBatch = true; if (Mode == TrainingMode.Unordered) { // Reset backward values, and clear error information: ResetGradientComputingValues(ctx); ctx.Training_NumberOfIterationsInBatch = 0; } base.ExecuteBatchIteration(context, vectorBuffer, batch); // Batch done, iterate algos: Network.CallErrorBasedBatchLearningAlgorithms(ctx, ctx.Training_NumberOfIterationsInBatch, AverageErrorBuffer); }
// Batch Iterations (all repeated): protected override void DoExecuteBatch(VectorComputationContext context, VectorBuffer<float> vectorBuffer, VectorFlowBatch<float> batch) { // This is where batch iterations begins var ctx = (NeuralComputationContext)context; EnsureInitialized(ctx); var neuralBatch = batch as NeuralVectorFlowBatch; if (neuralBatch != null && Mode == TrainingMode.Streamed && neuralBatch.ResetSchedule == ResetSchedule.BeforeExecution) { // Streamed reset scheduled: ResetAll(ctx); } base.DoExecuteBatch(context, vectorBuffer, batch); if (neuralBatch != null && Mode == TrainingMode.Streamed && neuralBatch.ResetSchedule == ResetSchedule.AfterExecution) { // Streamed reset scheduled: ResetAll(ctx); } }