Наследование: Encog.ML.Train.BasicTraining
Пример #1
0
        public void Execute(IExampleInterface app)
        {
            // create a neural network, without using a factory
            var svm = new SupportVectorMachine(1,true); // 1 input, & true for regression

            // create training data
            IMLDataSet trainingSet = new BasicMLDataSet(RegressionInput, RegressionIdeal);

            // train the SVM
            IMLTrain train = new SVMSearchTrain(svm, trainingSet);

            int epoch = 1;

            do
            {
                train.Iteration();
                Console.WriteLine(@"Epoch #" + epoch + @" Error:" + train.Error);
                epoch++;
            } while (train.Error > 0.01);

            // test the SVM
            Console.WriteLine(@"SVM Results:");
            foreach (IMLDataPair pair in trainingSet)
            {
                IMLData output = svm.Compute(pair.Input);
                Console.WriteLine(pair.Input[0]
                                  + @", actual=" + output[0] + @",ideal=" + pair.Ideal[0]);
            }
        }
Пример #2
0
        public override void TrainNetwork()
        {
            IMLTrain train = new SVMSearchTrain(Svm, TrainingSet);

            var iteration = 1;

            var errors = new List<double[]>();

            do
            {
                train.Iteration();

                errors.Add(new[] { -1, iteration, train.Error });

                Console.WriteLine(@"Iteration #" + iteration++ + @" Training error:" + train.Error);

            } while ((iteration < Parameters.IterationsCount) && (train.Error > Parameters.AcceptedError));

            train.FinishTraining();

            ErrorSet = errors.ToArray();
        }
            public static SupportVectorMachine SVMSearch(SupportVectorMachine anetwork, IMLDataSet training)
            {
                SVMSearchTrain bestsearch = new SVMSearchTrain(anetwork, training);
                StopTrainingStrategy stop = new StopTrainingStrategy(0.00000000001, 1);
                bestsearch.AddStrategy(stop);
                while (bestsearch.IterationNumber < 30 && !stop.ShouldStop())
                {
                bestsearch.Iteration();
                Console.WriteLine("Iteration #" + bestsearch.IterationNumber + " Error :" + bestsearch.Error);
                }

                bestsearch.FinishTraining();

                   return anetwork;
            }
        /// <summary>
        /// Create a SVM 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 SupportVectorMachine))
            {
                throw new EncogError(
                    "SVM Train training cannot be used on a method of type: "
                    + method.GetType().FullName);
            }

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

            var holder = new ParamsHolder(args);
            double gammaStart = holder.GetDouble(
                PropertyGamma1, false,
                SVMSearchTrain.DefaultGammaBegin);
            double cStart = holder.GetDouble(PropertyC1,
                                             false, SVMSearchTrain.DefaultConstBegin);
            double gammaStop = holder.GetDouble(
                PropertyGamma2, false,
                SVMSearchTrain.DefaultGammaEnd);
            double cStop = holder.GetDouble(PropertyC2,
                                            false, SVMSearchTrain.DefaultConstEnd);
            double gammaStep = holder.GetDouble(
                PropertyGammaStep, false,
                SVMSearchTrain.DefaultGammaStep);
            double cStep = holder.GetDouble(PropertyCStep,
                                            false, SVMSearchTrain.DefaultConstStep);

            var result = new SVMSearchTrain((SupportVectorMachine) method, training)
                             {
                                 GammaBegin = gammaStart,
                                 GammaEnd = gammaStop,
                                 GammaStep = gammaStep,
                                 ConstBegin = cStart,
                                 ConstEnd = cStop,
                                 ConstStep = cStep
                             };

            return result;
        }
Пример #5
0
 public IMLTrain Create(IMLMethod method, IMLDataSet training, string argsStr)
 {
     ParamsHolder holder;
     double num;
     double num2;
     double num3;
     double num4;
     double num5;
     double num6;
     SVMSearchTrain train2;
     if (method is SupportVectorMachine)
     {
         IDictionary<string, string> theParams = ArchitectureParse.ParseParams(argsStr);
         new ParamsHolder(theParams);
         if ((((uint) num3) - ((uint) num4)) < 0)
         {
             goto Label_0053;
         }
         if ((((uint) num2) + ((uint) num6)) <= uint.MaxValue)
         {
             holder = new ParamsHolder(theParams);
             num = holder.GetDouble("GAMMA1", false, -10.0);
             num2 = holder.GetDouble("C1", false, -5.0);
             goto Label_0101;
         }
         goto Label_016E;
     }
     goto Label_0185;
     Label_0053:
     train2.GammaEnd = num3;
     if ((((uint) num5) + ((uint) num)) > uint.MaxValue)
     {
         goto Label_0185;
     }
     train2.GammaStep = num5;
     if (((uint) num3) >= 0)
     {
         train2.ConstBegin = num2;
         train2.ConstEnd = num4;
         if ((((uint) num4) | 3) != 0)
         {
             train2.ConstStep = num6;
             return train2;
         }
     }
     else
     {
         return train2;
     }
     Label_0101:
     num3 = holder.GetDouble("GAMMA2", false, 10.0);
     num4 = holder.GetDouble("C2", false, 15.0);
     Label_016E:
     if (((uint) num4) <= uint.MaxValue)
     {
         num5 = holder.GetDouble("GAMMASTEP", false, 1.0);
         num6 = holder.GetDouble("CSTEP", false, 2.0);
         train2 = new SVMSearchTrain((SupportVectorMachine) method, training) {
             GammaBegin = num
         };
     }
     goto Label_0053;
     Label_0185:
     throw new EncogError("SVM Train training cannot be used on a method of type: " + method.GetType().FullName);
 }