Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/06/11 21:13:34 (13 years ago)
Author:
gkronber
Message:

#1450 implemented menu item to merge all data analysis solutions in a run collection into ensemble solutions and fixed a few bugs related to ensemble solutions.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleModel.cs

    r6239 r6520  
    5858
    5959    #region IClassificationEnsembleModel Members
     60    public void Add(IClassificationModel model) {
     61      models.Add(model);
     62    }
    6063
    6164    public IEnumerable<IEnumerable<double>> GetEstimatedClassValueVectors(Dataset dataset, IEnumerable<int> rows) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleProblemData.cs

    r6239 r6520  
    3737    public override IEnumerable<int> TrainingIndizes {
    3838      get {
    39         return Enumerable.Range(TrainingPartition.Start, TestPartition.End - TestPartition.Start);
     39        return Enumerable.Range(TrainingPartition.Start, TrainingPartition.End - TrainingPartition.Start);
    4040      }
    4141    }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationEnsembleSolution.cs

    r6302 r6520  
    7979      this.trainingPartitions = new Dictionary<IClassificationModel, IntRange>();
    8080      this.testPartitions = new Dictionary<IClassificationModel, IntRange>();
    81       var modelEnumerator = models.GetEnumerator();
    82       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    83       var testPartitionEnumerator = testPartitions.GetEnumerator();
    84       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    85         this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
    86         this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
    87       }
    88       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    89         throw new ArgumentException();
    90       }
     81      AddModelsAndParitions(models,
     82        trainingPartitions,
     83        testPartitions);
    9184      RecalculateResults();
    9285    }
     
    169162      .First();
    170163    }
     164
     165    public void AddModelsAndParitions(IEnumerable<IClassificationSolution> solutions) {
     166      foreach (var solution in solutions) {
     167        var ensembleSolution = solution as ClassificationEnsembleSolution;
     168        if (ensembleSolution != null) {
     169          var data = from m in ensembleSolution.Model.Models
     170                     let train = ensembleSolution.trainingPartitions[m]
     171                     let test = ensembleSolution.testPartitions[m]
     172                     select new { m, train, test };
     173
     174          foreach (var d in data) {
     175            Model.Add(d.m);
     176            trainingPartitions[d.m] = (IntRange)d.train.Clone();
     177            testPartitions[d.m] = (IntRange)d.test.Clone();
     178          }
     179        } else {
     180          Model.Add(solution.Model);
     181          trainingPartitions[solution.Model] = (IntRange)solution.ProblemData.TrainingPartition.Clone();
     182          testPartitions[solution.Model] = (IntRange)solution.ProblemData.TestPartition.Clone();
     183        }
     184      }
     185
     186      RecalculateResults();
     187    }
     188
     189    private void AddModelsAndParitions(IEnumerable<IClassificationModel> models, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions) {
     190      var modelEnumerator = models.GetEnumerator();
     191      var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
     192      var testPartitionEnumerator = testPartitions.GetEnumerator();
     193
     194      while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
     195        this.trainingPartitions[modelEnumerator.Current] = (IntRange)trainingPartitionEnumerator.Current.Clone();
     196        this.testPartitions[modelEnumerator.Current] = (IntRange)testPartitionEnumerator.Current.Clone();
     197      }
     198      if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
     199        throw new ArgumentException();
     200      }
     201    }
    171202  }
    172203}
Note: See TracChangeset for help on using the changeset viewer.