Free cookie consent management tool by TermsFeed Policy Generator

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

#1720 reused evaluationCache from base classes in EnsembleSolutions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.