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 |
|
---|
22 | using System.Linq;
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Data;
|
---|
26 | using HeuristicLab.Encodings.DecisionList;
|
---|
27 | using HeuristicLab.Encodings.DecisionList.Interfaces;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Optimization.Operators.LCS;
|
---|
30 | using HeuristicLab.Optimization.Operators.LCS.DefaultRule;
|
---|
31 | using HeuristicLab.Parameters;
|
---|
32 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
33 | using HeuristicLab.PluginInfrastructure;
|
---|
34 | using HeuristicLab.Problems.DataAnalysis;
|
---|
35 | using HeuristicLab.Problems.Instances;
|
---|
36 |
|
---|
37 | namespace 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 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 | }
|
---|
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 | IStrataSingleObjectiveEvaluator 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 UniformRandomDecisionListCreator()) { }
|
---|
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 | Evaluator.SizePenaltyMinRulesParameter.ActualName = "SizePenaltyMinRules";
|
---|
121 |
|
---|
122 | InitializeOperators();
|
---|
123 | }
|
---|
124 |
|
---|
125 | private void InitializeOperators() {
|
---|
126 | foreach (var op in ApplicationManager.Manager.GetInstances<IDefaultRuleOperator>())
|
---|
127 | Operators.Add(op);
|
---|
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();
|
---|
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);
|
---|
142 | }
|
---|
143 |
|
---|
144 | private void ParameterizeOperators() {
|
---|
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;
|
---|
148 | autoDefaultRule.NicheComparerParameter.Value = new GAssistNicheComparer();
|
---|
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 | }
|
---|
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 | }
|
---|
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 | }
|
---|
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
|
---|
189 | }
|
---|
190 | }
|
---|