Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 9596 was 9411, checked in by sforsten, 12 years ago

#1980:

  • added multiple discretizer to GAssist
  • created ensembles for LCS problems and edited CrossValidation to use them
File size: 9.2 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<DoubleValue> InitialTheoryLengthRatioParameter {
65      get { return (IFixedValueParameter<DoubleValue>)Parameters["InitialTheoryLengthRatio"]; }
66    }
67    public IFixedValueParameter<DoubleValue> WeightRelaxFactorParameter {
68      get { return (IFixedValueParameter<DoubleValue>)Parameters["WeightRelaxFactor"]; }
69    }
[9342]70    public IFixedValueParameter<PercentValue> ActionMutationProbabilityParameter {
71      get { return (IFixedValueParameter<PercentValue>)Parameters["ActionMutationProbability"]; }
72    }
[9334]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
[9392]87    IStrataSingleObjectiveEvaluator IGAssistProblem.Evaluator {
88      get { return Evaluator; }
89    }
[9334]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    }
[9392]103    public override IDeepCloneable Clone(Cloner cloner) {
104      return new DecisionListClassificationProblem(this, cloner);
105    }
[9334]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 UniformRandomDecisionListCreator()) { }
111
112    public DecisionListClassificationProblem(IDecisionListClassificationProblemData problemData, IDecisionListEvaluator decisionlistEvaluator, IDecisionListCreator decisionListCreator)
113      : base(decisionlistEvaluator, decisionListCreator) {
114      Parameters.Add(new ValueParameter<IDecisionListClassificationProblemData>("ProblemData", "", problemData));
[9352]115      Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "", new BoolValue(false)));
[9334]116      Parameters.Add(new FixedValueParameter<DoubleValue>("BestKnownQuality", "", new DoubleValue(0.5)));
117      Parameters.Add(new FixedValueParameter<IntValue>("SizePenaltyMinRules", "", new IntValue(4)));
[9342]118      Parameters.Add(new FixedValueParameter<PercentValue>("ActionMutationProbability", "", new PercentValue(0.1)));
[9334]119
120      Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules";
[9342]121
122      InitializeOperators();
[9334]123    }
[9342]124
125    private void InitializeOperators() {
[9352]126      foreach (var op in ApplicationManager.Manager.GetInstances<IDefaultRuleOperator>())
127        Operators.Add(op);
[9342]128      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListCrossover>())
129        Operators.Add(op);
130      foreach (var op in ApplicationManager.Manager.GetInstances<IDecisionListManipulator>())
131        Operators.Add(op);
132
133      ParameterizeOperators();
[9352]134
135      BestTrainingDecisionListAnalyzer analyzer = new BestTrainingDecisionListAnalyzer();
136      analyzer.ProblemDataParameter.ActualName = ProblemDataParameter.Name;
137      analyzer.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
138      analyzer.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
139      analyzer.ResultsParameter.ActualName = "Results";
140      analyzer.MaximizationParameter.ActualName = MaximizationParameter.Name;
141      Operators.Add(analyzer);
[9342]142    }
143
144    private void ParameterizeOperators() {
[9352]145      var autoDefaultRule = Operators.Where(x => x is AutoDefaultRule).Select(x => x as AutoDefaultRule).First();
146      autoDefaultRule.QualityParameter.ActualName = Evaluator.QualityParameter.ActualName;
147      autoDefaultRule.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
[9411]148      autoDefaultRule.NicheComparerParameter.Value = new GAssistNicheComparer();
[9352]149      foreach (IDefaultRuleOperator op in Operators.OfType<IDefaultRuleOperator>()) {
150        op.IndividualParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
151        op.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
152        op.GAssistNichesProblemDataParameter.ActualName = ProblemDataParameter.Name;
153        op.GAssistNichesProblemDataParameter.Hidden = true;
154        op.NichingParameter.ActualName = "Niching";
155      }
[9342]156      foreach (IDecisionListCrossover op in Operators.OfType<IDecisionListCrossover>()) {
157        op.ParentsParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
158        op.ParentsParameter.Hidden = true;
159        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
160        op.ChildParameter.Hidden = true;
161      }
162      foreach (IDecisionListManipulator op in Operators.OfType<IDecisionListManipulator>()) {
163        op.ChildParameter.ActualName = SolutionCreator.DecisionListParameter.ActualName;
164        op.ChildParameter.Hidden = true;
165        op.ActionMutationProbabilityParameter.ActualName = ActionMutationProbabilityParameter.Name;
166        op.ActionMutationProbabilityParameter.Hidden = true;
167      }
168    }
[9352]169
170    public string NichingParameterName {
171      get { return "Niching"; }
172    }
173
174    public void Load(DecisionListClassificationProblemData data) {
175      Name = data.Name;
176      Description = data.Description;
177      ProblemData = data;
178    }
[9411]179
180    #region IDataAnalysisProblem Members
181    IParameter IDataAnalysisProblem.ProblemDataParameter {
182      get { return ProblemDataParameter; }
183    }
184    IDataAnalysisProblemData IDataAnalysisProblem.ProblemData {
185      get { return ProblemData; }
186    }
187    public event System.EventHandler ProblemDataChanged;
188    #endregion
[9334]189  }
190}
Note: See TracBrowser for help on using the repository browser.