Beispiel #1
0
        private void LearnNewModel()
        {
            previousModel = new List <Feature>(currentModel);
            GlobalState.logInfo.logLine("Learning set: " + currentLearningSet.Count + ", Validation set: "
                                        + currentLearningSet.Count);
            Learning exp = new Learning(currentLearningSet, currentValidationSet)
            {
                metaModel  = influenceModel,
                mlSettings = this.mlSettings
            };

            exp.learn(currentModel);
            if (exp.models.Count != 1)
            {
                GlobalState.logError.logLine("There should be exactly one learned model! Aborting active learning!");
                Environment.Exit(0);
            }
            FeatureSubsetSelection fss = exp.models[0];

            currentModel            = fss.LearningHistory.Last().FeatureSet;
            previousValidationError = currentValidationError;
            currentValidationError  = fss.finalError;
            currentGlobalError      = fss.computeError(currentModel, GlobalState.allMeasurements.Configurations, false);
            GlobalState.logInfo.logLine("globalError = " + currentGlobalError);
        }
Beispiel #2
0
 /// <summary>
 /// Continues learning with recovered learning data.
 /// </summary>
 /// <param name="recoveredLr">Learning rounds that were already performed.</param>
 public void continueLearning(List <LearningRound> recoveredLr)
 {
     if (!hasNecessaryData())
     {
         return;
     }
     if (this.mlSettings.bagging)
     {
         throw new NotImplementedException("Recovering with bagging currently dosent work");
     }
     else
     {
         ObservableCollection <LearningRound> learningRounds = new ObservableCollection <LearningRound>();
         GlobalState.logInfo.logLine("Learning progress:");
         foreach (LearningRound lr in recoveredLr)
         {
             GlobalState.logInfo.logLine(lr.ToString());
             learningRounds.Add(lr);
         }
         InfluenceModel         infMod = new InfluenceModel(GlobalState.varModel, GlobalState.currentNFP);
         FeatureSubsetSelection sel    = new FeatureSubsetSelection(infMod, this.mlSettings);
         this.models.Add(sel);
         sel.setLearningSet(testSet);
         sel.setValidationSet(this.validationSet);
         Stopwatch sw = new Stopwatch();
         sw.Start();
         sel.continueLearn(learningRounds);
         sw.Stop();
         Console.WriteLine("Elapsed={0}", sw.Elapsed);
     }
 }
Beispiel #3
0
        public void learn()
        {
            if (!hasNecessaryData())
            {
                return;
            }
            if (this.mlSettings.bagging)
            {
                //Get number of cores
                int coreCount = System.Environment.ProcessorCount;
                createThreadPool(coreCount);

                this.nbBaggings = this.mlSettings.baggingNumbers;
                iCount          = this.nbBaggings;
                Random rand        = new Random(0);
                int    nbOfConfigs = (testSet.Count * this.mlSettings.baggingTestDataFraction) / 100;
                for (int i = 0; i < nbBaggings; i++)
                {
                    InfluenceModel         infMod = new InfluenceModel(GlobalState.varModel, GlobalState.currentNFP);
                    FeatureSubsetSelection sel    = new FeatureSubsetSelection(infMod, this.mlSettings);
                    this.models.Add(sel);
                    List <int> selection = new List <int>();
                    for (int r = 0; r <= nbOfConfigs; r++)
                    {
                        selection.Add(rand.Next(nbOfConfigs));
                    }
                    List <Configuration> newTestSet       = new List <Configuration>();
                    List <Configuration> newValidationSet = new List <Configuration>();
                    for (int r = 0; r <= selection.Count; r++)
                    {
                        if (selection.Contains(r))
                        {
                            newTestSet.Add(testSet[r]);
                        }
                        else
                        {
                            newValidationSet.Add(testSet[r]);
                        }
                    }
                    sel.setLearningSet(newTestSet);
                    sel.setValidationSet(newValidationSet);
                    Task task = EnqueueTask(() => sel.learn());
                }
                eventX.WaitOne(Timeout.Infinite, true);
                averageModels();
            }
            else
            {
                GlobalState.logInfo.logLine("Learning progress:");
                InfluenceModel         infMod = new InfluenceModel(GlobalState.varModel, GlobalState.currentNFP);
                FeatureSubsetSelection sel    = new FeatureSubsetSelection(infMod, this.mlSettings);
                this.models.Add(sel);
                sel.setLearningSet(testSet);
                sel.setValidationSet(this.validationSet);
                Stopwatch sw = new Stopwatch();
                sw.Start();
                sel.learn();
                sw.Stop();
                Console.WriteLine("Elapsed={0}", sw.Elapsed);
            }
        }