Changeset 16847 for branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/M5Regression.cs
- Timestamp:
- 04/19/19 13:06:11 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2847_M5Regression/HeuristicLab.Algorithms.DataAnalysis/3.4/M5Regression/M5Regression.cs
r15967 r16847 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2019 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; 2 23 using System.Collections.Generic; 3 24 using System.Linq; … … 9 30 using HeuristicLab.Optimization; 10 31 using HeuristicLab.Parameters; 11 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;12 32 using HeuristicLab.PluginInfrastructure; 13 33 using HeuristicLab.Problems.DataAnalysis; 14 34 using HeuristicLab.Random; 35 using HEAL.Attic; 15 36 16 37 namespace HeuristicLab.Algorithms.DataAnalysis { 17 [Storable Class]38 [StorableType("FC8D8E5A-D16D-41BB-91CF-B2B35D17ADD7")] 18 39 [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 95)] 19 40 [Item("M5RegressionTree", "A M5 regression tree / rule set")] … … 28 49 public const string TrainingSetVariableName = "TrainingSet"; 29 50 30 #region Parameter name51 #region Parameter names 31 52 private const string GenerateRulesParameterName = "GenerateRules"; 32 53 private const string HoldoutSizeParameterName = "HoldoutSize"; 33 private const string Split erParameterName = "Splitter";54 private const string SplitterParameterName = "Splitter"; 34 55 private const string MinimalNodeSizeParameterName = "MinimalNodeSize"; 35 56 private const string LeafModelParameterName = "LeafModel"; … … 47 68 get { return (IFixedValueParameter<PercentValue>)Parameters[HoldoutSizeParameterName]; } 48 69 } 49 public IConstrainedValueParameter<ISplitter> ImpurityParameter {50 get { return (IConstrainedValueParameter<ISplitter>)Parameters[Split erParameterName]; }70 public IConstrainedValueParameter<ISplitter> SplitterParameter { 71 get { return (IConstrainedValueParameter<ISplitter>)Parameters[SplitterParameterName]; } 51 72 } 52 73 public IFixedValueParameter<IntValue> MinimalNodeSizeParameter { … … 73 94 public bool GenerateRules { 74 95 get { return GenerateRulesParameter.Value.Value; } 96 set { GenerateRulesParameter.Value.Value = value; } 75 97 } 76 98 public double HoldoutSize { 77 99 get { return HoldoutSizeParameter.Value.Value; } 100 set { HoldoutSizeParameter.Value.Value = value; } 78 101 } 79 102 public ISplitter Splitter { 80 get { return ImpurityParameter.Value; } 103 get { return SplitterParameter.Value; } 104 // no setter because this is a constrained parameter 81 105 } 82 106 public int MinimalNodeSize { 83 107 get { return MinimalNodeSizeParameter.Value.Value; } 108 set { MinimalNodeSizeParameter.Value.Value = value; } 84 109 } 85 110 public ILeafModel LeafModel { … … 91 116 public int Seed { 92 117 get { return SeedParameter.Value.Value; } 118 set { SeedParameter.Value.Value = value; } 93 119 } 94 120 public bool SetSeedRandomly { 95 121 get { return SetSeedRandomlyParameter.Value.Value; } 122 set { SetSeedRandomlyParameter.Value.Value = value; } 96 123 } 97 124 public bool UseHoldout { 98 125 get { return UseHoldoutParameter.Value.Value; } 126 set { UseHoldoutParameter.Value.Value = value; } 99 127 } 100 128 #endregion … … 107 135 #region Constructors and Cloning 108 136 [StorableConstructor] 109 private M5Regression( bool deserializing) : base(deserializing) { }137 private M5Regression(StorableConstructorFlag _) : base(_) { } 110 138 private M5Regression(M5Regression original, Cloner cloner) : base(original, cloner) { 111 139 stateScope = cloner.Clone(stateScope); … … 114 142 var modelSet = new ItemSet<ILeafModel>(ApplicationManager.Manager.GetInstances<ILeafModel>()); 115 143 var pruningSet = new ItemSet<IPruning>(ApplicationManager.Manager.GetInstances<IPruning>()); 116 var impuritySet = new ItemSet<ISplitter>(ApplicationManager.Manager.GetInstances<ISplitter>());117 Parameters.Add(new FixedValueParameter<BoolValue>(GenerateRulesParameterName, "Whether a set of rules or a decision tree shall be created ", new BoolValue(false)));118 Parameters.Add(new FixedValueParameter<PercentValue>(HoldoutSizeParameterName, "How much of the training set shall be reserved for pruning ", new PercentValue(0.2)));119 Parameters.Add(new ConstrainedValueParameter<ISplitter>(Split erParameterName, "The type of split function used to create node splits", impuritySet, impuritySet.OfType<M5Splitter>().First()));120 Parameters.Add(new FixedValueParameter<IntValue>(MinimalNodeSizeParameterName, "The minimal number of samples in a leaf node ", new IntValue(1)));121 Parameters.Add(new ConstrainedValueParameter<ILeafModel>(LeafModelParameterName, "The type of model used for the nodes ", modelSet, modelSet.OfType<LinearLeaf>().First()));122 Parameters.Add(new ConstrainedValueParameter<IPruning>(PruningTypeParameterName, "The type of pruning used ", pruningSet, pruningSet.OfType<ComplexityPruning>().First()));144 var splitterSet = new ItemSet<ISplitter>(ApplicationManager.Manager.GetInstances<ISplitter>()); 145 Parameters.Add(new FixedValueParameter<BoolValue>(GenerateRulesParameterName, "Whether a set of rules or a decision tree shall be created (default=false)", new BoolValue(false))); 146 Parameters.Add(new FixedValueParameter<PercentValue>(HoldoutSizeParameterName, "How much of the training set shall be reserved for pruning (default=20%).", new PercentValue(0.2))); 147 Parameters.Add(new ConstrainedValueParameter<ISplitter>(SplitterParameterName, "The type of split function used to create node splits (default='M5Splitter').", splitterSet, splitterSet.OfType<M5Splitter>().First())); 148 Parameters.Add(new FixedValueParameter<IntValue>(MinimalNodeSizeParameterName, "The minimal number of samples in a leaf node (default=1).", new IntValue(1))); 149 Parameters.Add(new ConstrainedValueParameter<ILeafModel>(LeafModelParameterName, "The type of model used for the nodes (default='LinearLeaf').", modelSet, modelSet.OfType<LinearLeaf>().First())); 150 Parameters.Add(new ConstrainedValueParameter<IPruning>(PruningTypeParameterName, "The type of pruning used (default='ComplexityPruning').", pruningSet, pruningSet.OfType<ComplexityPruning>().First())); 123 151 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 124 152 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 125 Parameters.Add(new FixedValueParameter<BoolValue>(UseHoldoutParameterName, "True if a holdout set should be generated, false if splitting and pruning shall be performed on the same data ", new BoolValue(false)));153 Parameters.Add(new FixedValueParameter<BoolValue>(UseHoldoutParameterName, "True if a holdout set should be generated, false if splitting and pruning shall be performed on the same data (default=false).", new BoolValue(false))); 126 154 Problem = new RegressionProblem(); 127 155 } … … 134 162 base.Initialize(cancellationToken); 135 163 var random = new MersenneTwister(); 136 if (SetSeedRandomly) Seed Parameter.Value.Value = new System.Random().Next();164 if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed(); 137 165 random.Reset(Seed); 138 166 stateScope = InitializeScope(random, Problem.ProblemData, Pruning, MinimalNodeSize, LeafModel, Splitter, GenerateRules, UseHoldout, HoldoutSize);
Note: See TracChangeset
for help on using the changeset viewer.