- Timestamp:
- 04/09/10 17:28:32 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/SimpleMSEEvaluator.cs
r3253 r3294 39 39 } 40 40 41 public static double Calculate(DoubleMatrix values) { 42 double sse = 0; 43 double cnt = 0; 44 for (int i = 0; i < values.Rows; i++) { 45 double estimated = values[i, ESTIMATION_INDEX]; 46 double target = values[i, ORIGINAL_INDEX]; 47 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) && 48 !double.IsNaN(target) && !double.IsInfinity(target)) { 49 double error = estimated - target; 41 public static double Calculate(IEnumerable<double> original, IEnumerable<double> estimated) { 42 double sse = 0.0; 43 int cnt = 0; 44 var originalEnumerator = original.GetEnumerator(); 45 var estimatedEnumerator = estimated.GetEnumerator(); 46 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 47 double e = estimatedEnumerator.Current; 48 double o = originalEnumerator.Current; 49 if (!double.IsNaN(e) && !double.IsInfinity(e) && 50 !double.IsNaN(o) && !double.IsInfinity(o)) { 51 double error = e - o; 50 52 sse += error * error; 51 53 cnt++; 52 54 } 53 55 } 54 if (cnt > 0) { 56 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 57 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 58 } else if (cnt == 0) { 59 throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf"); 60 } else { 55 61 double mse = sse / cnt; 56 62 return mse; 57 } else {58 throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");59 63 } 64 } 65 66 public static double Calculate(DoubleMatrix values) { 67 var original = from row in Enumerable.Range(0, values.Rows) 68 select values[row, ORIGINAL_INDEX]; 69 var estimated = from row in Enumerable.Range(0, values.Rows) 70 select values[row, ORIGINAL_INDEX]; 71 return Calculate(original, estimated); 60 72 } 61 73 }
Note: See TracChangeset
for help on using the changeset viewer.