[7845] | 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 |
|
---|
[9162] | 22 | using System;
|
---|
[7845] | 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
| 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[17687] | 29 | using HEAL.Attic;
|
---|
[7845] | 30 |
|
---|
| 31 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
[9162] | 32 | [Item("Sliding Window Position", "")]
|
---|
[17687] | 33 | [StorableType("6D2F5417-5E2F-4BC6-AA4D-E4FB5B3D09D1")]
|
---|
[9162] | 34 | public sealed class SlidingWindowData : Item {
|
---|
[7845] | 35 | [Storable]
|
---|
| 36 | private IntRange slidingWindowPosition;
|
---|
| 37 | public IntRange SlidingWindowPosition {
|
---|
| 38 | get { return slidingWindowPosition; }
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | public IEnumerable<double> TargetValues {
|
---|
[9870] | 42 | get {
|
---|
| 43 | return problemData.Dataset.GetDoubleValues(GetTargetVariableName(problemData), problemData.TrainingIndices);
|
---|
| 44 | }
|
---|
[7845] | 45 | }
|
---|
| 46 |
|
---|
[9162] | 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 |
|
---|
[9870] | 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 |
|
---|
[9162] | 73 | [StorableConstructor]
|
---|
[17687] | 74 | private SlidingWindowData(StorableConstructorFlag _) : base(_) { }
|
---|
[9162] | 75 | private SlidingWindowData(SlidingWindowData original, Cloner cloner)
|
---|
[7845] | 76 | : base(original, cloner) {
|
---|
| 77 | slidingWindowPosition = cloner.Clone(original.slidingWindowPosition);
|
---|
[9870] | 78 | problemData = cloner.Clone(original.ProblemData);
|
---|
[7845] | 79 | }
|
---|
| 80 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 81 | return new SlidingWindowData(this, cloner);
|
---|
| 82 | }
|
---|
| 83 |
|
---|
[9870] | 84 | public SlidingWindowData(IntRange slidingWindowPosition, IDataAnalysisProblemData problemData)
|
---|
[7845] | 85 | : base() {
|
---|
| 86 | this.slidingWindowPosition = slidingWindowPosition;
|
---|
[9870] | 87 | this.problemData = (IDataAnalysisProblemData)problemData.Clone();
|
---|
[7845] | 88 | }
|
---|
[9162] | 89 |
|
---|
| 90 | public event EventHandler EstimatedValuesChanged;
|
---|
| 91 | private void OnEstimatedValuesChanged() {
|
---|
| 92 | var handler = EstimatedValuesChanged;
|
---|
| 93 | if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty);
|
---|
| 94 | }
|
---|
[9870] | 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 | }
|
---|
[7845] | 105 | }
|
---|
| 106 | }
|
---|