This factory is used to create machine learning methods.
Ejemplo n.º 1
0
        public static 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, 1);
            // second, create the data set
            IMLDataSet dataSet = MakeAsets(3000, outputNeurons);
            // 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);
            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);
        }
Ejemplo n.º 2
0
 public override sealed bool ExecuteCommand(string args)
 {
     FileInfo info2;
     string str3;
     string str4;
     EncogEGBFile file;
     int inputCount;
     int num2;
     string propertyString = base.Prop.GetPropertyString("ML:CONFIG_trainingFile");
     if (0x7fffffff != 0)
     {
         FileInfo info;
         string sourceID = base.Prop.GetPropertyString("ML:CONFIG_machineLearningFile");
         if (((uint) num2) <= uint.MaxValue)
         {
             info = base.Script.ResolveFilename(propertyString);
             info2 = base.Script.ResolveFilename(sourceID);
         }
         str3 = base.Prop.GetPropertyString("ML:CONFIG_type");
         str4 = base.Prop.GetPropertyString("ML:CONFIG_architecture");
         EncogLogging.Log(0, "Beginning create");
         EncogLogging.Log(0, "training file:" + propertyString);
         EncogLogging.Log(0, "resource file:" + sourceID);
         EncogLogging.Log(0, "type:" + str3);
         EncogLogging.Log(0, "arch:" + str4);
         file = new EncogEGBFile(info.ToString());
         goto Label_00A6;
     }
     Label_002E:
     num2 = file.IdealCount;
     file.Close();
     IMLMethod method = new MLMethodFactory().Create(str3, str4, inputCount, num2);
     if ((((uint) inputCount) + ((uint) num2)) >= 0)
     {
         if (1 != 0)
         {
         }
         EncogDirectoryPersistence.SaveObject(info2, method);
         return false;
     }
     Label_00A6:
     file.Open();
     inputCount = file.InputCount;
     goto Label_002E;
 }
Ejemplo n.º 3
0
        /// <inheritdoc />
        public override sealed bool ExecuteCommand(String args)
        {
            // get filenames
            String trainingID = Prop.GetPropertyString(
                ScriptProperties.MlConfigTrainingFile);
            String resourceID = Prop.GetPropertyString(
                ScriptProperties.MlConfigMachineLearningFile);

            FileInfo trainingFile = Script.ResolveFilename(trainingID);
            FileInfo resourceFile = Script.ResolveFilename(resourceID);

            String type = Prop.GetPropertyString(
                ScriptProperties.MlConfigType);
            String arch = Prop.GetPropertyString(
                ScriptProperties.MlConfigArchitecture);

            EncogLogging.Log(EncogLogging.LevelDebug, "Beginning create");
            EncogLogging.Log(EncogLogging.LevelDebug, "training file:"
                                                      + trainingID);
            EncogLogging.Log(EncogLogging.LevelDebug, "resource file:"
                                                      + resourceID);
            EncogLogging.Log(EncogLogging.LevelDebug, "type:" + type);
            EncogLogging.Log(EncogLogging.LevelDebug, "arch:" + arch);

            var egb = new EncogEGBFile(trainingFile.ToString());
            egb.Open();
            int input = egb.InputCount;
            int ideal = egb.IdealCount;
            egb.Close();

            var factory = new MLMethodFactory();
            IMLMethod obj = factory.Create(type, arch, input, ideal);

            if (obj is BayesianNetwork)
            {
                string query = Prop.GetPropertyString(ScriptProperties.MLConfigQuery);
                ((BayesianNetwork) obj).DefineClassificationStructure(query);
            }

            EncogDirectoryPersistence.SaveObject(resourceFile, obj);

            return false;
        }
Ejemplo n.º 4
0
        /// <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 the selected method.
 /// </summary>
 /// <returns>The created method.</returns>
 public IMLMethod CreateMethod()
 {
     if (_methodType == null)
     {
         throw new EncogError(
             "Please call selectMethod first to choose what type of method you wish to use.");
     }
     var methodFactory = new MLMethodFactory();
     IMLMethod method = methodFactory.Create(_methodType, _methodArgs, _dataset
         .NormHelper.CalculateNormalizedInputCount(), _config
             .DetermineOutputCount(_dataset));
     return method;
 }
Ejemplo n.º 6
0
        private void CreateCommand()
        {
            if (_cmd.Args.Count != 3)
            {
                Console.WriteLine(@"Must specify method filename, type and args.");
                return;
            }

            String methodFile = _cmd.Args[0];
            String type = _cmd.Args[1];
            String args = _cmd.Args[2];

            _sw.Start();
            var factory = new MLMethodFactory();
            IMLMethod method = factory.Create(type, args, 0, 0);
            EncogDirectoryPersistence.SaveObject(new FileInfo(methodFile), method);
        }