Changeset 5305 for branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Evaluators
- Timestamp:
- 01/17/11 08:57:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Evaluators/OnlineTheilsUStatisticEvaluator.cs
r4113 r5305 14 14 private OnlineMeanAndVarianceCalculator unbiasedEstimatorMeanCalculator; 15 15 private double prevOriginal; 16 private int windowSize; 17 private Queue<double> movingAverageWindow; 16 18 17 19 public double TheilsUStatistic { … … 21 23 } 22 24 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); 24 32 squaredErrorMeanCalculator = new OnlineMeanAndVarianceCalculator(); 25 33 unbiasedEstimatorMeanCalculator = new OnlineMeanAndVarianceCalculator(); … … 42 50 squaredErrorMeanCalculator.Add(errorEstimatedChange * errorEstimatedChange); 43 51 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)); 46 62 unbiasedEstimatorMeanCalculator.Add(errorNoChange * errorNoChange); 47 63 } 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; 48 73 } 49 74 … … 52 77 squaredErrorMeanCalculator.Reset(); 53 78 unbiasedEstimatorMeanCalculator.Reset(); 79 movingAverageWindow.Clear(); 54 80 } 55 81 … … 60 86 public void StartNewPredictionWindow(double referenceOriginalValue) { 61 87 prevOriginal = referenceOriginalValue; 88 movingAverageWindow.Enqueue(referenceOriginalValue); 62 89 } 63 90
Note: See TracChangeset
for help on using the changeset viewer.