/// <summary> /// Invokes EndEpochEvent /// </summary> /// <param name="currentIteration"> /// Current training iteration /// </param> /// <param name="trainingSet"> /// Training set which got trained successfully this epoch /// </param> protected virtual void OnEndEpoch(int currentIteration, Ajusteentrenamiento trainingSet) { if (EndEpochEvent != null) { EndEpochEvent(this, new TrainingEpochEventArgs(currentIteration, trainingSet)); } }
/// <summary> /// Trains the neural network for the given training set (Batch Training) /// </summary> /// <param name="trainingSet"> /// The training set to use /// </param> /// <param name="trainingEpochs"> /// Number of training epochs. (All samples are trained in some random order, in every /// training epoch) /// </param> /// <exception cref="ArgumentNullException"> /// if <c>trainingSet</c> is <c>null</c> /// </exception> /// <exception cref="ArgumentException"> /// if <c>trainingEpochs</c> is zero or negative /// </exception> public virtual void Learn(Ajusteentrenamiento trainingSet, int trainingEpochs) { // Validate Helper.ValidateNotNull(trainingSet, "trainingSet"); Helper.ValidatePositive(trainingEpochs, "trainingEpochs"); if ((trainingSet.InputVectorLength != inputLayer.NeuronCount) || (trainingMethod == TrainingMethod.Supervised && trainingSet.OutputVectorLength != outputLayer.NeuronCount) || (trainingMethod == TrainingMethod.Unsupervised && trainingSet.OutputVectorLength != 0)) { throw new ArgumentException("Invalid training set"); } // Reset isStopping isStopping = false; // Re-Initialize the network Initialize(); for (int currentIteration = 0; currentIteration < trainingEpochs; currentIteration++) { int[] randomOrder = Helper.GetRandomOrder(trainingSet.TrainingSampleCount); // Beginning a new training epoch OnBeginEpoch(currentIteration, trainingSet); // Check for Jitter Epoch if (jitterEpoch > 0 && currentIteration % jitterEpoch == 0) { for (int i = 0; i < connectors.Count; i++) { connectors[i].Jitter(jitterNoiseLimit); } } for (int index = 0; index < trainingSet.TrainingSampleCount; index++) { Entrenamiento randomSample = trainingSet[randomOrder[index]]; // Learn a random training sample OnBeginSample(currentIteration, randomSample); LearnSample(trainingSet[randomOrder[index]], currentIteration, trainingEpochs); OnEndSample(currentIteration, randomSample); // Check if we need to stop if (isStopping) { isStopping = false; return; } } // Training Epoch successfully complete OnEndEpoch(currentIteration, trainingSet); // Check if we need to stop if (isStopping) { isStopping = false; return; } } }
/// <summary> /// Creates a new instance of training epoch event arguments /// </summary> /// <param name="trainingIteration"> /// Current training iteration /// </param> /// <param name="trainingSet"> /// The training set associated with the event /// </param> public TrainingEpochEventArgs(int trainingIteration, Ajusteentrenamiento trainingSet) { this.trainingSet = trainingSet; this.trainingIteration = trainingIteration; }