- Timestamp:
- 08/08/11 17:47:46 (13 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineMeanAbsoluteErrorCalculator.cs
r6641 r6643 24 24 25 25 namespace HeuristicLab.Problems.DataAnalysis { 26 public class OnlineMean SquaredErrorCalculator : IOnlineCalculator {26 public class OnlineMeanAbsoluteErrorCalculator : IOnlineCalculator { 27 27 28 private double s se;28 private double sae; 29 29 private int n; 30 public double Mean SquaredError {30 public double MeanAbsoluteError { 31 31 get { 32 return n > 0 ? s se / n : 0.0;32 return n > 0 ? sae / n : 0.0; 33 33 } 34 34 } 35 35 36 public OnlineMean SquaredErrorCalculator() {36 public OnlineMeanAbsoluteErrorCalculator() { 37 37 Reset(); 38 38 } … … 44 44 } 45 45 public double Value { 46 get { return Mean SquaredError; }46 get { return MeanAbsoluteError; } 47 47 } 48 48 public void Reset() { 49 49 n = 0; 50 s se = 0.0;50 sae = 0.0; 51 51 errorState = OnlineCalculatorError.InsufficientElementsAdded; 52 52 } … … 58 58 } else { 59 59 double error = estimated - original; 60 s se += error * error;60 sae += Math.Abs(error); 61 61 n++; 62 62 errorState = errorState & (~OnlineCalculatorError.InsufficientElementsAdded); // n >= 1 … … 68 68 IEnumerator<double> firstEnumerator = first.GetEnumerator(); 69 69 IEnumerator<double> secondEnumerator = second.GetEnumerator(); 70 OnlineMean SquaredErrorCalculator mseCalculator = new OnlineMeanSquaredErrorCalculator();70 OnlineMeanAbsoluteErrorCalculator maeCalculator = new OnlineMeanAbsoluteErrorCalculator(); 71 71 72 72 // always move forward both enumerators (do not use short-circuit evaluation!) … … 74 74 double estimated = secondEnumerator.Current; 75 75 double original = firstEnumerator.Current; 76 m seCalculator.Add(original, estimated);77 if (m seCalculator.ErrorState != OnlineCalculatorError.None) break;76 maeCalculator.Add(original, estimated); 77 if (maeCalculator.ErrorState != OnlineCalculatorError.None) break; 78 78 } 79 79 80 80 // check if both enumerators are at the end to make sure both enumerations have the same length 81 if (m seCalculator.ErrorState == OnlineCalculatorError.None &&81 if (maeCalculator.ErrorState == OnlineCalculatorError.None && 82 82 (secondEnumerator.MoveNext() || firstEnumerator.MoveNext())) { 83 83 throw new ArgumentException("Number of elements in first and second enumeration doesn't match."); 84 84 } else { 85 errorState = m seCalculator.ErrorState;86 return m seCalculator.MeanSquaredError;85 errorState = maeCalculator.ErrorState; 86 return maeCalculator.MeanAbsoluteError; 87 87 } 88 88 }
Note: See TracChangeset
for help on using the changeset viewer.