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