Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13698 for trunk


Ignore:
Timestamp:
03/14/16 17:49:05 (9 years ago)
Author:
mkommend
Message:

#2590: Simplified ctors of RegressionEnsembleSolution.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleModel.cs

    r13697 r13698  
    7373
    7474    #region IRegressionEnsembleModel Members
    75 
    7675    public void Add(IRegressionModel model) {
    7776      models.Add(model);
     
    106105      }
    107106    }
    108 
    109107    #endregion
    110108
     
    117115
    118116    public RegressionEnsembleSolution CreateRegressionSolution(IRegressionProblemData problemData) {
    119       return new RegressionEnsembleSolution(this.Models, new RegressionEnsembleProblemData(problemData));
     117      return new RegressionEnsembleSolution(this, new RegressionEnsembleProblemData(problemData));
    120118    }
    121119    IRegressionSolution IRegressionModel.CreateRegressionSolution(IRegressionProblemData problemData) {
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r13697 r13698  
    9393      }
    9494
     95      evaluationCache = new Dictionary<int, double>(original.ProblemData.Dataset.Rows);
    9596      trainingEvaluationCache = new Dictionary<int, double>(original.ProblemData.TrainingIndices.Count());
    9697      testEvaluationCache = new Dictionary<int, double>(original.ProblemData.TestIndices.Count());
     
    110111
    111112    public RegressionEnsembleSolution(IRegressionProblemData problemData)
    112       : this(Enumerable.Empty<IRegressionModel>(), problemData) {
    113     }
    114 
    115     public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData)
    116       : this(models, problemData,
    117              models.Select(m => (IntRange)problemData.TrainingPartition.Clone()),
    118              models.Select(m => (IntRange)problemData.TestPartition.Clone())
    119       ) { }
    120 
    121     public RegressionEnsembleSolution(IEnumerable<IRegressionModel> models, IRegressionProblemData problemData, IEnumerable<IntRange> trainingPartitions, IEnumerable<IntRange> testPartitions)
    122       : base(new RegressionEnsembleModel(Enumerable.Empty<IRegressionModel>()), new RegressionEnsembleProblemData(problemData)) {
    123       this.trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
    124       this.testPartitions = new Dictionary<IRegressionModel, IntRange>();
    125       this.regressionSolutions = new ItemCollection<IRegressionSolution>();
    126 
    127       List<IRegressionSolution> solutions = new List<IRegressionSolution>();
    128       var modelEnumerator = models.GetEnumerator();
    129       var trainingPartitionEnumerator = trainingPartitions.GetEnumerator();
    130       var testPartitionEnumerator = testPartitions.GetEnumerator();
    131 
    132       while (modelEnumerator.MoveNext() & trainingPartitionEnumerator.MoveNext() & testPartitionEnumerator.MoveNext()) {
    133         var p = (IRegressionProblemData)problemData.Clone();
    134         p.TrainingPartition.Start = trainingPartitionEnumerator.Current.Start;
    135         p.TrainingPartition.End = trainingPartitionEnumerator.Current.End;
    136         p.TestPartition.Start = testPartitionEnumerator.Current.Start;
    137         p.TestPartition.End = testPartitionEnumerator.Current.End;
    138 
    139         solutions.Add(modelEnumerator.Current.CreateRegressionSolution(p));
    140       }
    141       if (modelEnumerator.MoveNext() | trainingPartitionEnumerator.MoveNext() | testPartitionEnumerator.MoveNext()) {
    142         throw new ArgumentException();
    143       }
    144 
     113      : this(new RegressionEnsembleModel(), problemData) {
     114    }
     115
     116    public RegressionEnsembleSolution(IRegressionEnsembleModel model, IRegressionProblemData problemData)
     117      : base(model, new RegressionEnsembleProblemData(problemData)) {
     118      trainingPartitions = new Dictionary<IRegressionModel, IntRange>();
     119      testPartitions = new Dictionary<IRegressionModel, IntRange>();
     120      regressionSolutions = new ItemCollection<IRegressionSolution>();
     121
     122      evaluationCache = new Dictionary<int, double>(problemData.Dataset.Rows);
    145123      trainingEvaluationCache = new Dictionary<int, double>(problemData.TrainingIndices.Count());
    146124      testEvaluationCache = new Dictionary<int, double>(problemData.TestIndices.Count());
    147125
    148126      RegisterRegressionSolutionsEventHandler();
     127      var solutions = model.Models.Select(m => m.CreateRegressionSolution((IRegressionProblemData)problemData.Clone()));
    149128      regressionSolutions.AddRange(solutions);
    150129    }
     130
    151131
    152132    public override IDeepCloneable Clone(Cloner cloner) {
Note: See TracChangeset for help on using the changeset viewer.