예제 #1
0
        /// <summary>
        /// Trains the <paramref name="network"/> using <paramref name="trainingDatasetEntries"/> and return the average training cost of the final iteration.
        /// </summary>
        /// <param name="network">The neural network that is to be trained.</param>
        /// <param name="trainingDatasetEntries">The training iterations to train the network with.</param>
        /// <returns>Returns the average training cost of the final iteration.</returns>
        private IDFFNeuralNetwork TrainNetwork(IDFFNeuralNetwork network, IList <INetworkTrainingIteration> trainingDatasetEntries)
        {
            var priorTrainingCost = 999.0;
            var trainingIteration = 0;

            while (true)
            {
                trainingDatasetEntries.Shuffle();

                // TODO: Implement Clone() method for NeuralNetwork and store the BEST network.
                var trainingCost = network.Train(trainingDatasetEntries).Average(i => i.TrainingCost);

                Console.WriteLine($"{trainingIteration} : {trainingCost}");

                // Check the training cost every 500 iterations to ensure it's continuing to improve
                if (trainingIteration % 500 == 0)
                {
                    if ((priorTrainingCost - trainingCost) < .01)
                    {
                        break;
                    }
                    else
                    {
                        priorTrainingCost = trainingCost;
                    }
                }


                trainingIteration++;
            }

            return(network);
        }
예제 #2
0
 public void Train_WithNullDataset_ThrowsException()
 {
     // Act
     _network.Train(null);
 }