Free cookie consent management tool by TermsFeed Policy Generator

Changeset 8167 for trunk


Ignore:
Timestamp:
06/30/12 17:05:23 (12 years ago)
Author:
gkronber
Message:

#1720 reused evaluationCache from base classes in EnsembleSolutions

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

Legend:

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

    r8153 r8167  
    3737  [Creatable("Data Analysis - Ensembles")]
    3838  public sealed class ClassificationEnsembleSolution : ClassificationSolution, IClassificationEnsembleSolution {
    39     private readonly Dictionary<int, double> trainingEstimatedValuesCache = new Dictionary<int, double>();
    40     private readonly Dictionary<int, double> testEstimatedValuesCache = new Dictionary<int, double>();
    41     private readonly Dictionary<int, double> estimatedValuesCache = new Dictionary<int, double>();
     39    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
     40    private readonly Dictionary<int, double> testEvaluationCache = new Dictionary<int, double>();
    4241
    4342    public new IClassificationEnsembleModel Model {
     
    153152      get {
    154153        var rows = ProblemData.TrainingIndices;
    155         var rowsToEvaluate = rows.Except(trainingEstimatedValuesCache.Keys);
     154        var rowsToEvaluate = rows.Except(trainingEvaluationCache.Keys);
    156155        var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    157156        var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, (r, m) => RowIsTrainingForModel(r, m) && !RowIsTestForModel(r, m)).GetEnumerator();
    158157
    159158        while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    160           trainingEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     159          trainingEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    161160        }
    162161
    163         return rows.Select(row => trainingEstimatedValuesCache[row]);
     162        return rows.Select(row => trainingEvaluationCache[row]);
    164163      }
    165164    }
     
    168167      get {
    169168        var rows = ProblemData.TestIndices;
    170         var rowsToEvaluate = rows.Except(testEstimatedValuesCache.Keys);
     169        var rowsToEvaluate = rows.Except(testEvaluationCache.Keys);
    171170        var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    172171        var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, RowIsTestForModel).GetEnumerator();
    173172
    174173        while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    175           testEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     174          testEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    176175        }
    177176
    178         return rows.Select(row => testEstimatedValuesCache[row]);
     177        return rows.Select(row => testEvaluationCache[row]);
    179178      }
    180179    }
     
    208207
    209208    public override IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) {
    210       var rowsToEvaluate = rows.Except(estimatedValuesCache.Keys);
     209      var rowsToEvaluate = rows.Except(evaluationCache.Keys);
    211210      var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    212211      var valuesEnumerator = (from xs in GetEstimatedClassValueVectors(ProblemData.Dataset, rowsToEvaluate)
     
    215214
    216215      while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    217         estimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    218       }
    219 
    220       return rows.Select(row => estimatedValuesCache[row]);
     216        evaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     217      }
     218
     219      return rows.Select(row => evaluationCache[row]);
    221220    }
    222221
     
    244243
    245244    protected override void OnProblemDataChanged() {
    246       trainingEstimatedValuesCache.Clear();
    247       testEstimatedValuesCache.Clear();
    248       estimatedValuesCache.Clear();
     245      trainingEvaluationCache.Clear();
     246      testEvaluationCache.Clear();
     247      evaluationCache.Clear();
    249248
    250249      IClassificationProblemData problemData = new ClassificationProblemData(ProblemData.Dataset,
     
    277276      classificationSolutions.AddRange(solutions);
    278277
    279       trainingEstimatedValuesCache.Clear();
    280       testEstimatedValuesCache.Clear();
    281       estimatedValuesCache.Clear();
     278      trainingEvaluationCache.Clear();
     279      testEvaluationCache.Clear();
     280      evaluationCache.Clear();
    282281    }
    283282    public void RemoveClassificationSolutions(IEnumerable<IClassificationSolution> solutions) {
    284283      classificationSolutions.RemoveRange(solutions);
    285284
    286       trainingEstimatedValuesCache.Clear();
    287       testEstimatedValuesCache.Clear();
    288       estimatedValuesCache.Clear();
     285      trainingEvaluationCache.Clear();
     286      testEvaluationCache.Clear();
     287      evaluationCache.Clear();
    289288    }
    290289
     
    309308      testPartitions[solution.Model] = solution.ProblemData.TestPartition;
    310309
    311       trainingEstimatedValuesCache.Clear();
    312       testEstimatedValuesCache.Clear();
    313       estimatedValuesCache.Clear();
     310      trainingEvaluationCache.Clear();
     311      testEvaluationCache.Clear();
     312      evaluationCache.Clear();
    314313    }
    315314
     
    320319      testPartitions.Remove(solution.Model);
    321320
    322       trainingEstimatedValuesCache.Clear();
    323       testEstimatedValuesCache.Clear();
    324       estimatedValuesCache.Clear();
     321      trainingEvaluationCache.Clear();
     322      testEvaluationCache.Clear();
     323      evaluationCache.Clear();
    325324    }
    326325  }
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionEnsembleSolution.cs

    r8152 r8167  
    3737  [Creatable("Data Analysis - Ensembles")]
    3838  public sealed class RegressionEnsembleSolution : RegressionSolution, IRegressionEnsembleSolution {
    39     private readonly Dictionary<int, double> trainingEstimatedValuesCache = new Dictionary<int, double>();
    40     private readonly Dictionary<int, double> testEstimatedValuesCache = new Dictionary<int, double>();
    41     private readonly Dictionary<int, double> estimatedValuesCache = new Dictionary<int, double>();
     39    private readonly Dictionary<int, double> trainingEvaluationCache = new Dictionary<int, double>();
     40    private readonly Dictionary<int, double> testEvaluationCache = new Dictionary<int, double>();
    4241
    4342    public new IRegressionEnsembleModel Model {
     
    158157      get {
    159158        var rows = ProblemData.TrainingIndices;
    160         var rowsToEvaluate = rows.Except(trainingEstimatedValuesCache.Keys);
     159        var rowsToEvaluate = rows.Except(trainingEvaluationCache.Keys);
    161160        var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    162161        var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, (r, m) => RowIsTrainingForModel(r, m) && !RowIsTestForModel(r, m)).GetEnumerator();
    163162
    164163        while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    165           trainingEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     164          trainingEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    166165        }
    167166
    168         return rows.Select(row => trainingEstimatedValuesCache[row]);
     167        return rows.Select(row => trainingEvaluationCache[row]);
    169168      }
    170169    }
     
    173172      get {
    174173        var rows = ProblemData.TestIndices;
    175         var rowsToEvaluate = rows.Except(testEstimatedValuesCache.Keys);
     174        var rowsToEvaluate = rows.Except(testEvaluationCache.Keys);
    176175        var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    177176        var valuesEnumerator = GetEstimatedValues(rowsToEvaluate, RowIsTestForModel).GetEnumerator();
    178177
    179178        while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    180           testEstimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     179          testEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    181180        }
    182181
    183         return rows.Select(row => testEstimatedValuesCache[row]);
     182        return rows.Select(row => testEvaluationCache[row]);
    184183      }
    185184    }
     
    213212
    214213    public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {
    215       var rowsToEvaluate = rows.Except(estimatedValuesCache.Keys);
     214      var rowsToEvaluate = rows.Except(evaluationCache.Keys);
    216215      var rowsEnumerator = rowsToEvaluate.GetEnumerator();
    217216      var valuesEnumerator = (from xs in GetEstimatedValueVectors(ProblemData.Dataset, rowsToEvaluate)
     
    220219
    221220      while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
    222         estimatedValuesCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
    223       }
    224 
    225       return rows.Select(row => estimatedValuesCache[row]);
     221        evaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     222      }
     223
     224      return rows.Select(row => evaluationCache[row]);
    226225    }
    227226
     
    244243
    245244    protected override void OnProblemDataChanged() {
    246       trainingEstimatedValuesCache.Clear();
    247       testEstimatedValuesCache.Clear();
    248       estimatedValuesCache.Clear();
     245      trainingEvaluationCache.Clear();
     246      testEvaluationCache.Clear();
     247      evaluationCache.Clear();
    249248      IRegressionProblemData problemData = new RegressionProblemData(ProblemData.Dataset,
    250249                                                                     ProblemData.AllowedInputVariables,
     
    276275      regressionSolutions.AddRange(solutions);
    277276
    278       trainingEstimatedValuesCache.Clear();
    279       testEstimatedValuesCache.Clear();
    280       estimatedValuesCache.Clear();
     277      trainingEvaluationCache.Clear();
     278      testEvaluationCache.Clear();
     279      evaluationCache.Clear();
    281280    }
    282281    public void RemoveRegressionSolutions(IEnumerable<IRegressionSolution> solutions) {
    283282      regressionSolutions.RemoveRange(solutions);
    284283
    285       trainingEstimatedValuesCache.Clear();
    286       testEstimatedValuesCache.Clear();
    287       estimatedValuesCache.Clear();
     284      trainingEvaluationCache.Clear();
     285      testEvaluationCache.Clear();
     286      evaluationCache.Clear();
    288287    }
    289288
     
    308307      testPartitions[solution.Model] = solution.ProblemData.TestPartition;
    309308
    310       trainingEstimatedValuesCache.Clear();
    311       testEstimatedValuesCache.Clear();
    312       estimatedValuesCache.Clear();
     309      trainingEvaluationCache.Clear();
     310      testEvaluationCache.Clear();
     311      evaluationCache.Clear();
    313312    }
    314313
     
    319318      testPartitions.Remove(solution.Model);
    320319
    321       trainingEstimatedValuesCache.Clear();
    322       testEstimatedValuesCache.Clear();
    323       estimatedValuesCache.Clear();
     320      trainingEvaluationCache.Clear();
     321      testEvaluationCache.Clear();
     322      evaluationCache.Clear();
    324323    }
    325324  }
Note: See TracChangeset for help on using the changeset viewer.