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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Parameters;
|
---|
27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
30 | [Item("Generational Sliding Window GP Analyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")]
|
---|
31 | [StorableClass]
|
---|
32 | public class GenerationalSlidingWindowAnalyzer<T> : SlidingWindowAnalyzer<T>, IIterationBasedOperator
|
---|
33 | where T : class, IDataAnalysisProblemData {
|
---|
34 | private const string GenerationsIntervalParameterName = "Generation Interval";
|
---|
35 | private const string GenerationsIntervalStartParameterName = "Generation Interval Start";
|
---|
36 | private const string IterationsParameterName = "Iterations";
|
---|
37 | private const string MaximumIterationsParameterName = "Maximum Iterations";
|
---|
38 |
|
---|
39 | #region parameter properties
|
---|
40 | public ILookupParameter<IntValue> IterationsParameter {
|
---|
41 | get { return (ILookupParameter<IntValue>)Parameters[IterationsParameterName]; }
|
---|
42 | }
|
---|
43 | public IValueLookupParameter<IntValue> MaximumIterationsParameter {
|
---|
44 | get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; }
|
---|
45 | }
|
---|
46 | public IFixedValueParameter<IntValue> GenerationsIntervalParameter {
|
---|
47 | get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalParameterName]; }
|
---|
48 | }
|
---|
49 | public IFixedValueParameter<IntValue> GenerationsIntervalStartParameter {
|
---|
50 | get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalStartParameterName]; }
|
---|
51 | }
|
---|
52 | #endregion
|
---|
53 |
|
---|
54 | #region properties
|
---|
55 | public IntValue GenerationsInterval {
|
---|
56 | get { return GenerationsIntervalParameter.Value; }
|
---|
57 | }
|
---|
58 | public IntValue GenerationsIntervalStart {
|
---|
59 | get { return GenerationsIntervalStartParameter.Value; }
|
---|
60 | }
|
---|
61 | #endregion
|
---|
62 |
|
---|
63 |
|
---|
64 | [StorableConstructor]
|
---|
65 | protected GenerationalSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
66 | protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer<T> original, Cloner cloner) : base(original, cloner) { }
|
---|
67 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
68 | return new GenerationalSlidingWindowAnalyzer<T>(this, cloner);
|
---|
69 | }
|
---|
70 |
|
---|
71 | public GenerationalSlidingWindowAnalyzer() {
|
---|
72 | Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, ""));
|
---|
73 | Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, ""));
|
---|
74 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "", new IntValue(5)));
|
---|
75 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "", new IntValue(0)));
|
---|
76 |
|
---|
77 | GenerationsIntervalStartParameter.Hidden = true;
|
---|
78 | }
|
---|
79 |
|
---|
80 | protected override bool CheckForUpdate() {
|
---|
81 | var iteration = IterationsParameter.ActualValue.Value;
|
---|
82 | var start = GenerationsIntervalStart.Value;
|
---|
83 | var step = GenerationsInterval.Value;
|
---|
84 | if (iteration == 0) return false;
|
---|
85 | if (iteration < start) return false;
|
---|
86 | if ((iteration - start) % step == 0) return true;
|
---|
87 |
|
---|
88 | return false;
|
---|
89 | }
|
---|
90 |
|
---|
91 | }
|
---|
92 | }
|
---|