Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Problems.DecisionListClassification/3.3/DecisionListClassificationProblem.cs @ 17195

Last change on this file since 17195 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: 9.4 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.Linq;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.DecisionList;
27using HeuristicLab.Encodings.DecisionList.Interfaces;
28using HeuristicLab.Optimization;
29using HeuristicLab.Optimization.Operators.LCS;
30using HeuristicLab.Optimization.Operators.LCS.DefaultRule;
31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
33using HeuristicLab.PluginInfrastructure;
34using HeuristicLab.Problems.DataAnalysis;
35using HeuristicLab.Problems.Instances;
36
37namespace HeuristicLab.Problems.DecisionListClassification {
38  [Item("DecisionListClassificationProblem", "")]
39  [StorableClass]
40  [Creatable("Problems")]
41  public class DecisionListClassificationProblem : HeuristicOptimizationProblem<IDecisionListEvaluator, IDecisionListCreator>,
42                                                   IDecisionListClassificationProblem, IGAssistProblem,
43                                                   IProblemInstanceConsumer<DecisionListClassificationProblemData> {
44
45    #region parameter properties
46    public FixedValueParameter<BoolValue> MaximizationParameter {
47      get { return (FixedValueParameter<BoolValue>)Parameters["Maximization"]; }
48    }
49    IParameter ISingleObjectiveHeuristicOptimizationProblem.MaximizationParameter {
50      get { return MaximizationParameter; }
51    }
52    public IFixedValueParameter<DoubleValue> BestKnownQualityParameter {
53      get { return (IFixedValueParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
54    }
55    IParameter ISingleObjectiveHeuristicOptimizationProblem.BestKnownQualityParameter {
56      get { return BestKnownQualityParameter; }
57    }
58    public IValueParameter<IDecisionListClassificationProblemData> ProblemDataParameter {
59      get { return (IValueParameter<IDecisionListClassificationProblemData>)Parameters["ProblemData"]; }
60    }
61    public IFixedValueParameter<IntValue> SizePenaltyMinRulesParameter {
62      get { return (IFixedValueParameter<IntValue>)Parameters["SizePenaltyMinRules"]; }
63    }
64    public IFixedValueParameter<DoubleValue> InitialTheoryLengthRatioParameter {
65      get { return (IFixedValueParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; }
66    }
67    public IFixedValueParameter<DoubleValue> WeightRelaxFactorParameter {
68      get { return (IFixedValueParameter<DoubleValue>)Parameters["WeightRelaxFactor"]; }
69    }
70    public IFixedValueParameter<PercentValue> ActionMutationProbabilityParameter {
71      get { return (IFixedValueParameter<PercentValue>)Parameters["ActionMutationProbability"]; }
72    }
73
74    public IDecisionListClassificationProblemData ProblemData {
75      get { return ProblemDataParameter.Value; }
76      protected set {
77        ProblemDataParameter.Value = value;
78      }
79    }
80    IParameter IDecisionListClassificationProblem.ProblemDataParameter {
81      get { return ProblemDataParameter; }
82    }
83    IDecisionListClassificationProblemData IDecisionListClassificationProblem.ProblemData {
84      get { return ProblemData; }
85    }
86
87    IGAssistObjectiveEvaluator IGAssistProblem.Evaluator {
88      get { return Evaluator; }
89    }
90    IDecisionListEvaluator IDecisionListClassificationProblem.Evaluator {
91      get { return Evaluator; }
92    }
93    ISingleObjectiveEvaluator ISingleObjectiveHeuristicOptimizationProblem.Evaluator {
94      get { return Evaluator; }
95    }
96    #endregion
97
98    [StorableConstructor]
99    protected DecisionListClassificationProblem(bool deserializing) : base(deserializing) { }
100    protected DecisionListClassificationProblem(DecisionListClassificationProblem original, Cloner cloner)
101      : base(original, cloner) {
102    }
103    public override IDeepCloneable Clone(Cloner cloner) {
104      return new DecisionListClassificationProblem(this, cloner);
105    }
106
107    public DecisionListClassificationProblem()
108      : this(new DecisionListClassificationProblemData(new Dataset(DecisionListClassificationProblemData.defaultVariableNames, DecisionListClassificationProblemData.defaultData),
109        DecisionListClassificationProblemData.defaultVariableNames.Take(DecisionListClassificationProblemData.defaultVariableNames.Length - 1), DecisionListClassificationProblemData.defaultVariableNames.Last()),
110        new MDLEvaluator(), new SmartDecisionListCreator()) { }
111
112    public DecisionListClassificationProblem(IDecisionListClassificationProblemData problemData, IDecisionListEvaluator decisionlistEvaluator, IDecisionListCreator decisionListCreator)
113      : base(decisionlistEvaluator, decisionListCreator) {
114      Parameters.Add(new ValueParameter<IDecisionListClassificationProblemData>("ProblemData", "", problemData));
115      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "", new BoolValue(false)));
116      Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownQuality", "", new DoubleValue(0.5)));
117      Parameters.Add(new FixedValueParameter<IntValue>("SizePenaltyMinRules", "", new IntValue(4)));
118      Parameters.Add(new FixedValueParameter<PercentValue>("ActionMutationProbability", "", new PercentValue(0.1)));
119
120      MaximizationParameter.Value.Value = Evaluator.MaximizationParameter.Value.Value;
121      Evaluator.MaximizationParameter.Value.ValueChanged += MaximizationParameter_ValueChanged;
122      Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules";
123
124      InitializeOperators();
125    }
126
127    private void MaximizationParameter_ValueChanged(object sender, System.EventArgs e) {
128      MaximizationParameter.Value.Value = Evaluator.MaximizationParameter.Value.Value;
129    }
130
131    private void InitializeOperators() {
132      foreach (var op in ApplicationManager.Manager.GetInstances<IDefaultRuleOperator>())
133        Operators.Add(op);
134      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListCrossover>())
135        Operators.Add(op);
136      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListManipulator>())
137        Operators.Add(op);
138
139      ParameterizeOperators();
140
141      BestTrainingDecisionListAnalyzer analyzer = new BestTrainingDecisionListAnalyzer();
142      analyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
143      analyzer.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
144      analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
145      analyzer.ResultsParameter.ActualName = "Results";
146      analyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
147      Operators.Add(analyzer);
148    }
149
150    private void ParameterizeOperators() {
151      var autoDefaultRule = Operators.OfType<AutoDefaultRule>().First();
152      autoDefaultRule.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
153      autoDefaultRule.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
154      autoDefaultRule.NicheComparerParameter.Value = new GAssistNicheComparer();
155      foreach (IDefaultRuleOperator op in Operators.OfType<IDefaultRuleOperator>()) {
156        op.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
157        op.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
158        op.GAssistNichesProblemDataParameter.Hidden = true;
159        op.NichingParameter.ActualName = "Niching";
160      }
161      foreach (IDecisionListCrossover op in Operators.OfType<IDecisionListCrossover>()) {
162        op.ParentsParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
163        op.ParentsParameter.Hidden = true;
164        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
165        op.ChildParameter.Hidden = true;
166      }
167      foreach (IDecisionListManipulator op in Operators.OfType<IDecisionListManipulator>()) {
168        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
169        op.ChildParameter.Hidden = true;
170        op.ActionMutationProbabilityParameter.ActualName = ActionMutationProbabilityParameter.Name;
171        op.ActionMutationProbabilityParameter.Hidden = true;
172      }
173    }
174
175    public string NichingParameterName {
176      get { return "Niching"; }
177    }
178
179    public void Load(DecisionListClassificationProblemData data) {
180      Name = data.Name;
181      Description = data.Description;
182      ProblemData = data;
183    }
184
185    #region IDataAnalysisProblem Members
186    IParameter IDataAnalysisProblem.ProblemDataParameter {
187      get { return ProblemDataParameter; }
188    }
189    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
190      get { return ProblemData; }
191    }
192    public event System.EventHandler ProblemDataChanged;
193    #endregion
194  }
195}
Note: See TracBrowser for help on using the repository browser.