Beispiel #1
0
        /// <summary>
        /// A protected helper function used to train single learning sample
        /// </summary>
        /// <param name="trainingSample">
        /// Training sample to use
        /// </param>
        /// <param name="currentIteration">
        /// Current training epoch (Assumed to be positive and less than <c>trainingEpochs</c>)
        /// </param>
        /// <param name="trainingEpochs">
        /// Number of training epochs (Assumed to be positive)
        /// </param>
        protected override void LearnSample(TrainingSample trainingSample, int currentIteration, int trainingEpochs)
        {
            // No validation here
            int layerCount = layers.Count;

            // Set input vector
            inputLayer.SetInput(trainingSample.InputVector);

            for (int i = 0; i < layerCount; i++)
            {
                layers[i].Run();
            }

            // Set Errors
            meanSquaredError += (outputLayer as ActivationLayer).SetErrors(trainingSample.OutputVector);

            // Backpropagate errors
            for (int i = layerCount; i > 0;)
            {
                ActivationLayer layer = layers[--i] as ActivationLayer;
                if (layer != null)
                {
                    layer.EvaluateErrors();
                }
            }

            // Optimize synapse weights and neuron bias values
            for (int i = 0; i < layerCount; i++)
            {
                layers[i].Learn(currentIteration, trainingEpochs);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a new activation neuron
        /// </summary>
        /// <param name="parent">
        /// The parent layer containing this neuron
        /// </param>
        /// <exception cref="System.ArgumentNullException">
        /// If <c>parent</c> is <c>null</c>
        /// </exception>
        public ActivationNeuron(ActivationLayer parent)
        {
            Helper.ValidateNotNull(parent, "parent");

            this.input  = 0d;
            this.output = 0d;
            this.error  = 0d;
            this.bias   = 0d;
            this.parent = parent;
        }
Beispiel #3
0
 /// <summary>
 /// Creates a new Back Propagation Network, with the specified input and output layers. (You
 /// are required to connect all layers using appropriate synapses, before using the constructor.
 /// Any changes made to the structure of the network after its creation may lead to complete
 /// malfunctioning)
 /// </summary>
 /// <param name="inputLayer">
 /// The input layer
 /// </param>
 /// <param name="outputLayer">
 /// The output layer
 /// </param>
 /// <exception cref="ArgumentNullException">
 /// If <c>inputLayer</c> or <c>outputLayer</c> is <c>null</c>
 /// </exception>
 public BackpropagationNetwork(ActivationLayer inputLayer, ActivationLayer outputLayer)
     : base(inputLayer, outputLayer, TrainingMethod.Supervised)
 {
     this.meanSquaredError = 0d;
     this.isValidMSE       = false;
 }