Create() public method

Create a trainer.
public Create ( IMLMethod method, IMLDataSet training, String type, String args ) : IMLTrain
method IMLMethod The method to train.
training IMLDataSet The training data.
type String Type type of trainer.
args String The training args.
return IMLTrain
        public void Process(String methodName, String methodArchitecture, String trainerName, String trainerArgs,
            int outputNeurons)
        {
            // first, create the machine learning method
            var methodFactory = new MLMethodFactory();
            IMLMethod method = methodFactory.Create(methodName, methodArchitecture, 2, outputNeurons);

            // second, create the data set
            IMLDataSet dataSet = new BasicMLDataSet(XORInput, XORIdeal);

            // third, create the trainer
            var trainFactory = new MLTrainFactory();
            IMLTrain train = trainFactory.Create(method, dataSet, trainerName, trainerArgs);
            // reset if improve is less than 1% over 5 cycles
            if (method is IMLResettable && !(train is ManhattanPropagation))
            {
                train.AddStrategy(new RequiredImprovementStrategy(500));
            }

            // fourth, train and evaluate.
            EncogUtility.TrainToError(train, 0.01);
            method = train.Method;
            EncogUtility.Evaluate((IMLRegression) method, dataSet);

            // finally, write out what we did
            Console.WriteLine(@"Machine Learning Type: " + methodName);
            Console.WriteLine(@"Machine Learning Architecture: " + methodArchitecture);

            Console.WriteLine(@"Training Method: " + trainerName);
            Console.WriteLine(@"Training Args: " + trainerArgs);
        }
Beispiel #2
0
        /// <summary>
        ///     Create a trainer, use cross validation if enabled.
        /// </summary>
        /// <param name="method">The method to use.</param>
        /// <param name="trainingSet">The training set to use.</param>
        /// <returns>The trainer.</returns>
        private IMLTrain CreateTrainer(IMLMethod method,
            IMLDataSet trainingSet)
        {
            var factory = new MLTrainFactory();

            String type = Prop.GetPropertyString(
                ScriptProperties.MlTrainType);
            String args = Prop.GetPropertyString(
                ScriptProperties.MlTrainArguments);

            EncogLogging.Log(EncogLogging.LevelDebug, "training type:" + type);
            EncogLogging.Log(EncogLogging.LevelDebug, "training args:" + args);

            IMLTrain train = factory.Create(method, trainingSet, type, args);

            if (_kfold > 0)
            {
                train = new CrossValidationKFold(train, _kfold);
            }

            return train;
        }
        /// <summary>
        /// Perform the training option.
        /// </summary>
        public void Train()
        {
            // first, create the machine learning method
            var methodFactory = new MLMethodFactory();
            IMLMethod method = methodFactory.Create(Config.MethodType, Config.MethodArchitecture, Config.InputWindow, 1);

            // second, create the data set
            string filename = FileUtil.CombinePath(new FileInfo(_path), Config.FilenameTrain).ToString();
            IMLDataSet dataSet = EncogUtility.LoadEGB2Memory(new FileInfo(filename));

            // third, create the trainer
            var trainFactory = new MLTrainFactory();
            IMLTrain train = trainFactory.Create(method, dataSet, Config.TrainType, Config.TrainParams);
            // reset if improve is less than 1% over 5 cycles
            if (method is IMLResettable && !(train is ManhattanPropagation))
            {
                train.AddStrategy(new RequiredImprovementStrategy(500));
            }

            // fourth, train and evaluate.
            EncogUtility.TrainToError(train, Config.TargetError);
            method = train.Method;
            EncogDirectoryPersistence.SaveObject(FileUtil.CombinePath(new FileInfo(_path), Config.MethodName), method);

            // finally, write out what we did
            Console.WriteLine(@"Machine Learning Type: " + Config.MethodType);
            Console.WriteLine(@"Machine Learning Architecture: " + Config.MethodArchitecture);

            Console.WriteLine(@"Training Method: " + Config.TrainType);
            Console.WriteLine(@"Training Args: " + Config.TrainParams);
        }
 /// <summary>
 ///     Create a trainer.
 /// </summary>
 /// <param name="method">The method to train.</param>
 /// <param name="dataset">The dataset.</param>
 /// <returns>The trainer.</returns>
 private IMLTrain CreateTrainer(IMLMethod method, IMLDataSet dataset)
 {
     if (_trainingType == null)
     {
         throw new EncogError(
             "Please call selectTraining first to choose how to train.");
     }
     var trainFactory = new MLTrainFactory();
     IMLTrain train = trainFactory.Create(method, dataset, _trainingType,
         _trainingArgs);
     return train;
 }
Beispiel #5
0
 private IMLTrain x8d3a841b4ad80901(IMLMethod x1306445c04667cc7, IMLDataSet x1c9e132f434262d8)
 {
     string propertyString;
     string str2;
     MLTrainFactory factory = new MLTrainFactory();
     if (0 == 0)
     {
         propertyString = base.Prop.GetPropertyString("ML:TRAIN_type");
         do
         {
             str2 = base.Prop.GetPropertyString("ML:TRAIN_arguments");
             EncogLogging.Log(0, "training type:" + propertyString);
             EncogLogging.Log(0, "training args:" + str2);
         }
         while (0 != 0);
     }
     IMLTrain train = factory.Create(x1306445c04667cc7, x1c9e132f434262d8, propertyString, str2);
     while (this._x33d31451731666c6 > 0)
     {
         return new CrossValidationKFold(train, this._x33d31451731666c6);
     }
     return train;
 }
Beispiel #6
0
        private void TrainCommand()
        {
            String methodFile = _cmd.Args[0];
            String trainingFile = _cmd.Args[1];

            String type = _cmd.PromptString("type", "rprop");
            String args = _cmd.PromptString("args", "");
            double maxError = _cmd.PromptDouble("maxError", 0.01);

            var dataSet = new BufferedMLDataSet(trainingFile);
            var method = (IMLMethod) EncogDirectoryPersistence.LoadObject(new FileInfo(methodFile));
            var factory = new MLTrainFactory();
            IMLTrain train = factory.Create(method, dataSet, type, args);
            _sw.Start();
            EncogUtility.TrainToError(train, maxError);
            Console.WriteLine(@"Saving machine learning method");
            EncogDirectoryPersistence.SaveObject(new FileInfo(methodFile), method);
        }