Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowData.cs @ 17717

Last change on this file since 17717 was 17687, checked in by fbaching, 4 years ago

#1837: merged changes from trunk

  • apply changes from Attic release to all SlidingWindow specific code files (replace StorableClass with StorableType)
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;
29using HEAL.Attic;
30
31namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
32  [Item("Sliding Window Position", "")]
33  [StorableType("6D2F5417-5E2F-4BC6-AA4D-E4FB5B3D09D1")]
34  public sealed class SlidingWindowData : Item {
35    [Storable]
36    private IntRange slidingWindowPosition;
37    public IntRange SlidingWindowPosition {
38      get { return slidingWindowPosition; }
39    }
40
41    public IEnumerable<double> TargetValues {
42      get {
43        return problemData.Dataset.GetDoubleValues(GetTargetVariableName(problemData), problemData.TrainingIndices);
44      }
45    }
46
47    [Storable]
48    private IEnumerable<double> estimatedValues;
49    public IEnumerable<double> EstimatedValues {
50      get { return estimatedValues; }
51      set {
52        if (value == null) throw new ArgumentNullException();
53        estimatedValues = value.ToArray();
54        OnEstimatedValuesChanged();
55      }
56    }
57
58    [Storable]
59    private readonly IDataAnalysisProblemData problemData;
60
61    public IDataAnalysisProblemData ProblemData {
62      get { return problemData; }
63    }
64
65    public int TrainingPartitionStart {
66      get { return problemData.TrainingPartition.Start; }
67    }
68
69    public int TrainingPartitionEnd {
70      get { return problemData.TrainingPartition.End; }
71    }
72
73    [StorableConstructor]
74    private SlidingWindowData(StorableConstructorFlag _) : base(_) { }
75    private SlidingWindowData(SlidingWindowData original, Cloner cloner)
76      : base(original, cloner) {
77      slidingWindowPosition = cloner.Clone(original.slidingWindowPosition);
78      problemData = cloner.Clone(original.ProblemData);
79    }
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new SlidingWindowData(this, cloner);
82    }
83
84    public SlidingWindowData(IntRange slidingWindowPosition, IDataAnalysisProblemData problemData)
85      : base() {
86      this.slidingWindowPosition = slidingWindowPosition;
87      this.problemData = (IDataAnalysisProblemData)problemData.Clone();
88    }
89
90    public event EventHandler EstimatedValuesChanged;
91    private void OnEstimatedValuesChanged() {
92      var handler = EstimatedValuesChanged;
93      if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty);
94    }
95
96    private string GetTargetVariableName(IDataAnalysisProblemData problemData) {
97      var classificationProblemData = problemData as IClassificationProblemData;
98      var regressionProblemData = problemData as IRegressionProblemData;
99      string targetVariable;
100      if (classificationProblemData != null) targetVariable = classificationProblemData.TargetVariable;
101      else if (regressionProblemData != null) targetVariable = regressionProblemData.TargetVariable;
102      else throw new NotSupportedException();
103      return targetVariable;
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.