Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Sliding Window GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SlidingWindow/GenerationalSlidingWindowAnalyzer.cs @ 11416

Last change on this file since 11416 was 9162, checked in by mkommend, 12 years ago

#1837: Refactored sliding window analyzers and updated the provided algorithm.

File size: 4.0 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;
28
29namespace 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 : SlidingWindowAnalyzer, IIterationBasedOperator {
33    private const string GenerationsIntervalParameterName = "Generation Interval";
34    private const string GenerationsIntervalStartParameterName = "Generation Interval Start";
35    private const string IterationsParameterName = "Iterations";
36    private const string MaximumIterationsParameterName = "Maximum Iterations";
37
38    #region parameter properties
39    public ILookupParameter<IntValue> IterationsParameter {
40      get { return (ILookupParameter<IntValue>)Parameters[IterationsParameterName]; }
41    }
42    public IValueLookupParameter<IntValue> MaximumIterationsParameter {
43      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumIterationsParameterName]; }
44    }
45    public IFixedValueParameter<IntValue> GenerationsIntervalParameter {
46      get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalParameterName]; }
47    }
48    public IFixedValueParameter<IntValue> GenerationsIntervalStartParameter {
49      get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalStartParameterName]; }
50    }
51    #endregion
52
53    #region properties
54    public IntValue GenerationsInterval {
55      get { return GenerationsIntervalParameter.Value; }
56    }
57    public IntValue GenerationsIntervalStart {
58      get { return GenerationsIntervalStartParameter.Value; }
59    }
60    #endregion
61
62
63    [StorableConstructor]
64    protected GenerationalSlidingWindowAnalyzer(bool deserializing) : base(deserializing) { }
65    protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { }
66    public override IDeepCloneable Clone(Cloner cloner) {
67      return new GenerationalSlidingWindowAnalyzer(this, cloner);
68    }
69
70    public GenerationalSlidingWindowAnalyzer() {
71      Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, ""));
72      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, ""));
73      Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "", new IntValue(5)));
74      Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "", new IntValue(0)));
75
76      IterationsParameter.ActualName = "Generations";
77      MaximumIterationsParameter.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}
Note: See TracBrowser for help on using the repository browser.