Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/23/11 12:54:57 (13 years ago)
Author:
gkronber
Message:

#1450 Added preliminary implementation for solution ensemble support.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis SolutionEnsembles/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r5809 r5816  
    355355      foreach (IResult result in ExtractAndAggregateResults<PercentValue>(resultCollections))
    356356        results.Add(result.Name, result.Value);
    357 
     357      foreach (IResult result in ExtractAndAggregateRegressionSolutions(resultCollections)) {
     358        results.Add(result.Name, result.Value);
     359      }
     360      //foreach (IResult result in ExtractAndAggregateClassificationSolutions(resultCollections)) {
     361      //  results.Add(result.Name, result.Value);
     362      //}
    358363      results.Add("Execution Time", new TimeSpanValue(this.ExecutionTime));
    359364      results.Add("CrossValidation Folds", new RunCollection(runs));
    360365    }
     366
     367    private IEnumerable<IResult> ExtractAndAggregateRegressionSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     368      Dictionary<string, List<IRegressionSolution>> resultSolutions = new Dictionary<string, List<IRegressionSolution>>();
     369      foreach (var result in resultCollections) {
     370        var regressionSolution = result.Value as IRegressionSolution;
     371        if (regressionSolution != null) {
     372          if (resultSolutions.ContainsKey(result.Key)) {
     373            resultSolutions[result.Key].Add(regressionSolution);
     374          } else {
     375            resultSolutions.Add(result.Key, new List<IRegressionSolution>() { regressionSolution });
     376          }
     377        }
     378      }
     379      List<IResult> aggregatedResults = new List<IResult>();
     380      foreach (KeyValuePair<string, List<IRegressionSolution>> solutions in resultSolutions) {
     381        var problemDataClone = (IRegressionProblemData)Problem.ProblemData.Clone();
     382        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     383        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     384        var ensembleSolution = new RegressionEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone,
     385          solutions.Value.Select(x => x.ProblemData.TrainingPartition),
     386          solutions.Value.Select(x => x.ProblemData.TestPartition)); ;
     387
     388        aggregatedResults.Add(new Result(solutions.Key, ensembleSolution));
     389      }
     390      return aggregatedResults;
     391    }
     392
     393    //private IEnumerable<IResult> ExtractAndAggregateClassificationSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     394    //  Dictionary<string, List<IClassificationSolution>> resultSolutions = new Dictionary<string, List<IClassificationSolution>>();
     395    //  foreach (var result in resultCollections) {
     396    //    var classificationSolution = result.Value as IClassificationSolution;
     397    //    if (classificationSolution != null) {
     398    //      if (resultSolutions.ContainsKey(result.Key)) {
     399    //        resultSolutions[result.Key].Add(classificationSolution);
     400    //      } else {
     401    //        resultSolutions.Add(result.Key, new List<IClassificationSolution>() { classificationSolution });
     402    //      }
     403    //    }
     404    //  }
     405    //  List<IResult> aggregatedResults = new List<IResult>();
     406    //  foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
     407    //    var ensembleModel = new ClassificationEnsembleModel(solutions.Value.Select(x => x.Model));
     408    //    var problemDataClone = (IClassificationProblemData)Problem.ProblemData.Clone();
     409
     410    //    problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     411    //    problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     412    //    aggregatedResults.Add(new Result(solutions.Key, new ClassificationSolution(ensembleModel, problemDataClone)));
     413    //  }
     414    //  return aggregatedResults;
     415    //}
    361416
    362417    private static IEnumerable<IResult> ExtractAndAggregateResults<T>(IEnumerable<KeyValuePair<string, IItem>> results)
Note: See TracChangeset for help on using the changeset viewer.