예제 #1
0
 private void ClassifyLayer(FeedforwardLayer startfeedforwardLayer, FeedforwardLayer inputfeedforwardLayer, FeedforwardLayer endfeedforwardLayer)
 {
     double[,] weightMatrix      = null;
     double[,] inputWeightMatrix = null;
     foreach (var matrix in weightMatrixes)
     {
         if (matrix.Item1 == startfeedforwardLayer.Layer && matrix.Item2 == endfeedforwardLayer.Layer)
         {
             weightMatrix = matrix.Item3;
         }
         //if (startfeedforwardLayer != inputFeedforwardLayer)
         //{
         //    if (matrix.Item2 == endfeedforwardLayer.Layer && matrix.Item1 == inputfeedforwardLayer.Layer)
         //    {
         //        inputWeightMatrix = matrix.Item3;
         //    }
         //}
     }
     for (int i = 0; i < endfeedforwardLayer.Values.Count(); i++)
     {
         double summe = 0.0;
         for (int j = 0; j < startfeedforwardLayer.Values.Count(); j++)
         {
             summe += startfeedforwardLayer.Values[j] * weightMatrix[j, i];
         }
         //if (inputWeightMatrix != null)
         //{
         //    for (int j = 0; j < inputfeedforwardLayer.Values.Count(); j++)
         //    {
         //        summe += inputfeedforwardLayer.Values[j] * inputWeightMatrix[j, i];
         //    }
         //}
         endfeedforwardLayer.Values[i] = endfeedforwardLayer.ActivationFunction_.ActivationFunction(summe);
     }
 }
예제 #2
0
 public override void BuildWeightMatrixOutputLayer(FeedforwardLayer feedforwardLayer)
 {
     // input to output
     weightMatrixes.Add(new Tuple <int, int, double[, ]>(
                            0, hiddenLayerCounter, new double[inputFeedforwardLayer.Neurons, outputFeedforwardLayer.Neurons]));
     weightMatrixes.Add(new Tuple <int, int, double[, ]>(
                            hiddenLayerCounter - 1, hiddenLayerCounter, new double[lastFeedforwardLayer.Neurons, outputFeedforwardLayer.Neurons]));
 }
예제 #3
0
 public override void BuildWeightMatrix(FeedforwardLayer feedforwardLayer, FeedforwardLayer previousfeedforwardLayer)
 {
     // input ot actual hiddenlayer
     weightMatrixes.Add(new Tuple <int, int, double[, ]>(
                            0, hiddenLayerCounter, new double[inputFeedforwardLayer.Neurons, feedforwardLayer.Neurons]));
     weightMatrixes.Add(new Tuple <int, int, double[, ]>(
                            hiddenLayerCounter - 1, hiddenLayerCounter, new double[previousfeedforwardLayer.Neurons, feedforwardLayer.Neurons]));
 }
예제 #4
0
 // 0 - 1 - 2
 private void Backpropagate(FeedforwardLayer inputfeedforwardLayer,
                            FeedforwardLayer hiddenfeedforwardLayer, FeedforwardLayer outputfeedforwardLayer, int layer)
 {
     double[,] weightMatrix = null;
     double[,] outputMatrix = null;
     foreach (var matrix in weightMatrixes)
     {
         if (matrix.Item2 == hiddenfeedforwardLayer.Layer)
         {
             weightMatrix = matrix.Item3;
         }
         else if (matrix.Item2 == outputfeedforwardLayer.Layer)
         {
             outputMatrix = matrix.Item3;
         }
     }
     for (int i = 0; i < inputfeedforwardLayer.Values.Count(); i++)
     {
         for (int j = 0; j < hiddenfeedforwardLayer.Values.Count(); j++)
         {
             var oj       = hiddenfeedforwardLayer.Values[j];
             var oi       = inputfeedforwardLayer.Values[i];
             var sumSigma = 0.0;
             for (int outputNeuronCount = 0; outputNeuronCount < outputfeedforwardLayer.Sigmas.Length; outputNeuronCount++)
             {
                 sumSigma += outputfeedforwardLayer.Sigmas[outputNeuronCount] * outputMatrix[j, outputNeuronCount];
             }
             var sigmaj = oj * (1 - oj) * sumSigma;
             hiddenfeedforwardLayer.Sigmas[j] = sigmaj;
             var deltaWk = LearningRate * sigmaj * oi;
             weightMatrix[i, j] += deltaWk;
         }
     }
     if (hiddenFeedforwardLayers.Count > layer)
     {
         var inputFeedforwardLayer          = this.inputFeedforwardLayer;
         var hiddenFeedforwardLayersCounter = hiddenFeedforwardLayers.Count;
         if (hiddenFeedforwardLayersCounter - 1 == layer)
         {
             inputFeedforwardLayer = this.inputFeedforwardLayer;
         }
         else
         {
             inputFeedforwardLayer = hiddenFeedforwardLayers[hiddenFeedforwardLayersCounter - layer - 2];
         }
         var hiddenfeedforwardLayer1 = hiddenFeedforwardLayers[hiddenFeedforwardLayersCounter - layer - 1];
         var hiddenfeedforwardLayer2 = hiddenFeedforwardLayers[hiddenFeedforwardLayersCounter - layer];
         Backpropagate(inputFeedforwardLayer, hiddenfeedforwardLayer1, hiddenfeedforwardLayer2, ++layer);
     }
 }
