Free cookie consent management tool by TermsFeed Policy Generator

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

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

#1980:

  • added DecisionListView
  • added event handlers in *ProblemData
  • renamed project Problems.XCS.Views to Problems.lCS.Views and Problems.Instances.ConditionActionClassification to Problems.Instances.LCS
  • integrated niching in GAssist and added NichingTournamentSelector
  • minor code improvements and property changes
File size: 9.6 KB
RevLine 
[9334]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;
[9352]29using HeuristicLab.Optimization.Operators.LCS;
30using HeuristicLab.Optimization.Operators.LCS.DefaultRule;
[9334]31using HeuristicLab.Parameters;
32using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[9342]33using HeuristicLab.PluginInfrastructure;
[9334]34using HeuristicLab.Problems.DataAnalysis;
[9352]35using HeuristicLab.Problems.Instances;
[9334]36
37namespace HeuristicLab.Problems.DecisionListClassification {
38  [Item("DecisionListClassificationProblem", "")]
39  [StorableClass]
40  [Creatable("Problems")]
[9352]41  public class DecisionListClassificationProblem : HeuristicOptimizationProblem<IDecisionListEvaluator, IDecisionListCreator>,
42                                                   IDecisionListClassificationProblem, IGAssistProblem,
43                                                   IProblemInstanceConsumer<DecisionListClassificationProblemData> {
[9334]44
45    #region parameter properties
46    public IFixedValueParameter<BoolValue> MaximizationParameter {
47      get { return (IFixedValueParameter<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<IntValue> ActivationIterationParameter {
65      get { return (IFixedValueParameter<IntValue>)Parameters["ActivationIteration"]; }
66    }
67    public IFixedValueParameter<DoubleValue> InitialTheoryLengthRatioParameter {
68      get { return (IFixedValueParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; }
69    }
70    public IFixedValueParameter<DoubleValue> WeightRelaxFactorParameter {
71      get { return (IFixedValueParameter<DoubleValue>)Parameters["WeightRelaxFactor"]; }
72    }
[9342]73    public IFixedValueParameter<PercentValue> ActionMutationProbabilityParameter {
74      get { return (IFixedValueParameter<PercentValue>)Parameters["ActionMutationProbability"]; }
75    }
[9334]76
77    public IDecisionListClassificationProblemData ProblemData {
78      get { return ProblemDataParameter.Value; }
79      protected set {
80        ProblemDataParameter.Value = value;
81      }
82    }
83    IParameter IDecisionListClassificationProblem.ProblemDataParameter {
84      get { return ProblemDataParameter; }
85    }
86    IDecisionListClassificationProblemData IDecisionListClassificationProblem.ProblemData {
87      get { return ProblemData; }
88    }
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
104    public DecisionListClassificationProblem()
105      : this(new DecisionListClassificationProblemData(new Dataset(DecisionListClassificationProblemData.defaultVariableNames, DecisionListClassificationProblemData.defaultData),
106        DecisionListClassificationProblemData.defaultVariableNames.Take(DecisionListClassificationProblemData.defaultVariableNames.Length - 1), DecisionListClassificationProblemData.defaultVariableNames.Last()),
107        new MDLEvaluator(), new UniformRandomDecisionListCreator()) { }
108
109    public DecisionListClassificationProblem(IDecisionListClassificationProblemData problemData, IDecisionListEvaluator decisionlistEvaluator, IDecisionListCreator decisionListCreator)
110      : base(decisionlistEvaluator, decisionListCreator) {
111      Parameters.Add(new ValueParameter<IDecisionListClassificationProblemData>("ProblemData", "", problemData));
[9352]112      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "", new BoolValue(false)));
[9334]113      Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownQuality", "", new DoubleValue(0.5)));
114      Parameters.Add(new FixedValueParameter<IntValue>("SizePenaltyMinRules", "", new IntValue(4)));
115      Parameters.Add(new FixedValueParameter<IntValue>("ActivationIteration", "", new IntValue(25)));
116      Parameters.Add(new FixedValueParameter<DoubleValue>("InitialTheoryLengthRatio", "", new DoubleValue(0.075)));
117      Parameters.Add(new FixedValueParameter<DoubleValue>("WeightRelaxFactor", "", new DoubleValue(0.9)));
[9342]118      Parameters.Add(new FixedValueParameter<PercentValue>("ActionMutationProbability", "", new PercentValue(0.1)));
[9334]119
120      Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules";
121      // do differently
122      ((MDLEvaluator)Evaluator).MDLCalculatorParameter.Value = new MDLCalculator(ActivationIterationParameter.Value.Value, InitialTheoryLengthRatioParameter.Value.Value, WeightRelaxFactorParameter.Value.Value);
[9342]123
124      InitializeOperators();
[9334]125    }
[9342]126
127    private void InitializeOperators() {
[9352]128      foreach (var op in ApplicationManager.Manager.GetInstances<IDefaultRuleOperator>())
129        Operators.Add(op);
[9342]130      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListCrossover>())
131        Operators.Add(op);
132      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListManipulator>())
133        Operators.Add(op);
134
135      ParameterizeOperators();
[9352]136
137      BestTrainingDecisionListAnalyzer analyzer = new BestTrainingDecisionListAnalyzer();
138      analyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
139      analyzer.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
140      analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
141      analyzer.ResultsParameter.ActualName = "Results";
142      analyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
143      Operators.Add(analyzer);
[9342]144    }
145
146    private void ParameterizeOperators() {
[9352]147      var autoDefaultRule = Operators.Where(x => x is AutoDefaultRule).Select(x => x as AutoDefaultRule).First();
148      autoDefaultRule.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
149      autoDefaultRule.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
150      autoDefaultRule.NicheComparerParameter.Value = new DecisionListNicheComparer();
151      foreach (IDefaultRuleOperator op in Operators.OfType<IDefaultRuleOperator>()) {
152        op.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
153        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
154        op.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
155        op.GAssistNichesProblemDataParameter.Hidden = true;
156        op.NichingParameter.ActualName = "Niching";
157      }
[9342]158      foreach (IDecisionListCrossover op in Operators.OfType<IDecisionListCrossover>()) {
159        op.ParentsParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
160        op.ParentsParameter.Hidden = true;
161        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
162        op.ChildParameter.Hidden = true;
163      }
164      foreach (IDecisionListManipulator op in Operators.OfType<IDecisionListManipulator>()) {
165        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
166        op.ChildParameter.Hidden = true;
167        op.ActionMutationProbabilityParameter.ActualName = ActionMutationProbabilityParameter.Name;
168        op.ActionMutationProbabilityParameter.Hidden = true;
169      }
170    }
[9334]171    public override IDeepCloneable Clone(Cloner cloner) {
172      return new DecisionListClassificationProblem(this, cloner);
173    }
[9352]174
175    IParameter IGAssistProblem.ProblemDataParameter {
176      get { return ProblemDataParameter; }
177    }
178
179    public string NichingParameterName {
180      get { return "Niching"; }
181    }
182
183    public void Load(DecisionListClassificationProblemData data) {
184      Name = data.Name;
185      Description = data.Description;
186      ProblemData = data;
187    }
[9334]188  }
189}
Note: See TracBrowser for help on using the repository browser.