Пример #1
0
        public void AddPattern(Pattern pattern)
        {
            if (pattern.Input.Count != _layers.InputLayer.Neurons.Count ||
                pattern.Output.Count != _layers.OutputLayer.Neurons.Count)
                throw new ArgumentException("The pattern must match the number of neurons in the input and output layers");

            _patterns.Add(pattern);
        }
Пример #2
0
 void SetInputLayer(Pattern pattern)
 {
     for (int i = 0; i < _layers.InputLayer.Neurons.Count; i++)
     {
         _layers.InputLayer.Neurons[i] = pattern.Input[i];
     }
 }
Пример #3
0
 void PrintError(Pattern pattern)
 {
     double error = 0.0;
     for (int num = 0; num < pattern.Output.Count; num++)
         error += pattern.Output[num] - _layers.OutputLayer.Neurons[num];
     error = error / pattern.Output.Count;
     Console.Out.WriteLine("Error = " + error);
 }
Пример #4
0
        void MoveForward(Pattern pattern)
        {
            this.SetInputLayer(pattern);

            for (int i = 0; i < _weights.Count; i++)
            {
                // Calculate Net.j = SUM.i  W.i.j * a.i + Bias.j
                double netInput = 0.0;

                for (int j = 0; j < _layers[i + 1].Neurons.Count; j++)
                {
                    for (int k = 0; k < _layers[i].Neurons.Count; k++)
                    {
                        netInput += _layers[i].Neurons[k] * _weights[i][k][j]; // +_layers[i + 1].Bias;
                    }

                    // Calculate a.j = f(Net.j)
                    _layers[i + 1].Neurons[j] = this.ActivationFunction(netInput);
                }
            }
        }
Пример #5
0
 void MoveBackward(Pattern pattern)
 {
     this.CalculateLearningDeltas(pattern);
     this.BackpropagateErrors();
 }
Пример #6
0
        void CalculateLearningDeltas(Pattern pattern)
        {
            List<double> outputDelta = _deltas[_deltas.Count - 1];

            for (int i = 0; i < _layers.OutputLayer.Neurons.Count; i++)
            {
                // Calculate error.k = t.p - a.k
                double error = pattern.Output[i] - _layers.OutputLayer.Neurons[i];

                // d.k = f'(Net.k) * error.k = a.k * (1 - a.k) * error.k
                outputDelta[i] = this.DeltaFunction(_layers.OutputLayer.Neurons[i]) * error;
            }
        }