Esempio n. 1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivationLayer"/> class.
 /// </summary>
 /// 
 /// <param name="neuronsCount">Layer's neurons count.</param>
 /// <param name="inputsCount">Layer's inputs count.</param>
 /// <param name="function">Activation function of neurons of the layer.</param>
 /// 
 /// <remarks>The new layer is randomized (see <see cref="ActivationNeuron.Randomize"/>
 /// method) after it is created.</remarks>
 /// 
 public ActivationLayer( int neuronsCount, int inputsCount, IActivationFunction function )
     : base( neuronsCount, inputsCount )
 {
     // create each neuron
     for ( int i = 0; i < neurons.Length; i++ )
         neurons[i] = new ActivationNeuron( inputsCount, function );
 }
Esempio n. 2
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;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="ActivationLayer"/> class.
 /// </summary>
 ///
 /// <param name="neuronsCount">Layer's neurons count.</param>
 /// <param name="inputsCount">Layer's inputs count.</param>
 /// <param name="function">Activation function of neurons of the layer.</param>
 ///
 /// <remarks>The new layer is randomized (see <see cref="ActivationNeuron.Randomize"/>
 /// method) after it is created.</remarks>
 ///
 public ActivationLayer(int neuronsCount, int inputsCount, IActivationFunction function)
     : base(neuronsCount, inputsCount)
 {
     // create each neuron
     for (int i = 0; i < neurons.Length; i++)
     {
         neurons[i] = new ActivationNeuron(inputsCount, function);
     }
 }