[7845] | 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]
|
---|
[9162] | 32 | public class GenerationalSlidingWindowAnalyzer : SlidingWindowAnalyzer, IIterationBasedOperator {
|
---|
[7845] | 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) { }
|
---|
[9162] | 65 | protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
[7845] | 66 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[9162] | 67 | return new GenerationalSlidingWindowAnalyzer(this, cloner);
|
---|
[7845] | 68 | }
|
---|
| 69 |
|
---|
| 70 | public GenerationalSlidingWindowAnalyzer() {
|
---|
| 71 | Parameters.Add(new LookupParameter<IntValue>(IterationsParameterName, ""));
|
---|
| 72 | Parameters.Add(new ValueLookupParameter<IntValue>(MaximumIterationsParameterName, ""));
|
---|
[7850] | 73 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "", new IntValue(5)));
|
---|
| 74 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "", new IntValue(0)));
|
---|
[9162] | 75 |
|
---|
| 76 | IterationsParameter.ActualName = "Generations";
|
---|
| 77 | MaximumIterationsParameter.Hidden = true;
|
---|
[7845] | 78 | }
|
---|
| 79 |
|
---|
| 80 | protected override bool CheckForUpdate() {
|
---|
| 81 | var iteration = IterationsParameter.ActualValue.Value;
|
---|
| 82 | var start = GenerationsIntervalStart.Value;
|
---|
| 83 | var step = GenerationsInterval.Value;
|
---|
[7850] | 84 | if (iteration == 0) return false;
|
---|
[7845] | 85 | if (iteration < start) return false;
|
---|
| 86 | if ((iteration - start) % step == 0) return true;
|
---|
| 87 |
|
---|
| 88 | return false;
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | }
|
---|
| 92 | }
|
---|