- Timestamp:
- 07/05/10 17:14:22 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators
- Files:
-
- 3 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMSEEvaluator.cs
r3462 r3996 45 45 46 46 public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) { 47 double sse = 0.0; 48 int cnt = 0; 47 var onlineMseEvaluator = new OnlineMeanSquaredErrorEvaluator(); 49 48 var originalEnumerator = original.GetEnumerator(); 50 49 var estimatedEnumerator = estimated.GetEnumerator(); … … 52 51 double e = estimatedEnumerator.Current; 53 52 double o = originalEnumerator.Current; 54 if (!double.IsNaN(e) && !double.IsInfinity(e) && 55 !double.IsNaN(o) && !double.IsInfinity(o)) { 56 double error = e - o; 57 sse += error * error; 58 cnt++; 59 } 53 onlineMseEvaluator.Add(o, e); 60 54 } 61 55 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 62 56 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 63 } else if (cnt == 0) {64 throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");65 57 } else { 66 double mse = sse / cnt; 67 return mse; 58 return onlineMseEvaluator.MeanSquaredError; 68 59 } 69 60 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMeanAbsolutePercentageErrorEvaluator.cs
r3980 r3996 48 48 49 49 public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) { 50 double sre = 0; 51 int cnt = 0; 50 OnlineMeanAbsolutePercentageErrorEvaluator onlineEvaluator = new OnlineMeanAbsolutePercentageErrorEvaluator(); 52 51 var originalEnumerator = original.GetEnumerator(); 53 52 var estimatedEnumerator = estimated.GetEnumerator(); … … 55 54 double e = estimatedEnumerator.Current; 56 55 double o = originalEnumerator.Current; 57 if (!double.IsNaN(e) && !double.IsInfinity(e) && 58 !double.IsNaN(o) && !double.IsInfinity(o) && !o.IsAlmost(0.0)) { 59 sre += Math.Abs((e - o) / o); 60 cnt++; 61 } 56 onlineEvaluator.Add(o, e); 62 57 } 63 58 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 64 59 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 65 } else if (cnt == 0) {66 throw new ArgumentException("Average relative error is not defined for input vectors of NaN or Inf");67 60 } else { 68 return sre / cnt;61 return onlineEvaluator.MeanAbsolutePercentageError; 69 62 } 70 63 } -
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleRSquaredEvaluator.cs
r3452 r3996 49 49 50 50 public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) { 51 var onlinePearsonRSquaredEvaluator = new OnlinePearsonsRSquaredEvaluator(); 51 52 var originalEnumerator = original.GetEnumerator(); 52 53 var estimatedEnumerator = estimated.GetEnumerator(); 53 originalEnumerator.MoveNext();54 estimatedEnumerator.MoveNext();55 double e = estimatedEnumerator.Current;56 double o = originalEnumerator.Current;57 54 58 // stable and iterative calculation of R² in one pass over original and estimated59 double sum_sq_x = 0.0;60 double sum_sq_y = 0.0;61 double sum_coproduct = 0.0;62 if (IsInvalidValue(o) || IsInvalidValue(e)) {63 throw new ArgumentException("R² is not defined for variables with NaN or infinity values.");64 }65 double mean_x = o;66 double mean_y = e;67 int n = 1;68 55 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 69 e = estimatedEnumerator.Current; 70 o = originalEnumerator.Current; 71 double sweep = (n - 1.0) / n; 72 if (IsInvalidValue(o) || IsInvalidValue(e)) { 73 throw new ArgumentException("Correlation coefficient is not defined for variables with NaN or infinity values."); 74 } 75 double delta_x = o - mean_x; 76 double delta_y = e - mean_y; 77 sum_sq_x += delta_x * delta_x * sweep; 78 sum_sq_y += delta_y * delta_y * sweep; 79 sum_coproduct += delta_x * delta_y * sweep; 80 mean_x += delta_x / n; 81 mean_y += delta_y / n; 82 n++; 56 double e = estimatedEnumerator.Current; 57 double o = originalEnumerator.Current; 58 onlinePearsonRSquaredEvaluator.Add(o, e); 83 59 } 84 60 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 85 61 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 86 62 } else { 87 double pop_sd_x = Math.Sqrt(sum_sq_x / n); 88 double pop_sd_y = Math.Sqrt(sum_sq_y / n); 89 double cov_x_y = sum_coproduct / n; 90 91 if (pop_sd_x.IsAlmost(0.0) || pop_sd_y.IsAlmost(0.0)) 92 return 0.0; 93 else { 94 double r = cov_x_y / (pop_sd_x * pop_sd_y); 95 return r * r; 96 } 63 return onlinePearsonRSquaredEvaluator.RSquared; 97 64 } 98 65 }
Note: See TracChangeset
for help on using the changeset viewer.