- Timestamp:
- 10/05/10 16:30:57 (14 years ago)
- Location:
- branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanAndVarianceSquaredErrorEvaluator.cs
r4460 r4555 126 126 IEnumerable<double> originalValues = dataset.GetEnumeratedVariableValues(targetVariable, rows); 127 127 IEnumerable<double> estimatedValues = interpreter.GetSymbolicExpressionTreeValues(solution, dataset, rows); 128 CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha);128 SymbolicRegressionScaledMeanSquaredErrorEvaluator.CalculateScalingParameters(originalValues, estimatedValues, out beta, out alpha); 129 129 130 130 return CalculateWithScaling(interpreter, solution, lowerEstimationLimit, upperEstimationLimit, dataset, targetVariable, rows, beta, alpha, out meanSE, out varianceSE, out count, out bias, out variance, out covariance); … … 174 174 } 175 175 } 176 177 /// <summary>178 /// Calculates linear scaling parameters in one pass.179 /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.180 /// http://www.springerlink.com/content/x035121165125175/181 /// </summary>182 public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) {183 IEnumerator<double> originalEnumerator = original.GetEnumerator();184 IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator();185 OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator();186 OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator();187 OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator();188 int cnt = 0;189 190 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) {191 double y = estimatedEnumerator.Current;192 double t = originalEnumerator.Current;193 if (IsValidValue(t) && IsValidValue(y)) {194 tMeanCalculator.Add(t);195 yVarianceCalculator.Add(y);196 ytCovarianceEvaluator.Add(y, t);197 198 cnt++;199 }200 }201 202 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext())203 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match.");204 if (cnt < 2) {205 alpha = 0;206 beta = 1;207 } else {208 if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0))209 beta = 1;210 else211 beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance;212 213 alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean;214 }215 }216 217 private static bool IsValidValue(double d) {218 return !double.IsInfinity(d) && !double.IsNaN(d) && d > -1.0E07 && d < 1.0E07; // don't consider very large or very small values for scaling219 }220 176 } 221 177 } -
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r4458 r4555 100 100 } 101 101 102 /// <summary>103 /// Calculates linear scaling parameters in one pass.104 /// The formulas to calculate the scaling parameters were taken from Scaled Symblic Regression by Maarten Keijzer.105 /// http://www.springerlink.com/content/x035121165125175/106 /// </summary>107 102 public static void CalculateScalingParameters(IEnumerable<double> original, IEnumerable<double> estimated, out double beta, out double alpha) { 108 103 IEnumerator<double> originalEnumerator = original.GetEnumerator(); 109 104 IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator(); 110 OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 111 OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator(); 112 OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator(); 113 int cnt = 0; 105 OnlineLinearScalingCalculator linearScalingCalculator = new OnlineLinearScalingCalculator(); 114 106 115 107 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 117 109 double t = originalEnumerator.Current; 118 110 if (IsValidValue(t) && IsValidValue(y)) { 119 tMeanCalculator.Add(t); 120 yVarianceCalculator.Add(y); 121 ytCovarianceEvaluator.Add(y, t); 122 123 cnt++; 111 linearScalingCalculator.Add(t, y); 124 112 } 125 113 } … … 127 115 if (estimatedEnumerator.MoveNext() || originalEnumerator.MoveNext()) 128 116 throw new ArgumentException("Number of elements in original and estimated enumeration doesn't match."); 129 if (cnt < 2) { 130 alpha = 0; 131 beta = 1; 132 } else { 133 if (yVarianceCalculator.PopulationVariance.IsAlmost(0.0)) 134 beta = 1; 135 else 136 beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.PopulationVariance; 137 138 alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean; 117 else { 118 beta = linearScalingCalculator.Beta; 119 alpha = linearScalingCalculator.Alpha; 139 120 } 140 121 }
Note: See TracChangeset
for help on using the changeset viewer.