Exemplo n.º 1
0
        /// <summary>
        /// Process one level.
        /// </summary>
        /// <param name="currentLevel">The level.</param>
        private void ProcessLevel(int currentLevel)
        {
            int fromLayerIndex = _layerIndex[currentLevel + 1];
            int toLayerIndex   = _layerIndex[currentLevel];
            int fromLayerSize  = _layerCounts[currentLevel + 1];
            int toLayerSize    = _layerFeedCounts[currentLevel];

            int index = _weightIndex[currentLevel];
            IActivationFunction activation = _flat
                                             .ActivationFunctions[currentLevel + 1];

            // handle weights
            int yi = fromLayerIndex;

            for (int y = 0; y < fromLayerSize; y++)
            {
                double output = _layerOutput[yi];
                double sum    = 0;
                int    xi     = toLayerIndex;
                int    wi     = index + y;
                for (int x = 0; x < toLayerSize; x++)
                {
                    _derivative[wi] += output * _layerDelta[xi];
                    sum             += _weights[wi] * _layerDelta[xi];
                    wi += fromLayerSize;
                    xi++;
                }

                _layerDelta[yi] = sum
                                  * (activation.DerivativeFunction(_layerSums[yi], _layerOutput[yi]));
                yi++;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Process one level.
        /// </summary>
        ///
        /// <param name="currentLevel">The level.</param>
        private void ProcessLevel(int currentLevel)
        {
            int fromLayerIndex = this.layerIndex[currentLevel + 1];
            int toLayerIndex   = this.layerIndex[currentLevel];
            int fromLayerSize  = this.layerCounts[currentLevel + 1];
            int toLayerSize    = this.layerFeedCounts[currentLevel];

            int index = this.weightIndex[currentLevel];
            IActivationFunction activation = this.network.ActivationFunctions[currentLevel + 1];

            // handle weights
            int yi = fromLayerIndex;

            for (int y = 0; y < fromLayerSize; y++)
            {
                double output = this.layerOutput[yi];
                double sum    = 0;
                int    xi     = toLayerIndex;
                int    wi     = index + y;
                for (int x = 0; x < toLayerSize; x++)
                {
                    this.gradients[wi] += output * this.layerDelta[xi];
                    sum += this.weights[wi] * this.layerDelta[xi];
                    wi  += fromLayerSize;
                    xi++;
                }

                this.layerDelta[yi] = sum
                                      * activation.DerivativeFunction(this.layerOutput[yi]);
                yi++;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculate the derivative.
        /// </summary>
        ///
        /// <param name="a">The activation function.</param>
        /// <param name="d">The value to calculate for.</param>
        /// <returns>The derivative.</returns>
        private static double CalcDerivative2(IActivationFunction a, double d)
        {
            var temp = new double[1];

            temp[0] = d;
            a.ActivationFunction(temp, 0, temp.Length);
            temp[0] = a.DerivativeFunction(temp[0], temp[0]);
            return(temp[0]);
        }
Exemplo n.º 4
0
 public void CalculateError(IActivationFunction af, double[] b, double[] a,
                            IMLData ideal, double[] actual, double[] error, double derivShift,
                            double significance)
 {
     for (int i = 0; i < actual.Length; i++)
     {
         double deriv = af.DerivativeFunction(b[i], a[i]);
         error[i] = (Math.Atan(ideal[i] - actual[i]) * significance) * deriv;
     }
 }
Exemplo n.º 5
0
 /// <inheritdoc />
 public void CalculateError(IActivationFunction af, double[] b, double[] a,
                            double[] ideal, double[] actual, double[] error, double derivShift,
                            double significance)
 {
     for (var i = 0; i < actual.Length; i++)
     {
         var deriv = af.DerivativeFunction(b[i], a[i]) + derivShift;
         error[i] = (ideal[i] - actual[i]) * significance * deriv;
     }
 }
Exemplo n.º 6
0
 /// <inheritdoc />
 public void CalculateError(IActivationFunction af, double[] b, double[] a,
     double[] ideal, double[] actual, double[] error, double derivShift,
     double significance)
 {
     for (var i = 0; i < actual.Length; i++)
     {
         var deriv = af.DerivativeFunction(b[i], a[i]) + derivShift;
         error[i] = (ideal[i] - actual[i])*significance*deriv;
     }
 }
        private void ProcessLevel(int currentLevel)
        {
            int    fromLayerIndex = _flat.LayerIndex[currentLevel + 1];
            int    toLayerIndex   = _flat.LayerIndex[currentLevel];
            int    fromLayerSize  = _flat.LayerCounts[currentLevel + 1];
            int    toLayerSize    = _flat.LayerFeedCounts[currentLevel];
            double dropoutRate    = 0;

            int index = _flat.WeightIndex[currentLevel];
            IActivationFunction activation = _flat
                                             .ActivationFunctions[currentLevel];

            // handle weights
            // array references are made method local to avoid one indirection
            double[] layerDelta  = _layerDelta;
            double[] weights     = _flat.Weights;
            double[] gradients   = _gradients;
            double[] layerOutput = _flat.LayerOutput;
            double[] layerSums   = _flat.LayerSums;
            int      yi          = fromLayerIndex;

            for (int y = 0; y < fromLayerSize; y++)
            {
                double output = layerOutput[yi];
                double sum    = 0;

                int wi      = index + y;
                int loopEnd = toLayerIndex + toLayerSize;

                for (int xi = toLayerIndex; xi < loopEnd; xi++, wi += fromLayerSize)
                {
                    gradients[wi] += output * layerDelta[xi];
                    sum           += weights[wi] * layerDelta[xi];
                }
                layerDelta[yi] = sum
                                 * (activation.DerivativeFunction(layerSums[yi], layerOutput[yi]));

                yi++;
            }
        }
 /// <summary>
 /// Calculate the derivative.
 /// </summary>
 /// <param name="a">The activation function.</param>
 /// <param name="d">The value to calculate for.</param>
 /// <returns>The derivative.</returns>
 private double CalcDerivative(IActivationFunction a, double d)
 {
     return a.DerivativeFunction(d);
 }
Exemplo n.º 9
0
 /// <summary>
 /// Calculate the derivative.
 /// </summary>
 /// <param name="a">The activation function.</param>
 /// <param name="d">The value to calculate for.</param>
 /// <returns>The derivative.</returns>
 private double CalcDerivative(IActivationFunction a, double d)
 {
     return(a.DerivativeFunction(d));
 }
Exemplo n.º 10
0
 private static double xd3eb00c1c38e3a49(IActivationFunction x19218ffab70283ef, double x73f821c71fe1e676)
 {
     return x19218ffab70283ef.DerivativeFunction(x73f821c71fe1e676, x73f821c71fe1e676);
 }
Exemplo n.º 11
0
 private static double xbc17cb206c45d25e(IActivationFunction x19218ffab70283ef, double x73f821c71fe1e676)
 {
     double[] d = new double[] { x73f821c71fe1e676 };
     x19218ffab70283ef.ActivationFunction(d, 0, d.Length);
     d[0] = x19218ffab70283ef.DerivativeFunction(d[0], d[0]);
     return d[0];
 }
Exemplo n.º 12
0
 /// <summary>
 /// Calculate the derivative.
 /// </summary>
 ///
 /// <param name="a">The activation function.</param>
 /// <param name="d">The value to calculate for.</param>
 /// <returns>The derivative.</returns>
 private static double CalcDerivative2(IActivationFunction a, double d)
 {
     var temp = new double[1];
     temp[0] = d;
     a.ActivationFunction(temp, 0, temp.Length);
     temp[0] = a.DerivativeFunction(temp[0],temp[0]);
     return temp[0];
 }