Rev | Line | |
---|
[4113] | 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 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 | }
|
---|
[4400] | 42 | n++;
|
---|
[4113] | 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.