Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Optimization.Operators.LCS/3.3/Discretizer/UniformWidthDiscretizer.cs @ 17578

Last change on this file since 17578 was 9392, checked in by sforsten, 12 years ago

#1980:

  • several small bug fixes
  • added windowing technique ILAS to GAssist
  • GAssist and XCS work now with real-valued features
  • severely improved the performance of XCS
File size: 2.7 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27
28namespace HeuristicLab.Optimization.Operators.LCS {
29  [StorableClass]
30  [Item("UniformWidthDiscretizer", "")]
31  public class UniformWidthDiscretizer : Item, IDiscretizer {
32
33    [Storable]
34    private int bins;
35
36    [Storable]
37    private IDictionary<string, IList<double>> variableMicroItervals;
38
39    [StorableConstructor]
40    protected UniformWidthDiscretizer(bool deserializing) : base(deserializing) { }
41    protected UniformWidthDiscretizer(UniformWidthDiscretizer original, Cloner cloner)
42      : base(original, cloner) {
43      this.bins = original.bins;
44      this.variableMicroItervals = new Dictionary<string, IList<double>>(original.variableMicroItervals);
45    }
46    public UniformWidthDiscretizer()
47      : this(5) {
48    }
49    public UniformWidthDiscretizer(int bins)
50      : base() {
51      variableMicroItervals = new Dictionary<string, IList<double>>();
52      this.bins = bins;
53    }
54    public override IDeepCloneable Clone(Cloner cloner) {
55      return new UniformWidthDiscretizer(this, cloner);
56    }
57
58    public int NumberOfMicroIntervals(string attribute) {
59      return bins;
60    }
61
62    public IEnumerable<double> DiscretizeValues(string attribute, IEnumerable<double> values) {
63      double min = values.Min();
64      double max = values.Max();
65
66      double intervalWidth = (max - min) / bins;
67      List<double> cutPoints = new List<double>(bins - 1);
68      double val = min;
69      for (int i = 0; i < bins - 1; i++) {
70        val += intervalWidth;
71        cutPoints.Add(val);
72      }
73
74      variableMicroItervals[attribute] = cutPoints;
75
76      return cutPoints;
77    }
78
79    public IEnumerable<double> GetCutPoints(string attribute) {
80      return variableMicroItervals[attribute];
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.