/// <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; } }