Changeset 11761
- Timestamp:
- 01/15/15 11:16:05 (10 years ago)
- Location:
- branches/Classification-Extensions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Classification-Extensions/HeuristicLab.Optimization/3.3/ResultCollection.cs
r11718 r11761 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using System.Linq;27 26 28 namespace HeuristicLab.Optimization { 27 namespace HeuristicLab.Optimization { 29 28 [StorableClass] 30 29 [Item("ResultCollection", "Represents a collection of results.")] … … 47 46 48 47 public virtual void CollectResultValues(IDictionary<string, IItem> values) { 49 CollectResultValues(values, string.Empty); 48 CollectResultValues(values, string.Empty); 50 49 } 51 50 … … 67 66 if (result.Value == null) yield break; 68 67 yield return new KeyValuePair<string, IItem>(string.Empty, result.Value); 68 69 69 var resultCollection = result.Value as ResultCollection; 70 if (resultCollection != null) { 70 if (resultCollection != null) { 71 71 var children = new Dictionary<string, IItem>(); 72 72 resultCollection.CollectResultValues(children); -
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/Implementation/Classification/ClassificationSolutionBase.cs
r11685 r11761 128 128 TestNormalizedGiniCoefficient = testNormalizedGini; 129 129 130 trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues , out errorState);131 if ( errorState == OnlineCalculatorError.None)130 trainingPerformanceCalculator.Calculate(originalTrainingClassValues, estimatedTrainingClassValues); 131 if (trainingPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 132 132 ClassificationPerformanceMeasures.SetTrainingResults(trainingPerformanceCalculator); 133 testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues, out errorState); 134 if (errorState == OnlineCalculatorError.None) 133 134 testPerformanceCalculator.Calculate(originalTestClassValues, estimatedTestClassValues); 135 if (testPerformanceCalculator.ErrorState == OnlineCalculatorError.None) 135 136 ClassificationPerformanceMeasures.SetTestResults(testPerformanceCalculator); 136 137 } -
branches/Classification-Extensions/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/ClassificationPerformanceMeasuresCalculator.cs
r11685 r11761 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq;25 using System.Text;26 24 using HeuristicLab.Common; 27 25 … … 32 30 this.positiveClassName = positiveClassName; 33 31 this.positiveClassValue = positiveClassValue; 34 Reset(); 32 Reset(); 35 33 } 36 34 37 35 #region Properties 38 private string positiveClassName;39 private double positiveClassValue;40 36 private int truePositiveCount, falsePositiveCount, trueNegativeCount, falseNegativeCount; 41 37 38 private readonly string positiveClassName; 42 39 public string PositiveClassName { 43 get { 44 return positiveClassName; 45 } 40 get { return positiveClassName; } 46 41 } 42 43 private readonly double positiveClassValue; 47 44 public double PositiveClassValue { 48 get { 49 return positiveClassValue; 50 } 45 get { return positiveClassValue; } 51 46 } 52 47 public double TruePositiveRate { … … 92 87 } 93 88 #endregion 94 89 95 90 public void Reset() { 96 91 truePositiveCount = 0; … … 103 98 public void Add(double originalClassValue, double estimatedClassValue) { 104 99 // ignore cases where original is NaN completely 105 if (!double.IsNaN(originalClassValue)) { 106 if (originalClassValue.IsAlmost(positiveClassValue) 107 || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation 108 if (estimatedClassValue.IsAlmost(originalClassValue)) { 109 truePositiveCount++; 110 } else { 111 if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class 112 falsePositiveCount++; 113 else //misclassification of the positive class 114 falseNegativeCount++; 115 } 116 } else { //negative class/negative class estimation 117 //In a multiclass classification all misclassifications of the negative class 118 //will be treated as true negatives except on positive class estimations 119 trueNegativeCount++; 100 if (double.IsNaN(originalClassValue)) return; 101 102 if (originalClassValue.IsAlmost(positiveClassValue) 103 || estimatedClassValue.IsAlmost(positiveClassValue)) { //positive class/positive class estimation 104 if (estimatedClassValue.IsAlmost(originalClassValue)) { 105 truePositiveCount++; 106 } else { 107 if (estimatedClassValue.IsAlmost(positiveClassValue)) //misclassification of the negative class 108 falsePositiveCount++; 109 else //misclassification of the positive class 110 falseNegativeCount++; 120 111 } 121 errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1 112 } else { //negative class/negative class estimation 113 //In a multiclass classification all misclassifications of the negative class 114 //will be treated as true negatives except on positive class estimations 115 trueNegativeCount++; 122 116 } 117 118 errorState = OnlineCalculatorError.None; // number of (non-NaN) samples >= 1 123 119 } 124 120 125 public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues, 126 out OnlineCalculatorError errorState) { 121 public void Calculate(IEnumerable<double> originalClassValues, IEnumerable<double> estimatedClassValues) { 127 122 IEnumerator<double> originalEnumerator = originalClassValues.GetEnumerator(); 128 123 IEnumerator<double> estimatedEnumerator = estimatedClassValues.GetEnumerator(); … … 137 132 138 133 // check if both enumerators are at the end to make sure both enumerations have the same length 139 if (ErrorState == OnlineCalculatorError.None && 140 (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 134 if (ErrorState == OnlineCalculatorError.None && (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())) { 141 135 throw new ArgumentException("Number of elements in originalValues and estimatedValues enumerations doesn't match."); 142 } else {143 errorState = ErrorState;144 136 } 137 errorState = ErrorState; 145 138 } 146 139 }
Note: See TracChangeset
for help on using the changeset viewer.