Changeset 5746
- Timestamp:
- 03/18/11 09:57:44 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineLinearScalingParameterCalculator.cs
r5722 r5746 78 78 /// </summary> 79 79 public void Add(double original, double target) { 80 if (IsValidValue(original) && IsValidValue(target)) {81 82 83 80 // validity of values is checked in mean clculator and covariance calculator 81 targetMeanCalculator.Add(target); 82 originalMeanAndVarianceCalculator.Add(original); 83 originalTargetCovarianceEvaluator.Add(original, target); 84 84 85 cnt++; 86 } 85 cnt++; 87 86 } 88 89 private static bool IsValidValue(double d) {90 return !double.IsInfinity(d) && !double.IsNaN(d) && d > -1.0E07 && d < 1.0E07; // don't consider very large or very small values for scaling91 }92 93 87 94 88 /// <summary> … … 109 103 double originalElement = originalEnumerator.Current; 110 104 double targetElement = targetEnumerator.Current; 111 calculator.Add(originalElement, targetElement); 105 // don't consider very large or very small values for scaling 106 // careful: this also excludes infinity and NaN values 107 if (originalElement > -1.0E07 && originalElement < 1.0E07) { 108 calculator.Add(originalElement, targetElement); 109 } 112 110 } 113 111 -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineMeanSquaredErrorEvaluator.cs
r5564 r5746 30 30 public double MeanSquaredError { 31 31 get { 32 if (n < 1) 33 throw new InvalidOperationException("No elements"); 34 else 35 return sse / n; 32 return n > 0 ? sse / n : 0.0; 36 33 } 37 34 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlineNormalizedMeanSquaredErrorEvaluator.cs
r5564 r5746 30 30 public double NormalizedMeanSquaredError { 31 31 get { 32 return meanSquaredErrorCalculator.Mean / originalVarianceCalculator.Variance; 32 double var = originalVarianceCalculator.Variance; 33 double m = meanSquaredErrorCalculator.Mean; 34 return var > 0 ? m / var : 0.0; 33 35 } 34 36 } … … 51 53 52 54 public void Add(double original, double estimated) { 53 if (double.IsNaN(estimated) || double.IsInfinity(estimated) || 54 double.IsNaN(original) || double.IsInfinity(original)) { 55 throw new ArgumentException("Mean squared error is not defined for NaN or infinity elements"); 56 } else { 57 double error = estimated - original; 58 meanSquaredErrorCalculator.Add(error * error); 59 originalVarianceCalculator.Add(original); 60 } 55 // no need to check for validity of values explicitly as it is checked in the meanAndVariance calculator anyway 56 double error = estimated - original; 57 meanSquaredErrorCalculator.Add(error * error); 58 originalVarianceCalculator.Add(original); 61 59 } 62 60 #endregion -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis/3.4/OnlineEvaluators/OnlinePearsonsRSquaredEvaluator.cs
r5742 r5746 56 56 57 57 public void Add(double x, double y) { 58 if (IsInvalidValue(x) || IsInvalidValue(y)) { 59 throw new ArgumentException("R² is not defined for variables with NaN or infinity values."); 60 } 58 // no need to check validity of values explicitly here as it is checked in all three evaluators 61 59 covEvaluator.Add(x, y); 62 60 sxEvaluator.Add(x); … … 65 63 66 64 #endregion 67 68 private static bool IsInvalidValue(double x) {69 return double.IsNaN(x) || double.IsInfinity(x);70 }71 65 72 66 public static double Calculate(IEnumerable<double> first, IEnumerable<double> second) { … … 79 73 double estimated = secondEnumerator.Current; 80 74 double original = firstEnumerator.Current; 81 if (!IsInvalidValue(estimated) && !IsInvalidValue(original)) 82 rSquaredEvaluator.Add(original, estimated); 75 rSquaredEvaluator.Add(original, estimated); 83 76 } 84 77
Note: See TracChangeset
for help on using the changeset viewer.