#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HEAL.Attic; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [Item("Sliding Window Position", "")] [StorableType("6D2F5417-5E2F-4BC6-AA4D-E4FB5B3D09D1")] public sealed class SlidingWindowData : Item { [Storable] private IntRange slidingWindowPosition; public IntRange SlidingWindowPosition { get { return slidingWindowPosition; } } public IEnumerable TargetValues { get { return problemData.Dataset.GetDoubleValues(GetTargetVariableName(problemData), problemData.TrainingIndices); } } [Storable] private IEnumerable estimatedValues; public IEnumerable EstimatedValues { get { return estimatedValues; } set { if (value == null) throw new ArgumentNullException(); estimatedValues = value.ToArray(); OnEstimatedValuesChanged(); } } [Storable] private readonly IDataAnalysisProblemData problemData; public IDataAnalysisProblemData ProblemData { get { return problemData; } } public int TrainingPartitionStart { get { return problemData.TrainingPartition.Start; } } public int TrainingPartitionEnd { get { return problemData.TrainingPartition.End; } } [StorableConstructor] private SlidingWindowData(StorableConstructorFlag _) : base(_) { } private SlidingWindowData(SlidingWindowData original, Cloner cloner) : base(original, cloner) { slidingWindowPosition = cloner.Clone(original.slidingWindowPosition); problemData = cloner.Clone(original.ProblemData); } public override IDeepCloneable Clone(Cloner cloner) { return new SlidingWindowData(this, cloner); } public SlidingWindowData(IntRange slidingWindowPosition, IDataAnalysisProblemData problemData) : base() { this.slidingWindowPosition = slidingWindowPosition; this.problemData = (IDataAnalysisProblemData)problemData.Clone(); } public event EventHandler EstimatedValuesChanged; private void OnEstimatedValuesChanged() { var handler = EstimatedValuesChanged; if (handler != null) EstimatedValuesChanged(this, EventArgs.Empty); } private string GetTargetVariableName(IDataAnalysisProblemData problemData) { var classificationProblemData = problemData as IClassificationProblemData; var regressionProblemData = problemData as IRegressionProblemData; string targetVariable; if (classificationProblemData != null) targetVariable = classificationProblemData.TargetVariable; else if (regressionProblemData != null) targetVariable = regressionProblemData.TargetVariable; else throw new NotSupportedException(); return targetVariable; } } }