Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3057_DynamicALPS/TestProblems/oesr-alps-master/HeuristicLab.Algorithms.OESRALPS/DriftDetection/ADWINWrapper.cs @ 17479

Last change on this file since 17479 was 17479, checked in by kyang, 4 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: 1.7 KB
Line 
1using HEAL.Attic;
2using System;
3using System.Collections.Generic;
4using System.Linq;
5using System.Text;
6using System.Threading.Tasks;
7
8namespace HeuristicLab.Algorithms.OESRALPS.DriftDetection
9{
10    [StorableType("719CE0E4-A88F-44A1-A2D0-92F4D8052C04")]
11    class ADWINWrapper
12    {
13        [Storable]
14        private ADWIN adwin;
15
16        [Storable]
17        private Histogram histogram;
18
19        [Storable]
20        public int Count { get; set; }
21        [Storable]
22        public int NumElementsProcessed { get; set; }
23        [Storable]
24        public int MaximumBucketsPerContainer { get; set; }
25
26        public ADWINWrapper() { }
27
28        public ADWINWrapper(double delta, int maximumBucketsPerContainer, int minKeepSize = 100, int minCutSize = 100)
29        {
30            histogram = new Histogram(maximumBucketsPerContainer);
31            adwin = new SequentialADWIN(delta, minKeepSize, minCutSize);
32            NumElementsProcessed = 0;
33            Count = 0;
34            MaximumBucketsPerContainer = maximumBucketsPerContainer;
35        }
36
37        public bool AddElement(double element)
38        {
39            NumElementsProcessed++;
40            histogram.AddElement(element);
41            Count++;
42            return adwin.Execute(ref histogram);
43        }
44
45
46        public void Reset()
47        {
48            Count = 0;
49        }
50
51        public int WindowSize {
52            get { return histogram.NumElements; }
53        }
54
55        public int RemoveOldestInstances()
56        {
57            int startElementsCount = WindowSize;
58            histogram.RemoveBuckets(1);
59            return startElementsCount - WindowSize;
60        }
61    }
62}
Note: See TracBrowser for help on using the repository browser.