Trains a neural network using a Levenberg Marquardt algorithm (LMA). This training technique is based on the mathematical technique of the same name. The LMA interpolates between the Gauss-Newton algorithm (GNA) and the method of gradient descent (similar to what is used by backpropagation. The lambda parameter determines the degree to which GNA and Gradient Descent are used. A lower lambda results in heavier use of GNA, whereas a higher lambda results in a heavier use of gradient descent. Each iteration starts with a low lambda that builds if the improvement to the neural network is not desirable. At some point the lambda is high enough that the training method reverts totally to gradient descent. This allows the neural network to be trained effectively in cases where GNA provides the optimal training time, but has the ability to fall back to the more primitive gradient descent method LMA finds only a local minimum, not a global minimum. References: C. R. Souza. (2009). Neural Network Learning by the Levenberg-Marquardt Algorithm with Bayesian Regularization. Website, available from: http://crsouza.blogspot.com/2009/11/neural-network-learning-by-levenberg_18.html http://www.heatonresearch.com/wiki/LMA http://en.wikipedia.org/wiki/Levenberg%E2%80%93Marquardt_algorithm http://en.wikipedia.org/wiki/Finite_difference_method http://mathworld.wolfram.com/FiniteDifference.html http://www-alg.ist.hokudai.ac.jp/~jan/alpha.pdf - http://www.inference.phy.cam.ac.uk/mackay/Bayes_FAQ.html
Inheritance: Encog.ML.Train.BasicTraining, IMultiThreadable
        public void TestLMA()
        {
            IMLDataSet trainingData = new BasicMLDataSet(XOR.XORInput, XOR.XORIdeal);

            BasicNetwork network = NetworkUtil.CreateXORNetworkUntrained();
            IMLTrain rprop = new LevenbergMarquardtTraining(network, trainingData);
            NetworkUtil.TestTraining(rprop, 0.03);
        }
        public void Execute(IExampleInterface app)
        {
            IMLDataSet trainingData = GenerateTraining(InputOutputCount, Compl);
            IMLMethod method = EncogUtility.SimpleFeedForward(InputOutputCount,
                                                              HiddenCount, 0, InputOutputCount, false);
            var train = new LevenbergMarquardtTraining((BasicNetwork) method, trainingData);
            EncogUtility.TrainToError(train, 0.01);

            EncogFramework.Instance.Shutdown();
        }
        /// <summary>
        /// Create a LMA 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)
        {
            if (!(method is BasicNetwork))
            {
                throw new EncogError(
                    "LMA training cannot be used on a method of type: "
                    + method.GetType().FullName);
            }

            IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr);
            var holder = new ParamsHolder(args);

            var result = new LevenbergMarquardtTraining(
                (BasicNetwork) method, training);
            return result;
        }
        /// <summary>
        /// Create a LMA 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)
        {
            if (!(method is BasicNetwork))
            {
                throw new EncogError(
                    "LMA training cannot be used on a method of type: "
                    + method.GetType().FullName);
            }

            IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr);
            var holder = new ParamsHolder(args);
            bool useReg = holder.GetBoolean(
                MLTrainFactory.PropertyBayesianRegularization, false, false);

            var result = new LevenbergMarquardtTraining(
                (BasicNetwork) method, training) {UseBayesianRegularization = useReg};
            return result;
        }
Exemple #5
0
 public IMLTrain Create(IMLMethod method, IMLDataSet training, string argsStr)
 {
     bool flag;
     LevenbergMarquardtTraining training3;
     if (method is BasicNetwork)
     {
         flag = new ParamsHolder(ArchitectureParse.ParseParams(argsStr)).GetBoolean("BAYES_REG", false, false);
         training3 = new LevenbergMarquardtTraining((BasicNetwork) method, training);
         if (3 == 0)
         {
             LevenbergMarquardtTraining training2;
             return training2;
         }
     }
     else if (0 == 0)
     {
         throw new EncogError("LMA training cannot be used on a method of type: " + method.GetType().FullName);
     }
     training3.UseBayesianRegularization = flag;
     if (0 == 0)
     {
     }
     return training3;
 }
        public void Train(BasicNetwork network, IMLDataSet training)
        {
            IMLTrain trainMain = new LevenbergMarquardtTraining(network, training);
            // train the neural network

            var stop = new StopTrainingStrategy();

            ICalculateScore score = new TrainingSetScore(trainMain.Training);
            IMLTrain trainAlt = new NeuralSimulatedAnnealing(network, score, 10, 2, 100);
            trainMain.AddStrategy(new HybridStrategy(trainAlt));
            trainMain.AddStrategy(stop);

            int epoch = 0;
            while (!stop.ShouldStop() && trainMain.IterationNumber < 1500)
            {
                trainMain.Iteration();
                Console.WriteLine("Training " +  ", Epoch #" + epoch + " Error:" + trainMain.Error);
                epoch++;
            }
        }
        private double TrainNetwork(String what, BasicNetwork network, IMLDataSet trainingSet, string Method)
        {
            // train the neural network
            ICalculateScore score = new TrainingSetScore(trainingSet);
            IMLTrain trainAlt = new NeuralSimulatedAnnealing(network, score, 10, 2, 100);
            IMLTrain trainMain;
            if (Method.Equals("Leven"))
            {
                Console.WriteLine("Using LevenbergMarquardtTraining");
                trainMain = new LevenbergMarquardtTraining(network, trainingSet);
            }
            else
                 trainMain = new Backpropagation(network, trainingSet);

            var stop = new StopTrainingStrategy();
            trainMain.AddStrategy(new Greedy());
            trainMain.AddStrategy(new HybridStrategy(trainAlt));
            trainMain.AddStrategy(stop);

            int epoch = 0;
            while (!stop.ShouldStop())
            {
                trainMain.Iteration();
                app.WriteLine("Training " + what + ", Epoch #" + epoch + " Error:" + trainMain.Error);
                epoch++;
            }
            return trainMain.Error;
        }