Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.DecisionList/3.3/DecisionListCreator.cs @ 15469

Last change on this file since 15469 was 9605, checked in by sforsten, 11 years ago

#1980:

  • set plugin dependencies
  • added smart initialization
  • added hierarchical selection
  • fixed major and minor default rule
  • fixed several smaller bugs
  • some refactoring has been done
File size: 4.5 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;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization.Operators.LCS;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.DecisionList {
32  [Item("DecisionListCreator", "Description missing")]
33  [StorableClass]
34  public abstract class DecisionListCreator : SingleSuccessorOperator, IDecisionListCreator {
35
36    #region Parameter Properties
37    public IValueLookupParameter<IDecisionListClassificationProblemData> ProblemDataParameter {
38      get { return (IValueLookupParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; }
39    }
40    public IValueLookupParameter<IntValue> InitialNumberOfRulesParameter {
41      get { return (IValueLookupParameter<IntValue>)Parameters["InitialNumberOfRules"]; }
42    }
43    public IValueLookupParameter<PercentValue> OneProbabilityParameter {
44      get { return (IValueLookupParameter<PercentValue>)Parameters["OneProbability"]; }
45    }
46    public IValueLookupParameter<ItemCollection<IDiscretizer>> DiscretizersParameter {
47      get { return (IValueLookupParameter<ItemCollection<IDiscretizer>>)Parameters["Discretizers"]; }
48    }
49    public ILookupParameter<DecisionList> DecisionListParameter {
50      get { return (ILookupParameter<DecisionList>)Parameters["DecisionList"]; }
51    }
52    public ILookupParameter<IRandom> RandomParameter {
53      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
54    }
55    public ILookupParameter<IGAssistNiche> GAssistNicheParameter {
56      get { return (ILookupParameter<IGAssistNiche>)Parameters["GAssistNiche"]; }
57    }
58    #endregion
59
60    [StorableConstructor]
61    protected DecisionListCreator(bool deserializing) : base(deserializing) { }
62    protected DecisionListCreator(DecisionListCreator original, Cloner cloner)
63      : base(original, cloner) {
64    }
65    public DecisionListCreator()
66      : base() {
67      Parameters.Add(new ValueLookupParameter<IDecisionListClassificationProblemData>("ProblemData", ""));
68      Parameters.Add(new ValueLookupParameter<IntValue>("InitialNumberOfRules", ""));
69      Parameters.Add(new ValueLookupParameter<PercentValue>("OneProbability", ""));
70      Parameters.Add(new ValueLookupParameter<ItemCollection<IDiscretizer>>("Discretizers", ""));
71      Parameters.Add(new LookupParameter<DecisionList>("DecisionList", ""));
72      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators."));
73      Parameters.Add(new LookupParameter<IGAssistNiche>("GAssistNiche", ""));
74    }
75
76    public override IOperation Apply() {
77      if (GAssistNicheParameter.ActualValue != null && !(GAssistNicheParameter.ActualValue is IAction)) throw new ArgumentException("GAssistNiche has to be a IAction.");
78      DecisionListParameter.ActualValue = Create(RandomParameter.ActualValue,
79                                              ProblemDataParameter.ActualValue.SampleRuleParameter.Value,
80                                              InitialNumberOfRulesParameter.ActualValue.Value,
81                                              OneProbabilityParameter.ActualValue.Value,
82                                              DiscretizersParameter.ActualValue,
83                                              (IAction)GAssistNicheParameter.ActualValue);
84      return base.Apply();
85    }
86
87    protected abstract DecisionList Create(IRandom random, Rule sampleRule, int initialNumberOfRules, double oneProbability, ItemCollection<IDiscretizer> discretizers, IAction niche);
88  }
89}
Note: See TracBrowser for help on using the repository browser.