Accord.Neuro.ActivationNeuron.Randomize C# (CSharp) Method

Randomize() public method

Randomize neuron.
Calls base class Randomize method to randomize neuron's weights and then randomizes threshold's value.
public Randomize ( ) : void
return void
        public override void Randomize()
        {
            // randomize weights
            base.Randomize();

            // randomize threshold
            threshold = rand.Generate();
        }

Usage Example

Example #1
0
        /// <summary>
        ///   Randomizes (initializes) the weights of
        ///   the network using Nguyen-Widrow method's.
        /// </summary>
        ///
        public void Randomize(int layerIndex)
        {
            Neuron.RandRange = randRange;

            for (int j = 0; j < network.Layers[layerIndex].Neurons.Length; j++)
            {
                ActivationNeuron neuron = network.Layers[layerIndex].Neurons[j] as ActivationNeuron;

                neuron.Randomize();

                double norm = 0.0;

                // Calculate the Euclidean Norm for the weights
                for (int k = 0; k < neuron.Weights.Length; k++)
                {
                    norm += neuron.Weights[k] * neuron.Weights[k];
                }
                norm += neuron.Threshold * neuron.Threshold;

                norm = System.Math.Sqrt(norm);

                // Rescale the weights using beta and the norm
                for (int k = 0; k < neuron.InputsCount; k++)
                {
                    neuron.Weights[k] = beta * neuron.Weights[k] / norm;
                }
                neuron.Threshold = beta * neuron.Threshold / norm;
            }
        }