Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.MultiVariate.TimeSeriesPrognosis/3.3/Evaluators/OnlineDirectionalSymmetryEvaluator.cs @ 6627

Last change on this file since 6627 was 4400, checked in by gkronber, 14 years ago

Fixed bug in directional symmetry evaluator. #1142

File size: 1.8 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 OnlineDirectionalSymmetryEvaluator : IOnlineTimeSeriesPrognosisEvaluator {
13    private double prevEstimated;
14    private double prevOriginal;
15    private int n;
16    private int nCorrect;
17
18    public double DirectionalSymmetry {
19      get {
20        if (n < 1) return 0.0;
21        return (double)nCorrect / n * 100.0;
22      }
23    }
24
25    public OnlineDirectionalSymmetryEvaluator() {
26      Reset();
27    }
28
29    #region IOnlineEvaluator Members
30    public double Value {
31      get { return DirectionalSymmetry; }
32    }
33
34    public void Add(double original, double estimated) {
35      if (double.IsNaN(original) || double.IsInfinity(original) || double.IsNaN(estimated) || double.IsInfinity(estimated)) {
36        throw new ArgumentException("Directional symmetry is not defined for series containing NaN or infinity values.");
37      }
38      if (!double.IsNaN(prevOriginal)) {
39        if ((original - prevOriginal) * (estimated - prevEstimated) >= 0.0) {
40          nCorrect++;
41        }
42        n++;
43      }
44    }
45
46    public void Reset() {
47      n = 0;
48      nCorrect = 0;
49      prevOriginal = double.NaN;
50      prevEstimated = double.NaN;
51    }
52
53    #endregion
54
55    #region IOnlineTimeSeriesPrognosisEvaluator Members
56
57    public void StartNewPredictionWindow(double lastKnownOriginalValue) {
58      prevEstimated = lastKnownOriginalValue;
59      prevOriginal = lastKnownOriginalValue;
60    }
61
62    #endregion
63  }
64}
Note: See TracBrowser for help on using the repository browser.