Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/28/11 13:57:05 (13 years ago)
Author:
mkommend
Message:

#1604: Enabled caching of evaluation results in data analysis solutions.

File:
1 edited

Legend:

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

    r6602 r6606  
    3131  [StorableClass]
    3232  public abstract class RegressionSolution : RegressionSolutionBase {
     33    protected readonly Dictionary<int, double> evaluationCache;
     34
    3335    [StorableConstructor]
    34     protected RegressionSolution(bool deserializing) : base(deserializing) { }
     36    protected RegressionSolution(bool deserializing)
     37      : base(deserializing) {
     38      evaluationCache = new Dictionary<int, double>();
     39    }
    3540    protected RegressionSolution(RegressionSolution original, Cloner cloner)
    3641      : base(original, cloner) {
     42      evaluationCache = new Dictionary<int, double>(original.evaluationCache);
    3743    }
    3844    protected RegressionSolution(IRegressionModel model, IRegressionProblemData problemData)
    3945      : base(model, problemData) {
     46      evaluationCache = new Dictionary<int, double>();
    4047    }
    4148
     
    5562
    5663    public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) {
    57       return Model.GetEstimatedValues(ProblemData.Dataset, rows);
     64      var rowsToEvaluate = rows.Except(evaluationCache.Keys);
     65      var rowsEnumerator = rowsToEvaluate.GetEnumerator();
     66      var valuesEnumerator = Model.GetEstimatedValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator();
     67
     68      while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
     69        evaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     70      }
     71
     72      return rows.Select(row => evaluationCache[row]);
     73    }
     74
     75    protected override void OnProblemDataChanged() {
     76      evaluationCache.Clear();
     77      base.OnProblemDataChanged();
     78    }
     79
     80    protected override void OnModelChanged() {
     81      evaluationCache.Clear();
     82      base.OnModelChanged();
    5883    }
    5984  }
Note: See TracChangeset for help on using the changeset viewer.