Ignore:
Timestamp:
07/28/11 13:57:05 (11 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/Classification/ClassificationSolution.cs

    r6589 r6606  
    3131  [StorableClass]
    3232  public abstract class ClassificationSolution : ClassificationSolutionBase {
     33    protected readonly Dictionary<int, double> evaluationCache;
     34
    3335    [StorableConstructor]
    34     protected ClassificationSolution(bool deserializing) : base(deserializing) { }
     36    protected ClassificationSolution(bool deserializing)
     37      : base(deserializing) {
     38      evaluationCache = new Dictionary<int, double>();
     39    }
    3540    protected ClassificationSolution(ClassificationSolution original, Cloner cloner)
    3641      : base(original, cloner) {
     42      evaluationCache = new Dictionary<int, double>(original.evaluationCache);
    3743    }
    3844    public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData)
    3945      : base(model, problemData) {
     46      evaluationCache = new Dictionary<int, double>();
    4047    }
    4148
     
    5158
    5259    public override IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) {
    53       return Model.GetEstimatedClassValues(ProblemData.Dataset, rows);
     60      var rowsToEvaluate = rows.Except(evaluationCache.Keys);
     61      var rowsEnumerator = rowsToEvaluate.GetEnumerator();
     62      var valuesEnumerator = Model.GetEstimatedClassValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator();
     63
     64      while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) {
     65        evaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current);
     66      }
     67
     68      return rows.Select(row => evaluationCache[row]);
     69    }
     70
     71    protected override void OnProblemDataChanged() {
     72      evaluationCache.Clear();
     73      base.OnProblemDataChanged();
     74    }
     75
     76    protected override void OnModelChanged() {
     77      evaluationCache.Clear();
     78      base.OnModelChanged();
    5479    }
    5580  }
Note: See TracChangeset for help on using the changeset viewer.