- Timestamp:
- 07/12/10 18:46:59 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r4001 r4027 114 114 IEnumerator<double> originalEnumerator = original.GetEnumerator(); 115 115 IEnumerator<double> estimatedEnumerator = estimated.GetEnumerator(); 116 116 OnlineMeanAndVarianceCalculator yVarianceCalculator = new OnlineMeanAndVarianceCalculator(); 117 OnlineMeanAndVarianceCalculator tMeanCalculator = new OnlineMeanAndVarianceCalculator(); 118 OnlineCovarianceEvaluator ytCovarianceEvaluator = new OnlineCovarianceEvaluator(); 117 119 int cnt = 0; 118 double tMean = 0;119 double yMean = 0;120 double Cn = 0;121 double M2 = 0;122 120 123 121 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 125 123 double t = originalEnumerator.Current; 126 124 if (IsValidValue(t) && IsValidValue(y)) { 125 tMeanCalculator.Add(t); 126 yVarianceCalculator.Add(y); 127 ytCovarianceEvaluator.Add(y, t); 128 127 129 cnt++; 128 // online calculation of tMean129 tMean = tMean + (t - tMean) / cnt;130 double delta = y - yMean; // delta = (y - yMean(n-1))131 yMean = yMean + delta / cnt;132 133 // online calculation of variance134 M2 = M2 + delta * (y - yMean); // M2(n) = M2(n-1) + (y - yMean(n-1)) (y - yMean(n))135 136 // online calculation of covariance137 Cn = Cn + delta * (t - tMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n))138 130 } 139 131 } … … 145 137 beta = 1; 146 138 } else { 147 // yVariance = M2 / cnt; 148 // ytCovariance = Cn / cnt; 149 150 if (M2.IsAlmost(0.0)) 139 if (yVarianceCalculator.Variance.IsAlmost(0.0)) 151 140 beta = 1; 152 141 else 153 beta = Cn / M2; // omit division by cnt142 beta = ytCovarianceEvaluator.Covariance / yVarianceCalculator.Variance; 154 143 155 alpha = tMean - beta * yMean;144 alpha = tMeanCalculator.Mean - beta * yVarianceCalculator.Mean; 156 145 } 157 146 }
Note: See TracChangeset
for help on using the changeset viewer.