[15830] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Data;
|
---|
| 26 | using HeuristicLab.Parameters;
|
---|
[16847] | 27 | using HEAL.Attic;
|
---|
[15830] | 28 |
|
---|
| 29 | namespace HeuristicLab.Algorithms.DataAnalysis {
|
---|
[16847] | 30 | [StorableType("EC3A5009-EE84-4E1A-A537-20F6F1224842")]
|
---|
[15830] | 31 | [Item("CorrelationSplitter", "An experimental split selector that uses correlation coefficients")]
|
---|
| 32 | public class CorrelationSplitter : SplitterBase {
|
---|
| 33 | public const string OrderParameterName = "Order";
|
---|
| 34 | public IFixedValueParameter<DoubleValue> OrderParameter {
|
---|
| 35 | get { return (IFixedValueParameter<DoubleValue>)Parameters[OrderParameterName]; }
|
---|
| 36 | }
|
---|
| 37 | public double Order {
|
---|
| 38 | get { return OrderParameter.Value.Value; }
|
---|
[16847] | 39 | set { OrderParameter.Value.Value = value; }
|
---|
[15830] | 40 | }
|
---|
| 41 |
|
---|
| 42 | #region Constructors & Cloning
|
---|
| 43 | [StorableConstructor]
|
---|
[16847] | 44 | private CorrelationSplitter(StorableConstructorFlag _) { }
|
---|
[15830] | 45 | private CorrelationSplitter(CorrelationSplitter original, Cloner cloner) : base(original, cloner) { }
|
---|
| 46 | public CorrelationSplitter() {
|
---|
[16847] | 47 | Parameters.Add(new FixedValueParameter<DoubleValue>(OrderParameterName, "The exponent in the split calculation ssrLeft^(1/Order)+ssrRight^(1/Order) (default=1.0).", new DoubleValue(1)));
|
---|
[15830] | 48 | }
|
---|
| 49 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 50 | return new CorrelationSplitter(this, cloner);
|
---|
| 51 | }
|
---|
| 52 | #endregion
|
---|
| 53 |
|
---|
| 54 | #region ISplitType
|
---|
| 55 | protected override void AttributeSplit(IReadOnlyList<double> attValues, IReadOnlyList<double> targetValues, int minLeafSize, out int leftSize, out double maxImpurity, out double splitValue) {
|
---|
| 56 | leftSize = -1;
|
---|
| 57 | splitValue = double.MinValue;
|
---|
| 58 | maxImpurity = double.NegativeInfinity;
|
---|
| 59 | var splitValues = new List<double>();
|
---|
| 60 | var splitSizes = new List<int>();
|
---|
| 61 | var length = attValues.Count;
|
---|
| 62 |
|
---|
| 63 | var start = minLeafSize;
|
---|
| 64 | while (start < length && attValues[start - 1].IsAlmost(attValues[start]))
|
---|
| 65 | start++;
|
---|
| 66 | if (start >= length) return;
|
---|
| 67 |
|
---|
[16847] | 68 | var imp = new CorreleationImpurityCalculator(minLeafSize, attValues, targetValues, Order);
|
---|
[15830] | 69 | maxImpurity = imp.Impurity;
|
---|
| 70 | splitValues.Add(imp.SplitValue);
|
---|
| 71 | splitSizes.Add(imp.LeftSize);
|
---|
| 72 |
|
---|
| 73 | while (imp.LeftSize < length - minLeafSize) {
|
---|
| 74 | imp.Increment();
|
---|
| 75 | if (!imp.ValidPosition) continue; //splits can not be made between to equal points
|
---|
| 76 |
|
---|
| 77 | if (imp.Impurity.IsAlmost(maxImpurity)) {
|
---|
| 78 | splitValues.Add(imp.SplitValue);
|
---|
| 79 | splitSizes.Add(imp.LeftSize);
|
---|
| 80 | continue;
|
---|
| 81 | }
|
---|
| 82 |
|
---|
| 83 | if (imp.Impurity < maxImpurity) continue;
|
---|
| 84 | splitValues.Clear();
|
---|
| 85 | splitSizes.Clear();
|
---|
| 86 | maxImpurity = imp.Impurity;
|
---|
| 87 | splitValues.Add(imp.SplitValue);
|
---|
| 88 | splitSizes.Add(imp.LeftSize);
|
---|
| 89 | }
|
---|
| 90 |
|
---|
| 91 | var j = splitSizes.Count / 2;
|
---|
| 92 | if (splitSizes.Count == 0) return;
|
---|
| 93 | splitValue = splitValues[j];
|
---|
| 94 | leftSize = splitSizes[j];
|
---|
| 95 | }
|
---|
| 96 | #endregion
|
---|
| 97 | }
|
---|
| 98 | } |
---|