Changeset 6964 for trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs
- Timestamp:
- 11/08/11 12:16:27 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs
r5945 r6964 26 26 public class OnlineCovarianceCalculator : IOnlineCalculator { 27 27 28 private double originalMean, estimatedMean, Cn;28 private double xMean, yMean, Cn; 29 29 private int n; 30 30 public double Covariance { … … 49 49 n = 0; 50 50 Cn = 0.0; 51 originalMean = 0.0;52 estimatedMean = 0.0;51 xMean = 0.0; 52 yMean = 0.0; 53 53 errorState = OnlineCalculatorError.InsufficientElementsAdded; 54 54 } 55 55 56 public void Add(double original, double estimated) {57 if (double.IsNaN( estimated) || double.IsInfinity(estimated) || double.IsNaN(original) || double.IsInfinity(original) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) {56 public void Add(double x, double y) { 57 if (double.IsNaN(y) || double.IsInfinity(y) || double.IsNaN(x) || double.IsInfinity(x) || (errorState & OnlineCalculatorError.InvalidValueAdded) > 0) { 58 58 errorState = errorState | OnlineCalculatorError.InvalidValueAdded; 59 59 } else { … … 62 62 63 63 // online calculation of tMean 64 originalMean = originalMean + (original - originalMean) / n;65 double delta = estimated - estimatedMean; // delta = (y - yMean(n-1))66 estimatedMean = estimatedMean + delta / n;64 xMean = xMean + (x - xMean) / n; 65 double delta = y - yMean; // delta = (y - yMean(n-1)) 66 yMean = yMean + delta / n; 67 67 68 68 // online calculation of covariance 69 Cn = Cn + delta * ( original - originalMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n))69 Cn = Cn + delta * (x - xMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n)) 70 70 } 71 71 } … … 79 79 // always move forward both enumerators (do not use short-circuit evaluation!) 80 80 while (firstEnumerator.MoveNext() & secondEnumerator.MoveNext()) { 81 double estimated= secondEnumerator.Current;82 double original= firstEnumerator.Current;83 covarianceCalculator.Add( original, estimated);81 double x = secondEnumerator.Current; 82 double y = firstEnumerator.Current; 83 covarianceCalculator.Add(x, y); 84 84 if (covarianceCalculator.ErrorState != OnlineCalculatorError.None) break; 85 85 }
Note: See TracChangeset
for help on using the changeset viewer.