/// <summary>
        /// Returns the quadratic cost of the test case for all inputs using:
        /// Cost = ((Expected - Actual)^2) ==> Take the average of all costs.
        /// </summary>
        /// <param name="testCase">The training iteration to calculate the cost for.</param>
        /// <returns>Returns the cost of the training iteration.</returns>
        private double CalculateCost(INetworkTrainingIteration testCase)
        {
            var neuronOutputs = GetNeuronOutputs();

            testCase.Outputs.ForEach(t =>
            {
                // Update the actual activation level of each test case.
                t.ActivationLevel = neuronOutputs.First(n => n.NeuronId == t.NeuronId).ActivationLevel;
            });

            return(testCase.Outputs.Sum(t => Math.Pow(t.ActivationLevel - t.ExpectedActivationLevel, 2)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates and returns a neural network using configuration settings in the <paramref name="networkConfiguration"/> and the <paramref name="trainingEntry"/>.
        /// </summary>
        /// <param name="networkConfiguration"></param>
        /// <param name="trainingDatasetEntries"></param>
        /// <returns>Returns a neural network using configuration settings in the <paramref name="networkConfiguration"/> and the <paramref name="trainingEntry"/>.</returns>
        private IDFFNeuralNetwork CreateNetwork(N networkConfiguration, INetworkTrainingIteration trainingEntry)
        {
            if (trainingEntry == null || trainingEntry.Inputs == null || trainingEntry.Outputs == null)
            {
                throw new ArgumentNullException("trainingEntry");
            }

            var numInputs             = trainingEntry.Inputs.Count();
            var numOutputs            = trainingEntry.Outputs.Count();
            var numHiddenLayers       = networkConfiguration.NumHiddenLayers;
            var numHiddenLayerNeurons = networkConfiguration.NumHiddenLayerNeurons;

            // Setup and randomize network.
            var network = new DFFNeuralNetwork(numInputs, numHiddenLayers, numHiddenLayerNeurons, numOutputs);

            network.RandomizeNetwork();

            return(network);
        }