Changeset 4001
- Timestamp:
- 07/06/10 15:07:21 (14 years ago)
- Location:
- trunk/sources
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionScaledMeanSquaredErrorEvaluator.cs
r3996 r4001 116 116 117 117 int cnt = 0; 118 double t Sum= 0;119 double y Sum= 0;120 double yySum= 0;121 double ytSum= 0;118 double tMean = 0; 119 double yMean = 0; 120 double Cn = 0; 121 double M2 = 0; 122 122 123 123 while (originalEnumerator.MoveNext() & estimatedEnumerator.MoveNext()) { … … 126 126 if (IsValidValue(t) && IsValidValue(y)) { 127 127 cnt++; 128 tSum += t; 129 ySum += y; 130 yySum += y * y; 131 ytSum += t * y; 128 // online calculation of tMean 129 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 variance 134 M2 = M2 + delta * (y - yMean); // M2(n) = M2(n-1) + (y - yMean(n-1)) (y - yMean(n)) 135 136 // online calculation of covariance 137 Cn = Cn + delta * (t - tMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n)) 132 138 } 133 139 } … … 139 145 beta = 1; 140 146 } else { 141 double tMean = tSum / cnt; 142 double yMean = ySum / cnt; 143 //division by cnt is omited because the variance and covariance are divided afterwards. 144 double yVariance = yySum - 2 * yMean * ySum + cnt * yMean * yMean; 145 double ytCovariance = ytSum - tMean * ySum - yMean * tSum + cnt * yMean * tMean; 147 // yVariance = M2 / cnt; 148 // ytCovariance = Cn / cnt; 146 149 147 if ( yVariance.IsAlmost(0.0))150 if (M2.IsAlmost(0.0)) 148 151 beta = 1; 149 152 else 150 beta = ytCovariance / yVariance;153 beta = Cn / M2; // omit division by cnt 151 154 152 155 alpha = tMean - beta * yMean;
Note: See TracChangeset
for help on using the changeset viewer.