1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 | using HeuristicLab.Problems.DataAnalysis.Evaluators;
|
---|
8 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
9 | using HeuristicLab.Parameters;
|
---|
10 |
|
---|
11 | namespace 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 | }
|
---|