Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/TestProblems/oesr-alps-master/HeuristicLab.Algorithms.OESRALPS/Analyzers/OverfittingSlidingWindowAnalyzer.cs @ 18242

Last change on this file since 18242 was 17479, checked in by kyang, 5 years ago

#3057

  1. upload the latest version of ALPS with SMS-EMOA
  2. upload the related dynamic test problems (dynamic, single-objective symbolic regression), written by David Daninel.
File size: 3.0 KB
Line 
1using HEAL.Attic;
2using HeuristicLab.Common;
3using HeuristicLab.Core;
4using HeuristicLab.Data;
5using HeuristicLab.Optimization;
6using HeuristicLab.Parameters;
7using HeuristicLab.Problems.DataAnalysis;
8using HeuristicLab.Problems.DataAnalysis.Symbolic;
9using System;
10using System.Collections.Generic;
11using System.Linq;
12using System.Text;
13using System.Threading.Tasks;
14
15namespace 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}
Note: See TracBrowser for help on using the repository browser.