Changeset 6606 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4
- Timestamp:
- 07/28/11 13:57:05 (13 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolution.cs
r6589 r6606 31 31 [StorableClass] 32 32 public abstract class ClassificationSolution : ClassificationSolutionBase { 33 protected readonly Dictionary<int, double> evaluationCache; 34 33 35 [StorableConstructor] 34 protected ClassificationSolution(bool deserializing) : base(deserializing) { } 36 protected ClassificationSolution(bool deserializing) 37 : base(deserializing) { 38 evaluationCache = new Dictionary<int, double>(); 39 } 35 40 protected ClassificationSolution(ClassificationSolution original, Cloner cloner) 36 41 : base(original, cloner) { 42 evaluationCache = new Dictionary<int, double>(original.evaluationCache); 37 43 } 38 44 public ClassificationSolution(IClassificationModel model, IClassificationProblemData problemData) 39 45 : base(model, problemData) { 46 evaluationCache = new Dictionary<int, double>(); 40 47 } 41 48 … … 51 58 52 59 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(); 54 79 } 55 80 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolution.cs
r6604 r6606 33 33 [Item("DiscriminantFunctionClassificationSolution", "Represents a classification solution that uses a discriminant function and classification thresholds.")] 34 34 public abstract class DiscriminantFunctionClassificationSolution : DiscriminantFunctionClassificationSolutionBase { 35 protected readonly Dictionary<int, double> valueEvaluationCache; 36 protected readonly Dictionary<int, double> classValueEvaluationCache; 35 37 36 38 [StorableConstructor] 37 protected DiscriminantFunctionClassificationSolution(bool deserializing) : base(deserializing) { } 39 protected DiscriminantFunctionClassificationSolution(bool deserializing) 40 : base(deserializing) { 41 valueEvaluationCache = new Dictionary<int, double>(); 42 classValueEvaluationCache = new Dictionary<int, double>(); 43 } 38 44 protected DiscriminantFunctionClassificationSolution(DiscriminantFunctionClassificationSolution original, Cloner cloner) 39 45 : base(original, cloner) { 46 valueEvaluationCache = new Dictionary<int, double>(original.valueEvaluationCache); 47 classValueEvaluationCache = new Dictionary<int, double>(original.classValueEvaluationCache); 40 48 } 41 49 protected DiscriminantFunctionClassificationSolution(IDiscriminantFunctionClassificationModel model, IClassificationProblemData problemData) 42 50 : base(model, problemData) { 51 valueEvaluationCache = new Dictionary<int, double>(); 52 classValueEvaluationCache = new Dictionary<int, double>(); 53 54 SetAccuracyMaximizingThresholds(); 43 55 } 44 56 … … 54 66 55 67 public override IEnumerable<double> GetEstimatedClassValues(IEnumerable<int> rows) { 56 return Model.GetEstimatedClassValues(ProblemData.Dataset, rows); 68 var rowsToEvaluate = rows.Except(classValueEvaluationCache.Keys); 69 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 70 var valuesEnumerator = Model.GetEstimatedClassValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator(); 71 72 while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) { 73 classValueEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current); 74 } 75 76 return rows.Select(row => classValueEvaluationCache[row]); 57 77 } 58 78 … … 69 89 70 90 public override IEnumerable<double> GetEstimatedValues(IEnumerable<int> rows) { 71 return Model.GetEstimatedValues(ProblemData.Dataset, rows); 91 var rowsToEvaluate = rows.Except(valueEvaluationCache.Keys); 92 var rowsEnumerator = rowsToEvaluate.GetEnumerator(); 93 var valuesEnumerator = Model.GetEstimatedValues(ProblemData.Dataset, rowsToEvaluate).GetEnumerator(); 94 95 while (rowsEnumerator.MoveNext() & valuesEnumerator.MoveNext()) { 96 valueEvaluationCache.Add(rowsEnumerator.Current, valuesEnumerator.Current); 97 } 98 99 return rows.Select(row => valueEvaluationCache[row]); 100 } 101 102 protected override void OnModelChanged() { 103 valueEvaluationCache.Clear(); 104 classValueEvaluationCache.Clear(); 105 base.OnModelChanged(); 106 } 107 protected override void OnModelThresholdsChanged(System.EventArgs e) { 108 classValueEvaluationCache.Clear(); 109 base.OnModelThresholdsChanged(e); 110 } 111 protected override void OnProblemDataChanged() { 112 valueEvaluationCache.Clear(); 113 classValueEvaluationCache.Clear(); 114 base.OnProblemDataChanged(); 72 115 } 73 116 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/DiscriminantFunctionClassificationSolutionBase.cs
r6604 r6606 86 86 Add(new Result(TestRSquaredResultName, "Squared Pearson's correlation coefficient of the model output and the actual values on the test partition", new DoubleValue())); 87 87 88 SetAccuracyMaximizingThresholds();89 88 RegisterEventHandler(); 90 89 } … … 95 94 } 96 95 97 protected override void OnModelChanged( EventArgs e) {96 protected override void OnModelChanged() { 98 97 DeregisterEventHandler(); 99 98 SetAccuracyMaximizingThresholds(); 100 99 RegisterEventHandler(); 101 base.OnModelChanged( e);100 base.OnModelChanged(); 102 101 } 103 102 … … 149 148 150 149 protected virtual void OnModelThresholdsChanged(EventArgs e) { 151 RecalculateResults();150 CalculateResults(); 152 151 } 153 152 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/DataAnalysisSolution.cs
r6588 r6606 48 48 if (value != null) { 49 49 this[ModelResultName].Value = value; 50 OnModelChanged( EventArgs.Empty);50 OnModelChanged(); 51 51 } 52 52 } … … 62 62 this[ProblemDataResultName].Value = value; 63 63 ProblemData.Changed += new EventHandler(ProblemData_Changed); 64 OnProblemDataChanged( EventArgs.Empty);64 OnProblemDataChanged(); 65 65 } 66 66 } … … 89 89 90 90 private void ProblemData_Changed(object sender, EventArgs e) { 91 OnProblemDataChanged( e);91 OnProblemDataChanged(); 92 92 } 93 93 94 94 public event EventHandler ModelChanged; 95 protected virtual void OnModelChanged( EventArgs e) {95 protected virtual void OnModelChanged() { 96 96 RecalculateResults(); 97 97 var listeners = ModelChanged; 98 if (listeners != null) listeners(this, e);98 if (listeners != null) listeners(this, EventArgs.Empty); 99 99 } 100 100 101 101 public event EventHandler ProblemDataChanged; 102 protected virtual void OnProblemDataChanged( EventArgs e) {102 protected virtual void OnProblemDataChanged() { 103 103 RecalculateResults(); 104 104 var listeners = ProblemDataChanged; 105 if (listeners != null) listeners(this, e);105 if (listeners != null) listeners(this, EventArgs.Empty); 106 106 } 107 107 -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Regression/RegressionSolution.cs
r6602 r6606 31 31 [StorableClass] 32 32 public abstract class RegressionSolution : RegressionSolutionBase { 33 protected readonly Dictionary<int, double> evaluationCache; 34 33 35 [StorableConstructor] 34 protected RegressionSolution(bool deserializing) : base(deserializing) { } 36 protected RegressionSolution(bool deserializing) 37 : base(deserializing) { 38 evaluationCache = new Dictionary<int, double>(); 39 } 35 40 protected RegressionSolution(RegressionSolution original, Cloner cloner) 36 41 : base(original, cloner) { 42 evaluationCache = new Dictionary<int, double>(original.evaluationCache); 37 43 } 38 44 protected RegressionSolution(IRegressionModel model, IRegressionProblemData problemData) 39 45 : base(model, problemData) { 46 evaluationCache = new Dictionary<int, double>(); 40 47 } 41 48 … … 55 62 56 63 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(); 58 83 } 59 84 }
Note: See TracChangeset
for help on using the changeset viewer.