Changeset 3996 for trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
- Timestamp:
- 07/05/10 17:14:22 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r3995 r3996 83 83 84 84 public static double CalculateWithScaling(ISymbolicExpressionTreeInterpreter interpreter, SymbolicExpressionTree solution, double lowerEstimationLimit, double upperEstimationLimit, Dataset dataset, string targetVariable, int start, int end, double beta, double alpha) { 85 //IEnumerable<double> estimatedValues = from x in interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start))86 // let boundedX = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, x * beta + alpha))87 // select double.IsNaN(boundedX) ? upperEstimationLimit : boundedX;88 85 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, Enumerable.Range(start, end - start)); 89 86 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, start, end); 90 87 IEnumerator<double> originalEnumerator = originalValues.GetEnumerator(); 91 88 IEnumerator<double> estimatedEnumerator = estimatedValues.GetEnumerator(); 92 double cnt = 0; 93 double sse = 0; 89 OnlineMeanSquaredErrorEvaluator mseEvaluator = new OnlineMeanSquaredErrorEvaluator(); 94 90 95 91 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { 96 92 double estimated = estimatedEnumerator.Current * beta + alpha; 97 93 double original = originalEnumerator.Current; 98 estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated));99 94 if (double.IsNaN(estimated)) 100 95 estimated = upperEstimationLimit; 101 if (!double.IsNaN(estimated) && !double.IsInfinity(estimated) && 102 !double.IsNaN(original) && !double.IsInfinity(original)) { 103 double error = estimated - original; 104 sse += error * error; 105 cnt++; 106 } 96 else 97 estimated = Math.Min(upperEstimationLimit, Math.Max(lowerEstimationLimit, estimated)); 98 mseEvaluator.Add(original, estimated); 107 99 } 108 100 109 101 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) { 110 102 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 111 } else if (cnt == 0) {112 throw new ArgumentException("Mean squared errors is not defined for input vectors of NaN or Inf");113 103 } else { 114 double mse = sse / cnt; 115 return mse; 104 return mseEvaluator.MeanSquaredError; 116 105 } 117 106 }
Note: See TracChangeset
for help on using the changeset viewer.