Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Evaluators/OnlineWeightedDirectionalSymmetryEvaluator.cs @ 11247

Last change on this file since 11247 was 4113, checked in by gkronber, 14 years ago

Added plugin for time series prognosis. #1081

File size: 2.0 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Problems.DataAnalysis.Evaluators;
8using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
9using HeuristicLab.Parameters;
10
11namespace HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis {
12  public class OnlineWeightedDirectionalSymmetryEvaluator : IOnlineTimeSeriesPrognosisEvaluator {
13    private double prevEstimated;
14    private double prevOriginal;
15    private double incorrectSum;
16    private double correctSum;
17
18    public double WeightedDirectionalSymmetry {
19      get {
20        return incorrectSum / correctSum;
21      }
22    }
23
24    public OnlineWeightedDirectionalSymmetryEvaluator() {
25      Reset();
26    }
27
28    #region IOnlineEvaluator Members
29    public double Value {
30      get { return WeightedDirectionalSymmetry; }
31    }
32
33    public void Add(double original, double estimated) {
34      if (double.IsInfinity(original) || double.IsNaN(original) || double.IsInfinity(estimated) || double.IsNaN(estimated)) {
35        throw new ArgumentException("Weighted directional symmetry is not defined for series containing NaN or infinity values.");
36      }
37
38      // not the first element and a valid estimated value
39      if (!double.IsNaN(prevOriginal)) {
40        double error = Math.Abs(estimated - original);
41        if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0)
42          correctSum += error;
43        else
44          incorrectSum += error;
45      }
46    }
47
48    public void Reset() {
49      correctSum = 0;
50      incorrectSum = 0;
51      prevOriginal = double.NaN;
52      prevEstimated = double.NaN;
53    }
54
55    #endregion
56
57    #region IOnlineTimeSeriesPrognosisEvaluator Members
58
59    public void StartNewPredictionWindow(double referenceOriginalValue) {
60      prevOriginal = referenceOriginalValue;
61      prevEstimated = referenceOriginalValue;
62    }
63
64    #endregion
65  }
66}
Note: See TracBrowser for help on using the repository browser.