Implementation of Nguyen-Widrow weight initialization. This is the default weight initialization used by Encog, as it generally provides the most trainable neural network.
Inheritance: IRandomizer
示例#1
0
        /// <summary>
        /// Create a PSO trainer.
        /// </summary>
        /// <param name="method">The method to use.</param>
        /// <param name="training">The training data to use.</param>
        /// <param name="argsStr">The arguments to use.</param>
        /// <returns>The newly created trainer.</returns>
        public IMLTrain Create(IMLMethod method,
                IMLDataSet training, String argsStr)
        {
            IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr);
            ParamsHolder holder = new ParamsHolder(args);

            int particles = holder.GetInt(
                    MLTrainFactory.PropertyParticles, false, 20);

            ICalculateScore score = new TrainingSetScore(training);
            IRandomizer randomizer = new NguyenWidrowRandomizer();

            IMLTrain train = new NeuralPSO((BasicNetwork)method, randomizer, score, particles);

            return train;
        }
        /// <summary>
        /// Program entry point.
        /// </summary>
        /// <param name="app">Holds arguments and other info.</param>
        public void Execute(IExampleInterface app)
        {
            IMLDataSet trainingSet = new BasicMLDataSet(XORInput, XORIdeal);
            BasicNetwork network = EncogUtility.SimpleFeedForward(2, 2, 0, 1, false);
            ICalculateScore score = new TrainingSetScore(trainingSet);
            IRandomizer randomizer = new NguyenWidrowRandomizer();

            IMLTrain train = new NeuralPSO(network, randomizer, score, 20);

            EncogUtility.TrainToError(train, 0.01);

            network = (BasicNetwork)train.Method;

            // test the neural network
            Console.WriteLine("Neural Network Results:");
            EncogUtility.Evaluate(network, trainingSet);

            EncogFramework.Instance.Shutdown();
        }
        public void Execute(IExampleInterface app)
        {
            var rangeRandom = new RangeRandomizer(-1, 1);
            var nwrRandom = new NguyenWidrowRandomizer(-1, 1);
            var fanRandom = new FanInRandomizer();
            var gaussianRandom = new GaussianRandomizer(0, 1);

            var training = new BasicMLDataSet(XOR_INPUT,
                                              XOR_IDEAL);
            BasicNetwork network = EncogUtility.SimpleFeedForward(2, 10, 0, 1, true);

            Console.WriteLine("Range random: "
                              + EvaluateRandomizer(rangeRandom, network, training));
            Console.WriteLine("Nguyen-Widrow: "
                              + EvaluateRandomizer(nwrRandom, network, training));
            Console.WriteLine("Fan-In: "
                              + EvaluateRandomizer(fanRandom, network, training));
            Console.WriteLine("Gaussian: "
                              + EvaluateRandomizer(gaussianRandom, network, training));
        }