#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HEAL.Attic; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [Item("Generational Sliding Window GP Analyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")] [StorableType("B72D17A8-B032-4974-9916-D48D128A0A4B")] public class GenerationalSlidingWindowAnalyzer : SlidingWindowAnalyzer, IIterationBasedOperator { private const string GenerationsIntervalParameterName = "Generation Interval"; private const string GenerationsIntervalStartParameterName = "Generation Interval Start"; private const string IterationsParameterName = "Iterations"; private const string MaximumIterationsParameterName = "Maximum Iterations"; #region parameter properties public ILookupParameter IterationsParameter { get { return (ILookupParameter)Parameters[IterationsParameterName]; } } public IValueLookupParameter MaximumIterationsParameter { get { return (IValueLookupParameter)Parameters[MaximumIterationsParameterName]; } } public IFixedValueParameter GenerationsIntervalParameter { get { return (IFixedValueParameter)Parameters[GenerationsIntervalParameterName]; } } public IFixedValueParameter GenerationsIntervalStartParameter { get { return (IFixedValueParameter)Parameters[GenerationsIntervalStartParameterName]; } } #endregion #region properties public IntValue GenerationsInterval { get { return GenerationsIntervalParameter.Value; } } public IntValue GenerationsIntervalStart { get { return GenerationsIntervalStartParameter.Value; } } #endregion [StorableConstructor] protected GenerationalSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { } protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new GenerationalSlidingWindowAnalyzer(this, cloner); } public GenerationalSlidingWindowAnalyzer() { Parameters.Add(new LookupParameter(IterationsParameterName, "")); Parameters.Add(new ValueLookupParameter(MaximumIterationsParameterName, "")); Parameters.Add(new FixedValueParameter(GenerationsIntervalParameterName, "", new IntValue(5))); Parameters.Add(new FixedValueParameter(GenerationsIntervalStartParameterName, "", new IntValue(0))); IterationsParameter.ActualName = "Generations"; MaximumIterationsParameter.Hidden = true; } protected override bool CheckForUpdate() { var iteration = IterationsParameter.ActualValue.Value; var start = GenerationsIntervalStart.Value; var step = GenerationsInterval.Value; if (iteration == 0) return false; if (iteration < start) return false; if ((iteration - start) % step == 0) return true; return false; } } }