Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/19 13:06:11 (5 years ago)
Author:
gkronber
Message:

#2847: made some minor changes while reviewing

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;
    223using System.Collections.Generic;
    324using System.Linq;
     
    930using HeuristicLab.Optimization;
    1031using HeuristicLab.Parameters;
    11 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    1232using HeuristicLab.PluginInfrastructure;
    1333using HeuristicLab.Problems.DataAnalysis;
    1434using HeuristicLab.Random;
     35using HEAL.Attic;
    1536
    1637namespace HeuristicLab.Algorithms.DataAnalysis {
    17   [StorableClass]
     38  [StorableType("FC8D8E5A-D16D-41BB-91CF-B2B35D17ADD7")]
    1839  [Creatable(CreatableAttribute.Categories.DataAnalysisRegression, Priority = 95)]
    1940  [Item("M5RegressionTree", "A M5 regression tree / rule set")]
     
    2849    public const string TrainingSetVariableName = "TrainingSet";
    2950
    30     #region Parametername
     51    #region Parameter names
    3152    private const string GenerateRulesParameterName = "GenerateRules";
    3253    private const string HoldoutSizeParameterName = "HoldoutSize";
    33     private const string SpliterParameterName = "Splitter";
     54    private const string SplitterParameterName = "Splitter";
    3455    private const string MinimalNodeSizeParameterName = "MinimalNodeSize";
    3556    private const string LeafModelParameterName = "LeafModel";
     
    4768      get { return (IFixedValueParameter<PercentValue>)Parameters[HoldoutSizeParameterName]; }
    4869    }
    49     public IConstrainedValueParameter<ISplitter> ImpurityParameter {
    50       get { return (IConstrainedValueParameter<ISplitter>)Parameters[SpliterParameterName]; }
     70    public IConstrainedValueParameter<ISplitter> SplitterParameter {
     71      get { return (IConstrainedValueParameter<ISplitter>)Parameters[SplitterParameterName]; }
    5172    }
    5273    public IFixedValueParameter<IntValue> MinimalNodeSizeParameter {
     
    7394    public bool GenerateRules {
    7495      get { return GenerateRulesParameter.Value.Value; }
     96      set { GenerateRulesParameter.Value.Value = value; }
    7597    }
    7698    public double HoldoutSize {
    7799      get { return HoldoutSizeParameter.Value.Value; }
     100      set { HoldoutSizeParameter.Value.Value = value; }
    78101    }
    79102    public ISplitter Splitter {
    80       get { return ImpurityParameter.Value; }
     103      get { return SplitterParameter.Value; }
     104      // no setter because this is a constrained parameter
    81105    }
    82106    public int MinimalNodeSize {
    83107      get { return MinimalNodeSizeParameter.Value.Value; }
     108      set { MinimalNodeSizeParameter.Value.Value = value; }
    84109    }
    85110    public ILeafModel LeafModel {
     
    91116    public int Seed {
    92117      get { return SeedParameter.Value.Value; }
     118      set { SeedParameter.Value.Value = value; }
    93119    }
    94120    public bool SetSeedRandomly {
    95121      get { return SetSeedRandomlyParameter.Value.Value; }
     122      set { SetSeedRandomlyParameter.Value.Value = value; }
    96123    }
    97124    public bool UseHoldout {
    98125      get { return UseHoldoutParameter.Value.Value; }
     126      set { UseHoldoutParameter.Value.Value = value; }
    99127    }
    100128    #endregion
     
    107135    #region Constructors and Cloning
    108136    [StorableConstructor]
    109     private M5Regression(bool deserializing) : base(deserializing) { }
     137    private M5Regression(StorableConstructorFlag _) : base(_) { }
    110138    private M5Regression(M5Regression original, Cloner cloner) : base(original, cloner) {
    111139      stateScope = cloner.Clone(stateScope);
     
    114142      var modelSet = new ItemSet<ILeafModel>(ApplicationManager.Manager.GetInstances<ILeafModel>());
    115143      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>(SpliterParameterName, "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()));
    123151      Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
    124152      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)));
    126154      Problem = new RegressionProblem();
    127155    }
     
    134162      base.Initialize(cancellationToken);
    135163      var random = new MersenneTwister();
    136       if (SetSeedRandomly) SeedParameter.Value.Value = new System.Random().Next();
     164      if (SetSeedRandomly) Seed = RandomSeedGenerator.GetSeed();
    137165      random.Reset(Seed);
    138166      stateScope = InitializeScope(random, Problem.ProblemData, Pruning, MinimalNodeSize, LeafModel, Splitter, GenerateRules, UseHoldout, HoldoutSize);
Note: See TracChangeset for help on using the changeset viewer.