Ignore:
Timestamp:
11/08/11 12:16:27 (11 years ago)
Author:
gkronber
Message:

#1670 changed remaining calculators to follow originalValues/estimatedValues convention.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis/3.4/OnlineCalculators/OnlineCovarianceCalcualtor.cs

    r5945 r6964  
    2626  public class OnlineCovarianceCalculator : IOnlineCalculator {
    2727
    28     private double originalMean, estimatedMean, Cn;
     28    private double xMean, yMean, Cn;
    2929    private int n;
    3030    public double Covariance {
     
    4949      n = 0;
    5050      Cn = 0.0;
    51       originalMean = 0.0;
    52       estimatedMean = 0.0;
     51      xMean = 0.0;
     52      yMean = 0.0;
    5353      errorState = OnlineCalculatorError.InsufficientElementsAdded;
    5454    }
    5555
    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) {
    5858        errorState = errorState | OnlineCalculatorError.InvalidValueAdded;
    5959      } else {
     
    6262
    6363        // 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;
    6767
    6868        // 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))       
    7070      }
    7171    }
     
    7979      // always move forward both enumerators (do not use short-circuit evaluation!)
    8080      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);
    8484        if (covarianceCalculator.ErrorState != OnlineCalculatorError.None) break;
    8585      }
Note: See TracChangeset for help on using the changeset viewer.