Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowData.cs @ 9870

Last change on this file since 9870 was 9870, checked in by bburlacu, 11 years ago

#1837: Merged trunk changes and fixed sliding window visualization.

File size: 3.8 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
31  [StorableClass]
32  [Item("Sliding Window Position", "")]
33  public sealed class SlidingWindowData : Item {
34    [Storable]
35    private IntRange slidingWindowPosition;
36    public IntRange SlidingWindowPosition {
37      get { return slidingWindowPosition; }
38    }
39
40    public IEnumerable<double> TargetValues {
41      get {
42        return problemData.Dataset.GetDoubleValues(GetTargetVariableName(problemData), problemData.TrainingIndices);
43      }
44    }
45
46    [Storable]
47    private IEnumerable<double> estimatedValues;
48    public IEnumerable<double> EstimatedValues {
49      get { return estimatedValues; }
50      set {
51        if (value == null) throw new ArgumentNullException();
52        estimatedValues = value.ToArray();
53        OnEstimatedValuesChanged();
54      }
55    }
56
57    [Storable]
58    private readonly IDataAnalysisProblemData problemData;
59
60    public IDataAnalysisProblemData ProblemData {
61      get { return problemData; }
62    }
63
64    public int TrainingPartitionStart {
65      get { return problemData.TrainingPartition.Start; }
66    }
67
68    public int TrainingPartitionEnd {
69      get { return problemData.TrainingPartition.End; }
70    }
71
72    [StorableConstructor]
73    private SlidingWindowData(bool deserializing) : base(deserializing) { }
74    private SlidingWindowData(SlidingWindowData original, Cloner cloner)
75      : base(original, cloner) {
76      slidingWindowPosition = cloner.Clone(original.slidingWindowPosition);
77      problemData = cloner.Clone(original.ProblemData);
78    }
79    public override IDeepCloneable Clone(Cloner cloner) {
80      return new SlidingWindowData(this, cloner);
81    }
82
83    public SlidingWindowData(IntRange slidingWindowPosition, IDataAnalysisProblemData problemData)
84      : base() {
85      this.slidingWindowPosition = slidingWindowPosition;
86      this.problemData = (IDataAnalysisProblemData)problemData.Clone();
87    }
88
89    public event EventHandler EstimatedValuesChanged;
90    private void OnEstimatedValuesChanged() {
91      var handler = EstimatedValuesChanged;
92      if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty);
93    }
94
95    private string GetTargetVariableName(IDataAnalysisProblemData problemData) {
96      var classificationProblemData = problemData as IClassificationProblemData;
97      var regressionProblemData = problemData as IRegressionProblemData;
98      string targetVariable;
99      if (classificationProblemData != null) targetVariable = classificationProblemData.TargetVariable;
100      else if (regressionProblemData != null) targetVariable = regressionProblemData.TargetVariable;
101      else throw new NotSupportedException();
102      return targetVariable;
103    }
104  }
105}
Note: See TracBrowser for help on using the repository browser.