Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/30/13 16:54:43 (11 years ago)
Author:
sforsten
Message:

#1980:

  • added multiple discretizer to GAssist
  • created ensembles for LCS problems and edited CrossValidation to use them
File:
1 edited

Legend:

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

    r8970 r9411  
    2929using HeuristicLab.Core;
    3030using HeuristicLab.Data;
     31using HeuristicLab.Encodings.ConditionActionEncoding;
    3132using HeuristicLab.Optimization;
     33using HeuristicLab.Optimization.Operators.LCS;
    3234using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3335using HeuristicLab.Problems.DataAnalysis;
     
    405407        results.Add(result.Name, result.Value);
    406408      }
     409      foreach (IResult result in ExtractAndAggregateGAssistSolutions(resultCollections)) {
     410        results.Add(result.Name, result.Value);
     411      }
     412      foreach (IResult result in ExtractAndAggregateConditionActionSolutions(resultCollections)) {
     413        results.Add(result.Name, result.Value);
     414      }
    407415      results.Add("Execution Time", new TimeSpanValue(this.ExecutionTime));
    408416      results.Add("CrossValidation Folds", new RunCollection(runs));
     417    }
     418
     419    private IEnumerable<IResult> ExtractAndAggregateConditionActionSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     420      Dictionary<string, List<IConditionActionSolution>> resultSolutions = new Dictionary<string, List<IConditionActionSolution>>();
     421      foreach (var result in resultCollections) {
     422        var conditionActionSolution = result.Value as IConditionActionSolution;
     423        if (conditionActionSolution != null) {
     424          if (resultSolutions.ContainsKey(result.Key)) {
     425            resultSolutions[result.Key].Add(conditionActionSolution);
     426          } else {
     427            resultSolutions.Add(result.Key, new List<IConditionActionSolution>() { conditionActionSolution });
     428          }
     429        }
     430      }
     431      List<IResult> aggregatedResults = new List<IResult>();
     432      foreach (KeyValuePair<string, List<IConditionActionSolution>> solutions in resultSolutions) {
     433        // clone manually to correctly clone references between cloned root objects
     434        Cloner cloner = new Cloner();
     435        var problemDataClone = (IConditionActionProblemData)cloner.Clone(Problem.ProblemData);
     436        // set partitions of problem data clone correctly
     437        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     438        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     439        // clone models
     440        var ensembleSolution = new ConditionActionEnsembleSolution(problemDataClone);
     441        ensembleSolution.AddConditionActionSolutions(solutions.Value);
     442
     443        aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
     444      }
     445      List<IResult> flattenedResults = new List<IResult>();
     446      CollectResultsRecursively("", aggregatedResults, flattenedResults);
     447      return flattenedResults;
     448    }
     449
     450    private IEnumerable<IResult> ExtractAndAggregateGAssistSolutions(IEnumerable<KeyValuePair<string, IItem>> resultCollections) {
     451      Dictionary<string, List<IGAssistSolution>> resultSolutions = new Dictionary<string, List<IGAssistSolution>>();
     452      foreach (var result in resultCollections) {
     453        var gassistSolution = result.Value as IGAssistSolution;
     454        if (gassistSolution != null) {
     455          if (resultSolutions.ContainsKey(result.Key)) {
     456            resultSolutions[result.Key].Add(gassistSolution);
     457          } else {
     458            resultSolutions.Add(result.Key, new List<IGAssistSolution>() { gassistSolution });
     459          }
     460        }
     461      }
     462      List<IResult> aggregatedResults = new List<IResult>();
     463      foreach (KeyValuePair<string, List<IGAssistSolution>> solutions in resultSolutions) {
     464        // clone manually to correctly clone references between cloned root objects
     465        Cloner cloner = new Cloner();
     466        var problemDataClone = (IGAssistProblemData)cloner.Clone(Problem.ProblemData);
     467        // set partitions of problem data clone correctly
     468        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
     469        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
     470        // clone models
     471        var ensembleSolution = new GAssistEnsembleSolution(problemDataClone);
     472        ensembleSolution.AddGAssistSolutions(solutions.Value);
     473
     474        aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
     475      }
     476      List<IResult> flattenedResults = new List<IResult>();
     477      CollectResultsRecursively("", aggregatedResults, flattenedResults);
     478      return flattenedResults;
    409479    }
    410480
Note: See TracChangeset for help on using the changeset viewer.