Exemple #1
0
        /// <summary>
        /// Calculates the value for this neuron
        /// </summary>
        /// <param name="prevVals">The values from the layer before the current one</param>
        public void forward(float[] prevVals)
        {
            inputs = (float[])prevVals.Clone();
            value  = CpuFuncs.sigmoid(CpuFuncs.inner_product(weights, inputs));

            if (isOutput) //linear if output
            {
                value = CpuFuncs.inner_product(weights, inputs);
            }
        }
Exemple #2
0
        /// <summary>
        /// Calculates the gradient for this neuron.
        /// This is only used in the backwards training phase.
        /// </summary>
        /// <param name="goal">Expected value of this neuron (gradient or goal value)</param>
        /// <param name="nextWeight">Null if output neuron, otherwise equals to weights to this neuron from layer after it.</param>
        public void calcGradient(float goal, float[] nextWeight)
        {
            float derivitive = CpuFuncs.sigmoid_prime(value);

            if (isOutput)
            {
                gradient = (goal - value);
            }
            else
            {
                float sum = 0.0f;
                for (int i = 0; i < nextWeight.Length; i++)
                {
                    sum += goal * nextWeight[i];
                }

                gradient = derivitive * sum;
            }
        }