Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2994-AutoDiffForIntervals/HeuristicLab.Algorithms.DataAnalysis.DecisionTrees/3.4/Splitting/Splitter.cs @ 17120

Last change on this file since 17120 was 17081, checked in by gkronber, 5 years ago

#2847: more changes for renaming the M5 plugin

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2017 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;
23using System.Collections.Generic;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Parameters;
28using HEAL.Attic;
29
30namespace HeuristicLab.Algorithms.DataAnalysis {
31  [StorableType("502B1429-7A28-45C1-A60A-93E72CB3AF4A")]
32  [Item("Splitter", "A split selector that uses the ratio between Variances^(1/Order) to determine good splits.")]
33  public sealed class Splitter : SplitterBase {
34    public const string OrderParameterName = "Order";
35    public IFixedValueParameter<DoubleValue> OrderParameter {
36      get { return (IFixedValueParameter<DoubleValue>)Parameters[OrderParameterName]; }
37    }
38    public double Order {
39      get { return OrderParameter.Value.Value; }
40      set { OrderParameter.Value.Value = value; }
41    }
42
43    #region Constructors & Cloning
44    [StorableConstructor]
45    private Splitter(StorableConstructorFlag _) { }
46    private Splitter(Splitter original, Cloner cloner) : base(original, cloner) { }
47    public Splitter() {
48      Parameters.Add(new FixedValueParameter<DoubleValue>(OrderParameterName, "The exponent in the split calculation sum (x_i - x_avg)^Order (default=5).", new DoubleValue(5)));
49    }
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new Splitter(this, cloner);
52    }
53    #endregion
54
55    protected override void AttributeSplit(IReadOnlyList<double> attValues, IReadOnlyList<double> targetValues, int minLeafSize, out int position, out double maxImpurity, out double splitValue) {
56      position = 0;
57      maxImpurity = double.NegativeInfinity;
58      splitValue = 0.0;
59      var length = targetValues.Count;
60
61      // weka code
62      var low = 0;
63      var high = length - 1;
64      if (high - low + 1 < 4) return;
65      var len = Math.Max(minLeafSize - 1, high - low + 1 < 5 ? 1 : (high - low + 1) / 5);
66      position = low;
67      var part = low + len - 1;
68      var imp = new OrderImpurityCalculator(part + 1, targetValues, Order);
69
70      for (var i = low + len; i < high - len; i++) {
71        imp.Increment(targetValues[i], OrderImpurityCalculator.IncrementType.Left);
72        if (attValues[i].IsAlmost(attValues[i + 1])) continue; //splits can not be made between to equal points
73        if (imp.Impurity < maxImpurity) continue;
74        maxImpurity = imp.Impurity;
75        splitValue = (attValues[i] + attValues[i + 1]) / 2;
76        position = i;
77      }
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.