Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/01/11 17:48:53 (13 years ago)
Author:
mkommend
Message:

#1479: Integrated trunk changes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GP.Grammar.Editor/HeuristicLab.Algorithms.DataAnalysis/3.4/CrossValidation.cs

    r6250 r6618  
    3434
    3535namespace HeuristicLab.Algorithms.DataAnalysis {
    36   [Item("Cross Validation", "Cross Validation wrapper for data analysis algorithms.")]
     36  [Item("Cross Validation", "Cross-validation wrapper for data analysis algorithms.")]
    3737  [Creatable("Data Analysis")]
    3838  [StorableClass]
     
    363363
    364364    public void CollectResultValues(IDictionary<string, IItem> results) {
     365      var clonedResults = (ResultCollection)this.results.Clone();
     366      foreach (var result in clonedResults) {
     367        results.Add(result.Name, result.Value);
     368      }
     369    }
     370
     371    private void AggregateResultValues(IDictionary<string, IItem> results) {
    365372      Dictionary<string, List<double>> resultValues = new Dictionary<string, List<double>>();
    366373      IEnumerable<IRun> runs = clonedAlgorithms.Select(alg => alg.Runs.FirstOrDefault()).Where(run => run != null);
     
    397404      List<IResult> aggregatedResults = new List<IResult>();
    398405      foreach (KeyValuePair<string, List<IRegressionSolution>> solutions in resultSolutions) {
    399         var problemDataClone = (IRegressionProblemData)Problem.ProblemData.Clone();
     406        // clone manually to correctly clone references between cloned root objects
     407        Cloner cloner = new Cloner();
     408        var problemDataClone = (IRegressionProblemData)cloner.Clone(Problem.ProblemData);
     409        // set partitions of problem data clone correctly
    400410        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
    401411        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
    402         var ensembleSolution = new RegressionEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone,
    403           solutions.Value.Select(x => x.ProblemData.TrainingPartition),
    404           solutions.Value.Select(x => x.ProblemData.TestPartition));
     412        // clone models
     413        var ensembleSolution = new RegressionEnsembleSolution(
     414          solutions.Value.Select(x => cloner.Clone(x.Model)),
     415          problemDataClone,
     416          solutions.Value.Select(x => cloner.Clone(x.ProblemData.TrainingPartition)),
     417          solutions.Value.Select(x => cloner.Clone(x.ProblemData.TestPartition)));
    405418
    406419        aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
     
    425438      var aggregatedResults = new List<IResult>();
    426439      foreach (KeyValuePair<string, List<IClassificationSolution>> solutions in resultSolutions) {
    427         var problemDataClone = (IClassificationProblemData)Problem.ProblemData.Clone();
     440        // clone manually to correctly clone references between cloned root objects
     441        Cloner cloner = new Cloner();
     442        var problemDataClone = (IClassificationProblemData)cloner.Clone(Problem.ProblemData);
     443        // set partitions of problem data clone correctly
    428444        problemDataClone.TrainingPartition.Start = SamplesStart.Value; problemDataClone.TrainingPartition.End = SamplesEnd.Value;
    429445        problemDataClone.TestPartition.Start = SamplesStart.Value; problemDataClone.TestPartition.End = SamplesEnd.Value;
    430         var ensembleSolution = new ClassificationEnsembleSolution(solutions.Value.Select(x => x.Model), problemDataClone,
    431           solutions.Value.Select(x => x.ProblemData.TrainingPartition),
    432           solutions.Value.Select(x => x.ProblemData.TestPartition));
     446        // clone models
     447        var ensembleSolution = new ClassificationEnsembleSolution(
     448          solutions.Value.Select(x => cloner.Clone(x.Model)),
     449          problemDataClone,
     450          solutions.Value.Select(x => cloner.Clone(x.ProblemData.TrainingPartition)),
     451          solutions.Value.Select(x => cloner.Clone(x.ProblemData.TestPartition)));
    433452
    434453        aggregatedResults.Add(new Result(solutions.Key + " (ensemble)", ensembleSolution));
     
    553572      } else
    554573        SamplesEnd.Value = 0;
     574
     575      SamplesStart_ValueChanged(this, EventArgs.Empty);
     576      SamplesEnd_ValueChanged(this, EventArgs.Empty);
    555577    }
    556578
     
    699721      stopPending = false;
    700722      Dictionary<string, IItem> collectedResults = new Dictionary<string, IItem>();
    701       CollectResultValues(collectedResults);
     723      AggregateResultValues(collectedResults);
    702724      results.AddRange(collectedResults.Select(x => new Result(x.Key, x.Value)).Cast<IResult>().ToArray());
    703725      runsCounter++;
Note: See TracChangeset for help on using the changeset viewer.