- Timestamp:
- 08/16/10 19:17:13 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis/3.3/Evaluators/OnlineCovarianceEvaluator.cs
r4068 r4233 25 25 public class OnlineCovarianceEvaluator : IOnlineEvaluator { 26 26 27 private double originalMean, estimatedMean, Cn;27 private double xMean, yMean, Cn; 28 28 private int n; 29 29 public double Covariance { … … 47 47 n = 0; 48 48 Cn = 0.0; 49 originalMean = 0.0;50 estimatedMean = 0.0;49 xMean = 0.0; 50 yMean = 0.0; 51 51 } 52 52 53 public void Add(double original, double estimated) {54 if (double.IsNaN( estimated) || double.IsInfinity(estimated) ||55 double.IsNaN( original) || double.IsInfinity(original)) {53 public void Add(double x, double y) { 54 if (double.IsNaN(x) || double.IsInfinity(x) || 55 double.IsNaN(y) || double.IsInfinity(y)) { 56 56 throw new ArgumentException("Covariance is not defined for series containing NaN or infinity elements"); 57 57 } else { 58 58 n++; 59 59 // online calculation of tMean 60 originalMean = originalMean + (original - originalMean) / n; 61 double delta = estimated - estimatedMean; // delta = (y - yMean(n-1)) 62 estimatedMean = estimatedMean + delta / n; 60 61 xMean = xMean + (x - xMean) / n; 62 double deltaY = y - yMean; // delta = (y - yMean(n-1)) 63 yMean = yMean + deltaY / n; 63 64 64 65 // online calculation of covariance 65 Cn = Cn + delta * (original - originalMean); // C(n) = C(n-1) + (y - yMean(n-1)) (t - tMean(n))66 Cn = Cn + deltaY * (x - xMean); // C(n) = C(n-1) + (y - yMean(n-1)) (x - xMean(n)) 66 67 } 67 68 }
Note: See TracChangeset
for help on using the changeset viewer.