Inheritance: Encog.ML.Train.BasicTraining
        /// <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);
            }

            double defaultGamma = 1.0d/((SupportVectorMachine) method).InputCount;
            double defaultC = 1.0d;

            IDictionary<String, String> args = ArchitectureParse.ParseParams(argsStr);
            var holder = new ParamsHolder(args);
            double gamma = holder.GetDouble(MLTrainFactory.PropertyGamma,
                                            false, defaultGamma);
            double c = holder.GetDouble(MLTrainFactory.PropertyC, false,
                                        defaultC);

            var result = new SVMTrain((SupportVectorMachine) method, training);
            result.Gamma = gamma;
            result.C = c;
            return result;
        }
Exemple #2
0
 public SVMSearchTrain(SupportVectorMachine method, IMLDataSet training)
     : base(TrainingImplementationType.Iterative)
 {
     this._x9425fdc2df7bcafc = 0;
     this._x2350dfd8c7639ed6 = -5.0;
     this._x38c942a9bdfcbac4 = 2.0;
     while (true)
     {
         if (3 != 0)
         {
             this._xdee5cbd981b6d49e = 15.0;
             if (0 == 0)
             {
                 this._xec9380575da42aee = -10.0;
             }
         }
         this._xd522fee165affb59 = 10.0;
         this._x441f2c3a7d69c688 = 1.0;
         this._x87a7fc6a72741c2e = method;
         this.Training = training;
         this._x9eeb587621db687c = false;
         if (0 == 0)
         {
             if (0 == 0)
             {
                 this._xab248fa87e95a7df = false;
                 this._x1e074b5762f8595b = new SVMTrain(this._x87a7fc6a72741c2e, training);
                 return;
             }
             return;
         }
     }
 }
Exemple #3
0
 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);
     }
     double defaultValue = 1.0 / ((double) ((SupportVectorMachine) method).InputCount);
     while (true)
     {
         double num4;
         SVMTrain train;
         double num2 = 1.0;
         IDictionary<string, string> theParams = ArchitectureParse.ParseParams(argsStr);
         ParamsHolder holder = new ParamsHolder(theParams);
         double num3 = holder.GetDouble("GAMMA", false, defaultValue);
         do
         {
             num4 = holder.GetDouble("C", false, num2);
             train = new SVMTrain((SupportVectorMachine) method, training) {
                 Gamma = num3
             };
         }
         while (((uint) defaultValue) > uint.MaxValue);
         if ((((uint) num2) + ((uint) num3)) <= uint.MaxValue)
         {
             train.C = num4;
             return train;
         }
     }
 }
        /// <summary>
        /// Trains a random trainer.
        /// </summary>
        /// <param name="inputs">The inputs.</param>
        /// <param name="predictWindow">The predict window.</param>
        public static void RandomTrainerMethod(int inputs, int predictWindow)
        {
            double[] firstinput = MakeInputs(inputs);
            double[] SecondInput = MakeInputs(inputs);
            double[] ThirdInputs = MakeInputs(inputs);
            double[] FourthInputs = MakeInputs(inputs);
            var pair = SuperUtilsTrainer.ProcessPairs(firstinput, FourthInputs, inputs, predictWindow);
            var pair2 = SuperUtilsTrainer.ProcessPairs(SecondInput, FourthInputs, inputs, predictWindow);
            var pair3 = SuperUtilsTrainer.ProcessPairs(ThirdInputs, FourthInputs, inputs, predictWindow);
            var pair4 = SuperUtilsTrainer.ProcessPairs(FourthInputs, FourthInputs, inputs, predictWindow);
            BasicMLDataSet SuperSet = new BasicMLDataSet();
            SuperSet.Add(pair);
            SuperSet.Add(pair2);
            SuperSet.Add(pair3);
            SuperSet.Add(pair4);

            SupportVectorMachine machine = Create(SuperSet, inputs);
            SVMTrain train = new SVMTrain(machine, SuperSet);

            ///  var network = (BasicNetwork)CreateEval.CreateElmanNetwork(SuperSet.InputSize, SuperSet.IdealSize);
            //double error = CreateEval.TrainNetworks(machine, SuperSet);

            TrainSVM(train, machine);

            //Lets create an evaluation.
            // Console.WriteLine(@"Last error rate on random trainer:" + error);
        }
