Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1837_Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/GenerationalSlidingWindowAnalyzer.cs @ 17687

Last change on this file since 17687 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.1 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HEAL.Attic;
29
30namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
31  [Item("Generational Sliding Window GP Analyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")]
32  [StorableType("B72D17A8-B032-4974-9916-D48D128A0A4B")]
33  public class GenerationalSlidingWindowAnalyzer : SlidingWindowAnalyzer, IIterationBasedOperator {
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(StorableConstructorFlag _) : base(_) { }
66    protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { }
67    public override IDeepCloneable Clone(Cloner cloner) {
68      return new GenerationalSlidingWindowAnalyzer(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      IterationsParameter.ActualName = "Generations";
78      MaximumIterationsParameter.Hidden = true;
79    }
80
81    protected override bool CheckForUpdate() {
82      var iteration = IterationsParameter.ActualValue.Value;
83      var start = GenerationsIntervalStart.Value;
84      var step = GenerationsInterval.Value;
85      if (iteration == 0) return false;
86      if (iteration < start) return false;
87      if ((iteration - start) % step == 0) return true;
88
89      return false;
90    }
91
92  }
93}
Note: See TracBrowser for help on using the repository browser.