Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/SlidingWindowVisualizer.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: 4.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HEAL.Attic;
31
32namespace HeuristicLab.Problems.DataAnalysis.Symbolic.SlidingWindow {
33  [Item("Sliding Window Visualizer", "Visualizes the actual sliding window position.")]
34  [StorableType("27F88470-70F5-47B5-A491-BE6B39B1F78D")]
35  public sealed class SlidingWindowVisualizer : SymbolicDataAnalysisAnalyzer {
36    private const string ProblemDataParameterName = "ProblemData";
37    private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition";
38
39    private const string SlidingWindowResultName = "Sliding Window";
40    private const string SlidingWindowDataResultName = "Sliding Window Data";
41    private const string BestTrainingSolutionResultName = "Best training solution";
42
43    #region parameter properties
44    public IValueLookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
45      get { return (IValueLookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
46    }
47    public ILookupParameter<IntRange> FitnessCalculationPartitionParameter {
48      get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; }
49    }
50    #endregion
51
52    [StorableConstructor]
53    private SlidingWindowVisualizer(StorableConstructorFlag _) : base(_) { }
54    private SlidingWindowVisualizer(SlidingWindowVisualizer original, Cloner cloner) : base(original, cloner) { }
55    public override IDeepCloneable Clone(Cloner cloner) {
56      return new SlidingWindowVisualizer(this, cloner);
57    }
58
59    public SlidingWindowVisualizer()
60      : base() {
61      Parameters.Add(new ValueLookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
62      Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName, ""));
63      ProblemDataParameter.Hidden = true;
64    }
65
66    public override IOperation Apply() {
67      //create and update result
68      var results = ResultCollectionParameter.ActualValue;
69
70      IntRange slidingWindow;
71      if (!results.ContainsKey(SlidingWindowResultName)) {
72        slidingWindow = new IntRange();
73        results.Add(new Result(SlidingWindowResultName, slidingWindow));
74      } else slidingWindow = (IntRange)results[SlidingWindowResultName].Value;
75      slidingWindow.Start = FitnessCalculationPartitionParameter.ActualValue.Start;
76      slidingWindow.End = FitnessCalculationPartitionParameter.ActualValue.End;
77
78      SlidingWindowData slidingWindowData;
79      if (!results.ContainsKey(SlidingWindowDataResultName)) {
80        slidingWindowData = new SlidingWindowData(FitnessCalculationPartitionParameter.ActualValue, ProblemDataParameter.ActualValue);
81        results.Add(new Result(SlidingWindowDataResultName, slidingWindowData));
82      } else slidingWindowData = (SlidingWindowData)results[SlidingWindowDataResultName].Value;
83
84      IEnumerable<double> estimatedValues = Enumerable.Empty<double>();
85      if (results.ContainsKey(BestTrainingSolutionResultName)) {
86        var trainingSolution = results[BestTrainingSolutionResultName].Value;
87        var regressionSolution = trainingSolution as IRegressionSolution;
88        var classificationSolution = trainingSolution as IClassificationSolution;
89
90        if (regressionSolution != null) estimatedValues = regressionSolution.EstimatedTrainingValues;
91        if (classificationSolution != null) estimatedValues = classificationSolution.EstimatedTrainingClassValues;
92      }
93
94      slidingWindowData.SlidingWindowPosition.Start = FitnessCalculationPartitionParameter.ActualValue.Start;
95      slidingWindowData.SlidingWindowPosition.End = FitnessCalculationPartitionParameter.ActualValue.End;
96      slidingWindowData.EstimatedValues = estimatedValues;
97      return base.Apply();
98    }
99  }
100}
Note: See TracBrowser for help on using the repository browser.