Exemple #5
0
 private SupportVectorMachine Create()
 {
     IMLDataSet training = new BasicMLDataSet(XOR.XORInput, XOR.XORIdeal);
     SupportVectorMachine result = new SupportVectorMachine(2, SVMType.EpsilonSupportVectorRegression, KernelType.RadialBasisFunction);
     SVMTrain train = new SVMTrain(result, training);
     train.Iteration();
     return result;
 }
 private static SupportVectorMachine Create(IMLDataSet theset, int inputs)
 {
     IMLDataSet training = new BasicMLDataSet(theset);
     SupportVectorMachine result = new SupportVectorMachine(inputs, SVMType.EpsilonSupportVectorRegression, KernelType.Sigmoid);
     SVMTrain train = new SVMTrain(result, training);
     train.Iteration();
     return result;
 }
        /// <summary>
        /// Construct a trainer for an SVM network.
        /// </summary>
        ///
        /// <param name="method">The method to train.</param>
        /// <param name="training">The training data for this network.</param>
        public SVMSearchTrain(SupportVectorMachine method, IMLDataSet training)
            : base(TrainingImplementationType.Iterative)
        {
            _fold         = 0;
            _constBegin   = DefaultConstBegin;
            _constStep    = DefaultConstStep;
            _constEnd     = DefaultConstEnd;
            _gammaBegin   = DefaultGammaBegin;
            _gammaEnd     = DefaultGammaEnd;
            _gammaStep    = DefaultGammaStep;
            _network      = method;
            Training      = training;
            _isSetup      = false;
            _trainingDone = false;

            _internalTrain = new SVMTrain(_network, training);
        }
        /// <summary>
        /// Construct a trainer for an SVM network.
        /// </summary>
        ///
        /// <param name="method">The method to train.</param>
        /// <param name="training">The training data for this network.</param>
        public SVMSearchTrain(SupportVectorMachine method, IMLDataSet training)
            : base(TrainingImplementationType.Iterative)
        {
            _fold = 0;
            _constBegin = DefaultConstBegin;
            _constStep = DefaultConstStep;
            _constEnd = DefaultConstEnd;
            _gammaBegin = DefaultGammaBegin;
            _gammaEnd = DefaultGammaEnd;
            _gammaStep = DefaultGammaStep;
            _network = method;
            Training = training;
            _isSetup = false;
            _trainingDone = false;

            _internalTrain = new SVMTrain(_network, training);
        }
        public static double TrainNetworks(SupportVectorMachine network, MarketMLDataSet training)
        {
            // train the neural network
            SVMTrain trainMain = new SVMTrain(network, training);

            StopTrainingStrategy stop = new StopTrainingStrategy(0.0001, 200);
            trainMain.AddStrategy(stop);


            var sw = new Stopwatch();
            sw.Start();
            while (!stop.ShouldStop())
            {
                trainMain.PreIteration();


                trainMain.Iteration();
                trainMain.PostIteration();

                Console.WriteLine(@"Iteration #:" + trainMain.IterationNumber + @" Error:" + trainMain.Error);
            }
            sw.Stop();
            Console.WriteLine("SVM Trained in :" + sw.ElapsedMilliseconds + "For error:" + trainMain.Error + " Iterated:" + trainMain.IterationNumber);
            return trainMain.Error;
        }
 public static void train(SupportVectorMachine network,IMLDataSet training)
 {
     SVMTrain train = new SVMTrain(network, training);
     train.Iteration();
 }
Exemple #11
0
 public static double  train(SupportVectorMachine network, IMLDataSet training)
 {
     SVMTrain train = new SVMTrain(network, training);
     train.Iteration();
     return train.Error;
 }
 public static double TrainSVM(SVMTrain train, SupportVectorMachine machine)
 {
    
     StopTrainingStrategy stop = new StopTrainingStrategy(0.0001, 200);
     train.AddStrategy(stop);
     var sw = new Stopwatch();
     sw.Start();
     while (!stop.ShouldStop())
     {
         train.PreIteration();
         
         train.Iteration();
         train.PostIteration();
         Console.WriteLine(@"Iteration #:" + train.IterationNumber + @" Error:" + train.Error +" Gamma:"+train.Gamma);
     }
     sw.Stop();
     Console.WriteLine(@"SVM Trained in :" + sw.ElapsedMilliseconds);
     return train.Error;
 }
        /// <summary>
        /// Train the network, to a specific error, send the output to the console.
        /// </summary>
        /// <param name="method">The model to train.</param>
        /// <param name="trainingSet">The training set to use.</param>
        /// <param name="error">The error level to train to.</param>
        public static void TrainToError(IMLMethod method,
            IMLDataSet trainingSet, double error)
        {
            IMLTrain train;

            if (method is SupportVectorMachine)
            {
                train = new SVMTrain((SupportVectorMachine)method, trainingSet);
            } if (method is FreeformNetwork)
            {
                train = new FreeformResilientPropagation((FreeformNetwork)method, trainingSet);
            }
            else
            {
                train = new ResilientPropagation((IContainsFlat)method, trainingSet);
            }
            TrainToError(train, error);
        }