1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Algorithms.OESRALPS.SlidingWindow.Operator;
|
---|
3 | using HeuristicLab.Common;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 | using HeuristicLab.Parameters;
|
---|
7 | using HeuristicLab.Problems.DataAnalysis;
|
---|
8 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
9 | using System;
|
---|
10 | using System.Collections.Generic;
|
---|
11 | using System.Linq;
|
---|
12 | using System.Text;
|
---|
13 | using System.Threading.Tasks;
|
---|
14 |
|
---|
15 | namespace HeuristicLab.Algorithms.OESRALPS.Analyzers
|
---|
16 | {
|
---|
17 | [Item("GenerationalSlidingWindowAnalyzer", "Analyzer which moves a sliding window every n-th generation over the training partition.")]
|
---|
18 | [StorableType("3E8EA052-3A86-4610-BA18-E3FE78DAD22F")]
|
---|
19 | public abstract class GenerationalSlidingWindowAnalyzer<T, U> : SlidingWindowAnalyzer<T, U>, IGenerationalSlidingWindowOperator
|
---|
20 | where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
|
---|
21 | where U : class, IDataAnalysisProblemData
|
---|
22 | {
|
---|
23 | private const string GenerationsIntervalParameterName = "GenerationInterval";
|
---|
24 | private const string GenerationsIntervalStartParameterName = "GenerationIntervalStart";
|
---|
25 |
|
---|
26 | #region parameter properties
|
---|
27 | public IFixedValueParameter<IntValue> GenerationsIntervalParameter {
|
---|
28 | get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalParameterName]; }
|
---|
29 | }
|
---|
30 | public IFixedValueParameter<IntValue> GenerationsIntervalStartParameter {
|
---|
31 | get { return (IFixedValueParameter<IntValue>)Parameters[GenerationsIntervalStartParameterName]; }
|
---|
32 | }
|
---|
33 | #endregion
|
---|
34 |
|
---|
35 | #region properties
|
---|
36 | public IntValue GenerationsInterval { get { return GenerationsIntervalParameter.Value; } }
|
---|
37 | public IntValue GenerationsIntervalStart { get { return GenerationsIntervalStartParameter.Value; } }
|
---|
38 | #endregion
|
---|
39 |
|
---|
40 | [StorableConstructor]
|
---|
41 | protected GenerationalSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
42 | protected GenerationalSlidingWindowAnalyzer(GenerationalSlidingWindowAnalyzer<T, U> original, Cloner cloner) : base(original, cloner) { }
|
---|
43 | public GenerationalSlidingWindowAnalyzer()
|
---|
44 | : base()
|
---|
45 | {
|
---|
46 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalParameterName, "The number of generations to pass for a window move.", new IntValue(1)));
|
---|
47 | Parameters.Add(new FixedValueParameter<IntValue>(GenerationsIntervalStartParameterName, "The number of generations to pass before the first window move.", new IntValue(0)));
|
---|
48 |
|
---|
49 | MinimumIterationsUntilNextMoveParameter.Value = GenerationsIntervalParameter.Value;
|
---|
50 | MinimumIterationsUntilNextMoveParameter.Hidden = true;
|
---|
51 | }
|
---|
52 |
|
---|
53 | public override IOperation Apply()
|
---|
54 | {
|
---|
55 | if (TrainingPartitionParameter.ActualValue == null
|
---|
56 | || IsIterationIntervalPassed())
|
---|
57 | return OnMoveWindow();
|
---|
58 |
|
---|
59 | return base.Apply();
|
---|
60 | }
|
---|
61 |
|
---|
62 | protected IOperation GetBaseOperation()
|
---|
63 | {
|
---|
64 | return base.Apply();
|
---|
65 | }
|
---|
66 |
|
---|
67 | protected bool IsIterationIntervalPassed() {
|
---|
68 | return (IterationsParameter.ActualValue.Value - GenerationsIntervalStart.Value) % GenerationsInterval.Value == 0;
|
---|
69 | }
|
---|
70 | }
|
---|
71 | }
|
---|