1 | using HEAL.Attic;
|
---|
2 | using HeuristicLab.Common;
|
---|
3 | using HeuristicLab.Core;
|
---|
4 | using HeuristicLab.Data;
|
---|
5 | using HeuristicLab.Optimization;
|
---|
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("OverfittingSlidingWindowAnalyzer", "An operator that analyzes the correlation of training and validation fitness of symbolic regression models and moves a sliding window if the thresholds are exceeded.")]
|
---|
18 | [StorableType("75E112AA-91B2-4BA4-8544-CF2025A65822")]
|
---|
19 | public abstract class OverfittingSlidingWindowAnalyzer<T, U> : SlidingWindowAnalyzer<T, U>
|
---|
20 | where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
|
---|
21 | where U : class, IDataAnalysisProblemData
|
---|
22 | {
|
---|
23 | private const string OverfittingParameterName = "IsOverfitting";
|
---|
24 |
|
---|
25 | #region parameter properties
|
---|
26 | public IScopeTreeLookupParameter<BoolValue> OverfittingParameter {
|
---|
27 | get { return (IScopeTreeLookupParameter<BoolValue>)Parameters[OverfittingParameterName]; }
|
---|
28 | }
|
---|
29 | #endregion
|
---|
30 |
|
---|
31 | #region properties
|
---|
32 | public ItemArray<BoolValue> Overfitting {
|
---|
33 | get { return OverfittingParameter.ActualValue; }
|
---|
34 | }
|
---|
35 | #endregion
|
---|
36 |
|
---|
37 | [StorableConstructor]
|
---|
38 | protected OverfittingSlidingWindowAnalyzer(StorableConstructorFlag _) : base(_) { }
|
---|
39 | protected OverfittingSlidingWindowAnalyzer(OverfittingSlidingWindowAnalyzer<T, U> original, Cloner cloner) : base(original, cloner) { }
|
---|
40 | public OverfittingSlidingWindowAnalyzer()
|
---|
41 | {
|
---|
42 | Parameters.Add(new ScopeTreeLookupParameter<BoolValue>(OverfittingParameterName, "Boolean indicator for overfitting."));
|
---|
43 | }
|
---|
44 |
|
---|
45 | public override IOperation Apply()
|
---|
46 | {
|
---|
47 | if (TrainingPartitionParameter.ActualValue == null
|
---|
48 | || IsSystemOverfitting())
|
---|
49 | return OnMoveWindow();
|
---|
50 |
|
---|
51 | return base.Apply();
|
---|
52 | }
|
---|
53 |
|
---|
54 | private bool IsSystemOverfitting()
|
---|
55 | {
|
---|
56 | // TODO think of a suitable strategy
|
---|
57 | return Overfitting.Any()
|
---|
58 | && IsMajorityOverfitting();
|
---|
59 | //&& IsOverfittingMoreThanTwo();
|
---|
60 | }
|
---|
61 |
|
---|
62 | private bool IsMajorityOverfitting()
|
---|
63 | {
|
---|
64 | var skipFirstLayerNumb = 2;
|
---|
65 | return Overfitting
|
---|
66 | .Skip(skipFirstLayerNumb)
|
---|
67 | .Where(overfit => overfit.Value)
|
---|
68 | .Count() > Math.Ceiling((Overfitting.Count() - skipFirstLayerNumb) / 2.0);
|
---|
69 | }
|
---|
70 |
|
---|
71 | private bool IsOverfittingMoreThanTwo()
|
---|
72 | {
|
---|
73 | var skipFirstLayerNumb = 2;
|
---|
74 | return Overfitting
|
---|
75 | .Skip(skipFirstLayerNumb)
|
---|
76 | .Where(overfit => overfit.Value)
|
---|
77 | .Count() > 2;
|
---|
78 | }
|
---|
79 | }
|
---|
80 | }
|
---|