예제 #5
0
 public override void AddHiddenLayer(FeedforwardLayer feedforwardLayer)
 {
     base.hiddenFeedforwardLayers.Add(feedforwardLayer);
     lastFeedforwardLayer = feedforwardLayer;
     if (hiddenLayerCounter == 1)
     {
         BuildWeightMatrix(feedforwardLayer);
     }
     else
     {
         BuildWeightMatrix(feedforwardLayer, base.hiddenFeedforwardLayers[hiddenLayerCounter - hiddenLayerCounter]);
     }
     hiddenLayerCounter++;
 }
예제 #6
0
        private double SummeDeltaK(FeedforwardLayer startfeedforwardLayer, int counter, int fromHiddenNeuron)
        {
            double[,] weightMatrix = null;
            foreach (var matrix in weightMatrixes)
            {
                if (matrix.Item2 == startfeedforwardLayer.Layer)
                {
                    weightMatrix = matrix.Item3;
                    break;
                }
            }
            double summe  = 0.0;
            var    wjk    = weightMatrix[counter, fromHiddenNeuron];
            var    deltak = startfeedforwardLayer.Sigmas[fromHiddenNeuron];

            summe += wjk * deltak;
            return(summe);
        }
예제 #7
0
 private void CalculateLayer(FeedforwardLayer startfeedforwardLayer, FeedforwardLayer endfeedforwardLayer)
 {
     double[,] weightMatrix = null;
     foreach (var matrix in weightMatrixes)
     {
         if (matrix.Item1 == startfeedforwardLayer.Layer)
         {
             weightMatrix = matrix.Item3;
         }
     }
     for (int i = 0; i < endfeedforwardLayer.Values.Count(); i++)
     {
         double summe = 0.0;
         for (int j = 0; j < startfeedforwardLayer.Values.Count(); j++)
         {
             summe += startfeedforwardLayer.Values[j] * weightMatrix[j, i]; //j, i];
         }
         endfeedforwardLayer.Values[i] = endfeedforwardLayer.ActivationFunction_.ActivationFunction(summe);
     }
 }
예제 #8
0
 private void Backpropagate(FeedforwardLayer startfeedforwardLayer,
                            FeedforwardLayer endfeedforwardLayer, double outputValue, int layer)
 {
     //FeedforwardLayer endfeedforwardLayer = hiddenFeedforwardLayers[0];
     double[,] weightMatrix = null;
     foreach (var matrix in weightMatrixes)
     {
         if (matrix.Item2 == startfeedforwardLayer.Layer)
         {
             weightMatrix = matrix.Item3;
             break;
         }
     }
     for (int i = 0; i < startfeedforwardLayer.Values.Count(); i++)
     {
         for (int j = 0; j < endfeedforwardLayer.Values.Count(); j++)
         {
             var tk     = (double)outputValue;
             var ok     = startfeedforwardLayer.Values[i];
             var oj     = endfeedforwardLayer.Values[j];
             var sigmak = ok * (1 - ok) * (tk - ok);
             startfeedforwardLayer.Sigmas[i] = sigmak;
             var deltaWk = LearningRate * sigmak * oj;
             weightMatrix[j, i] += deltaWk;
         }
     }
     if (endfeedforwardLayer.Layer > 0)
     {
         var inputFeedforwardLayer = this.inputFeedforwardLayer;
         if (hiddenFeedforwardLayers.Count > 1)
         {
             var hiddenLayerCounter = hiddenFeedforwardLayers.Count - 1;
             inputFeedforwardLayer = hiddenFeedforwardLayers[hiddenLayerCounter];
         }
         Backpropagate(inputFeedforwardLayer, endfeedforwardLayer, startfeedforwardLayer, ++layer);
     }
 }
예제 #9
0
 public override void BuildWeightMatrix(FeedforwardLayer feedforwardLayer)
 {
     weightMatrixes.Add(new Tuple <int, int, double[, ]>(
                            hiddenLayerCounter - 1, hiddenLayerCounter, new double[inputFeedforwardLayer.Neurons, feedforwardLayer.Neurons]));
 }
예제 #10
0
 public override void AddOutputLayer(FeedforwardLayer feedforwardLayer)
 {
     base.outputFeedforwardLayer = feedforwardLayer;
     BuildWeightMatrixOutputLayer(feedforwardLayer);
 }
예제 #11
0
 public override void AddInputLayer(FeedforwardLayer feedforwardLayer)
 {
     base.inputFeedforwardLayer = feedforwardLayer;
 }
예제 #12
0
 public abstract void BuildWeightMatrixOutputLayer(FeedforwardLayer feedforwardLayer);
예제 #13
0
 public abstract void BuildWeightMatrix(FeedforwardLayer feedforwardLayer, FeedforwardLayer previousfeedforwardLayer);
예제 #14
0
 public abstract void AddOutputLayer(FeedforwardLayer feedforwardLayer);
예제 #15
0
 public abstract void AddHiddenLayer(FeedforwardLayer feedforwardLayer);