Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/17/11 08:57:23 (14 years ago)
Author:
gkronber
Message:

worked on data analysis feature exploration branch. #1142

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Evaluators/OnlineTheilsUStatisticEvaluator.cs

    r4113 r5305  
    1414    private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator;
    1515    private double prevOriginal;
     16    private int windowSize;
     17    private Queue<double> movingAverageWindow;
    1618
    1719    public double TheilsUStatistic {
     
    2123    }
    2224
    23     public OnlineTheilsUStatisticEvaluator() {
     25    public OnlineTheilsUStatisticEvaluator()
     26      : this(1) {
     27    }
     28
     29    public OnlineTheilsUStatisticEvaluator(int movingAverageWindowSize) {
     30      this.windowSize = movingAverageWindowSize;
     31      movingAverageWindow = new Queue<double>(windowSize);
    2432      squaredErrorMeanCalculator = new OnlineMeanAndVarianceCalculator();
    2533      unbiasedEstimatorMeanCalculator = new OnlineMeanAndVarianceCalculator();
     
    4250        squaredErrorMeanCalculator.Add(errorEstimatedChange * errorEstimatedChange);
    4351
    44         // error of naive model y(t+1) = y(t)
    45         double errorNoChange = (original - prevOriginal);
     52        // calculate trend observed in the MA window
     53        double d = CalculateTrend(movingAverageWindow);
     54       
     55        // shift window forward
     56        if (movingAverageWindow.Count == windowSize) {
     57          movingAverageWindow.Dequeue();
     58        }
     59        movingAverageWindow.Enqueue(original);
     60
     61        double errorNoChange = (original - prevOriginal * (1+d));
    4662        unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange);
    4763      }
     64    }
     65
     66    private double CalculateTrend(Queue<double> movingAverageWindow) {
     67      double[] xs = movingAverageWindow.ToArray();
     68      double sum = 0.0;
     69      for (int i = 0; i < xs.Length - 1; i++) {
     70        sum += (xs[i + 1] - xs[i]) / xs[i];
     71      }
     72      return sum / xs.Length;
    4873    }
    4974
     
    5277      squaredErrorMeanCalculator.Reset();
    5378      unbiasedEstimatorMeanCalculator.Reset();
     79      movingAverageWindow.Clear();
    5480    }
    5581
     
    6086    public void StartNewPredictionWindow(double referenceOriginalValue) {
    6187      prevOriginal = referenceOriginalValue;
     88      movingAverageWindow.Enqueue(referenceOriginalValue);
    6289    }
    6390
Note: See TracChangeset for help on using the changeset viewer.