/// <summary> /// Perform the training. /// </summary> /// <param name="train">The training method.</param> /// <param name="method">The ML method.</param> /// <param name="trainingSet">The training set.</param> private void PerformTraining(IMLTrain train, IMLMethod method, IMLDataSet trainingSet) { ValidateNetwork.ValidateMethodToData(method, trainingSet); double targetError = Prop.GetPropertyDouble( ScriptProperties.MlTrainTargetError); Analyst.ReportTrainingBegin(); int maxIteration = Analyst.MaxIteration; if (train.ImplementationType == TrainingImplementationType.OnePass) { train.Iteration(); Analyst.ReportTraining(train); } else { do { train.Iteration(); Analyst.ReportTraining(train); } while ((train.Error > targetError) && !Analyst.ShouldStopCommand() && !train.TrainingDone && ((maxIteration == -1) || (train.IterationNumber < maxIteration))); } train.FinishTraining(); Analyst.ReportTrainingEnd(); }
/// <summary> /// </summary> public override sealed bool ExecuteCommand(String args) { _kfold = ObtainCross(); IMLDataSet trainingSet = ObtainTrainingSet(); IMLMethod method = ObtainMethod(); IMLTrain trainer = CreateTrainer(method, trainingSet); EncogLogging.Log(EncogLogging.LevelDebug, "Beginning training"); PerformTraining(trainer, method, trainingSet); String resourceID = Prop.GetPropertyString( ScriptProperties.MlConfigMachineLearningFile); FileInfo resourceFile = Analyst.Script.ResolveFilename( resourceID); method = trainer.Method; EncogDirectoryPersistence.SaveObject(resourceFile, method); EncogLogging.Log(EncogLogging.LevelDebug, "save to:" + resourceID); return(Analyst.ShouldStopCommand()); }