1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2011 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 | using System.Linq;
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
|
---|
29 | [Item("Symbolic Classification Problem (multi objective)", "Represents a multi objective symbolic classfication problem.")]
|
---|
30 | [StorableClass]
|
---|
31 | [Creatable("Problems")]
|
---|
32 | public class SymbolicClassificationMultiObjectiveProblem : SymbolicDataAnalysisMultiObjectiveProblem<IClassificationProblemData, ISymbolicClassificationMultiObjectiveEvaluator, ISymbolicDataAnalysisSolutionCreator>, IClassificationProblem {
|
---|
33 | private const double PunishmentFactor = 10;
|
---|
34 | private const int InitialMaximumTreeDepth = 8;
|
---|
35 | private const int InitialMaximumTreeLength = 25;
|
---|
36 | private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
|
---|
37 | private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
|
---|
38 | private const string LowerEstimationLimitParameterDescription = "The lower limit for the estimated value that can be returned by the symbolic classification model.";
|
---|
39 | private const string UpperEstimationLimitParameterDescription = "The upper limit for the estimated value that can be returned by the symbolic classification model.";
|
---|
40 |
|
---|
41 | #region parameter properties
|
---|
42 | public IFixedValueParameter<DoubleValue> LowerEstimationLimitParameter {
|
---|
43 | get { return (IFixedValueParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
|
---|
44 | }
|
---|
45 | public IFixedValueParameter<DoubleValue> UpperEstimationLimitParameter {
|
---|
46 | get { return (IFixedValueParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
|
---|
47 | }
|
---|
48 | #endregion
|
---|
49 | #region properties
|
---|
50 | public DoubleValue LowerEstimationLimit {
|
---|
51 | get { return LowerEstimationLimitParameter.Value; }
|
---|
52 | }
|
---|
53 | public DoubleValue UpperEstimationLimit {
|
---|
54 | get { return UpperEstimationLimitParameter.Value; }
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 | [StorableConstructor]
|
---|
58 | protected SymbolicClassificationMultiObjectiveProblem(bool deserializing) : base(deserializing) { }
|
---|
59 | protected SymbolicClassificationMultiObjectiveProblem(SymbolicClassificationMultiObjectiveProblem original, Cloner cloner) : base(original, cloner) { }
|
---|
60 | public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicClassificationMultiObjectiveProblem(this, cloner); }
|
---|
61 |
|
---|
62 | public SymbolicClassificationMultiObjectiveProblem()
|
---|
63 | : base(new ClassificationProblemData(), new SymbolicClassificationMultiObjectiveMeanSquaredErrorTreeSizeEvaluator(), new SymbolicDataAnalysisExpressionTreeCreator()) {
|
---|
64 | Parameters.Add(new FixedValueParameter<DoubleValue>(LowerEstimationLimitParameterName, LowerEstimationLimitParameterDescription, new DoubleValue()));
|
---|
65 | Parameters.Add(new FixedValueParameter<DoubleValue>(UpperEstimationLimitParameterName, UpperEstimationLimitParameterDescription, new DoubleValue()));
|
---|
66 |
|
---|
67 | Maximization = new BoolArray(new bool[] { false, false });
|
---|
68 | MaximumSymbolicExpressionTreeDepth.Value = InitialMaximumTreeDepth;
|
---|
69 | MaximumSymbolicExpressionTreeLength.Value = InitialMaximumTreeLength;
|
---|
70 |
|
---|
71 | InitializeOperators();
|
---|
72 | UpdateEstimationLimits();
|
---|
73 | }
|
---|
74 |
|
---|
75 | private void InitializeOperators() {
|
---|
76 | Operators.Add(new SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer());
|
---|
77 | Operators.Add(new SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer());
|
---|
78 | ParameterizeOperators();
|
---|
79 | }
|
---|
80 |
|
---|
81 | private void UpdateEstimationLimits() {
|
---|
82 | if (ProblemData.TrainingPartition.Start < ProblemData.TrainingPartition.End) {
|
---|
83 | var targetValues = ProblemData.Dataset.GetVariableValues(ProblemData.TargetVariable, ProblemData.TrainingPartition.Start, ProblemData.TrainingPartition.End);
|
---|
84 | var mean = targetValues.Average();
|
---|
85 | var range = targetValues.Max() - targetValues.Min();
|
---|
86 | UpperEstimationLimit.Value = mean + PunishmentFactor * range;
|
---|
87 | LowerEstimationLimit.Value = mean - PunishmentFactor * range;
|
---|
88 | }
|
---|
89 | }
|
---|
90 |
|
---|
91 | protected override void OnProblemDataChanged() {
|
---|
92 | base.OnProblemDataChanged();
|
---|
93 | UpdateEstimationLimits();
|
---|
94 | }
|
---|
95 |
|
---|
96 | protected new void ParameterizeOperators() {
|
---|
97 | base.ParameterizeOperators();
|
---|
98 | var operators = Parameters.OfType<IValueParameter>().Select(p => p.Value).OfType<IOperator>().Union(Operators);
|
---|
99 | foreach (var op in operators.OfType<ISymbolicDataAnalysisBoundedOperator>()) {
|
---|
100 | op.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameterName;
|
---|
101 | op.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameterName;
|
---|
102 | }
|
---|
103 | }
|
---|
104 |
|
---|
105 | public override void ImportProblemDataFromFile(string fileName) {
|
---|
106 | ClassificationProblemData problemData = ClassificationProblemData.ImportFromFile(fileName);
|
---|
107 | ProblemData = problemData;
|
---|
108 | }
|
---|
109 | }
|
---|
110 | }
|
---|