1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
25 | using HeuristicLab.Parameters;
|
---|
26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
27 |
|
---|
28 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
|
---|
29 | /// <summary>
|
---|
30 | /// An operator that analyzes the training best symbolic classification solution for single objective symbolic classification problems.
|
---|
31 | /// </summary>
|
---|
32 | [Item("SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic classification solution for single objective symbolic classification problems.")]
|
---|
33 | [StorableClass]
|
---|
34 | public sealed class SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisSingleObjectiveTrainingBestSolutionAnalyzer<ISymbolicClassificationSolution>,
|
---|
35 | ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator, ISymbolicClassificationModelCreatorOperator {
|
---|
36 | private const string ProblemDataParameterName = "ProblemData";
|
---|
37 | private const string ModelCreatorParameterName = "ModelCreator";
|
---|
38 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
|
---|
39 | private const string EstimationLimitsParameterName = "UpperEstimationLimit";
|
---|
40 | #region parameter properties
|
---|
41 | public ILookupParameter<IClassificationProblemData> ProblemDataParameter {
|
---|
42 | get { return (ILookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; }
|
---|
43 | }
|
---|
44 | public IValueLookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter {
|
---|
45 | get { return (IValueLookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; }
|
---|
46 | }
|
---|
47 | ILookupParameter<ISymbolicClassificationModelCreator> ISymbolicClassificationModelCreatorOperator.ModelCreatorParameter {
|
---|
48 | get { return ModelCreatorParameter; }
|
---|
49 | }
|
---|
50 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
51 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
52 | }
|
---|
53 | public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
54 | get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
55 | }
|
---|
56 | #endregion
|
---|
57 |
|
---|
58 |
|
---|
59 | [StorableConstructor]
|
---|
60 | private SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
61 | private SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
62 | public SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer()
|
---|
63 | : base() {
|
---|
64 | Parameters.Add(new LookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data for the symbolic classification solution."));
|
---|
65 | Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
|
---|
66 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
|
---|
67 | Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
|
---|
68 | }
|
---|
69 |
|
---|
70 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
71 | return new SymbolicClassificationSingleObjectiveTrainingBestSolutionAnalyzer(this, cloner);
|
---|
72 | }
|
---|
73 | [StorableHook(HookType.AfterDeserialization)]
|
---|
74 | private void AfterDeserialization() {
|
---|
75 | // BackwardsCompatibility3.4
|
---|
76 | #region Backwards compatible code, remove with 3.5
|
---|
77 | if (!Parameters.ContainsKey(ModelCreatorParameterName))
|
---|
78 | Parameters.Add(new ValueLookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName, ""));
|
---|
79 | #endregion
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected override ISymbolicClassificationSolution CreateSolution(ISymbolicExpressionTree bestTree, double bestQuality) {
|
---|
83 | var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(ProblemDataParameter.ActualValue.TargetVariable, (ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
|
---|
84 | if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
|
---|
85 |
|
---|
86 | model.RecalculateModelParameters(ProblemDataParameter.ActualValue, ProblemDataParameter.ActualValue.TrainingIndices);
|
---|
87 | return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
|
---|
88 | }
|
---|
89 | }
|
---|
90 | }
|
---|