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 |
|
---|
22 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
26 | using HeuristicLab.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 | using HeuristicLab.Problems.DataAnalysis.Evaluators;
|
---|
30 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic.Analyzers {
|
---|
33 | /// <summary>
|
---|
34 | /// "An operator to calculate the quality values of a symbolic regression solution symbolic expression tree encoding."
|
---|
35 | /// </summary>
|
---|
36 | [Item("SymbolicRegressionModelQualityCalculator", "An operator to calculate the quality values of a symbolic regression solution symbolic expression tree encoding.")]
|
---|
37 | [StorableClass]
|
---|
38 | public sealed class SymbolicRegressionModelQualityCalculator : AlgorithmOperator {
|
---|
39 | private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
40 | private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
|
---|
41 | private const string ProblemDataParameterName = "ProblemData";
|
---|
42 | private const string ValuesParameterName = "Values";
|
---|
43 | private const string RSQuaredQualityParameterName = "R-squared";
|
---|
44 | private const string MeanSquaredErrorQualityParameterName = "Mean Squared Error";
|
---|
45 | private const string RelativeErrorQualityParameterName = "Relative Error";
|
---|
46 | private const string SamplesStartParameterName = "SamplesStart";
|
---|
47 | private const string SamplesEndParameterName = "SamplesEnd";
|
---|
48 | private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
|
---|
49 | private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
|
---|
50 |
|
---|
51 | #region parameter properties
|
---|
52 | public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
53 | get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
54 | }
|
---|
55 | public IValueLookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
|
---|
56 | get { return (IValueLookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
|
---|
57 | }
|
---|
58 | public IValueLookupParameter<DataAnalysisProblemData> ProblemDataParameter {
|
---|
59 | get { return (IValueLookupParameter<DataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
|
---|
60 | }
|
---|
61 | public IValueLookupParameter<IntValue> SamplesStartParameter {
|
---|
62 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
|
---|
63 | }
|
---|
64 | public IValueLookupParameter<IntValue> SamplesEndParameter {
|
---|
65 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
|
---|
66 | }
|
---|
67 | public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
|
---|
68 | get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
|
---|
69 | }
|
---|
70 | public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
|
---|
71 | get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
|
---|
72 | }
|
---|
73 | public ILookupParameter<DoubleValue> RSquaredQualityParameter {
|
---|
74 | get { return (ILookupParameter<DoubleValue>)Parameters[RSQuaredQualityParameterName]; }
|
---|
75 | }
|
---|
76 | public ILookupParameter<DoubleValue> AverageRelativeErrorQualityParameter {
|
---|
77 | get { return (ILookupParameter<DoubleValue>)Parameters[RelativeErrorQualityParameterName]; }
|
---|
78 | }
|
---|
79 | public ILookupParameter<DoubleValue> MeanSquaredErrorQualityParameter {
|
---|
80 | get { return (ILookupParameter<DoubleValue>)Parameters[MeanSquaredErrorQualityParameterName]; }
|
---|
81 | }
|
---|
82 | #endregion
|
---|
83 |
|
---|
84 | [StorableConstructor]
|
---|
85 | private SymbolicRegressionModelQualityCalculator(bool deserializing) : base(deserializing) { }
|
---|
86 | private SymbolicRegressionModelQualityCalculator(SymbolicRegressionModelQualityCalculator original, Cloner cloner) : base(original, cloner) { }
|
---|
87 | public SymbolicRegressionModelQualityCalculator()
|
---|
88 | : base() {
|
---|
89 | Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression tree to analyze."));
|
---|
90 | Parameters.Add(new ValueLookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
|
---|
91 | Parameters.Add(new ValueLookupParameter<DataAnalysisProblemData>(ProblemDataParameterName, "The problem data containing the input varaibles for the symbolic regression problem."));
|
---|
92 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The first index of the data set partition on which the model quality values should be calculated."));
|
---|
93 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The first index of the data set partition on which the model quality values should be calculated."));
|
---|
94 | Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper limit that should be used as cut off value for the output values of symbolic expression trees."));
|
---|
95 | Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower limit that should be used as cut off value for the output values of symbolic expression trees."));
|
---|
96 | Parameters.Add(new ValueParameter<DoubleMatrix>(ValuesParameterName, "The matrix of original target values and estimated values of the model."));
|
---|
97 | Parameters.Add(new ValueLookupParameter<DoubleValue>(MeanSquaredErrorQualityParameterName, "The mean squared error value of the output of the model."));
|
---|
98 | Parameters.Add(new ValueLookupParameter<DoubleValue>(RSQuaredQualityParameterName, "The R² correlation coefficient of the output of the model and the original target values."));
|
---|
99 | Parameters.Add(new ValueLookupParameter<DoubleValue>(RelativeErrorQualityParameterName, "The average relative percentage error of the output of the model."));
|
---|
100 |
|
---|
101 | #region operator initialization
|
---|
102 | SimpleSymbolicRegressionEvaluator simpleEvaluator = new SimpleSymbolicRegressionEvaluator();
|
---|
103 | SimpleRSquaredEvaluator simpleR2Evalator = new SimpleRSquaredEvaluator();
|
---|
104 | SimpleMeanAbsolutePercentageErrorEvaluator simpleRelErrorEvaluator = new SimpleMeanAbsolutePercentageErrorEvaluator();
|
---|
105 | SimpleMSEEvaluator simpleMseEvaluator = new SimpleMSEEvaluator();
|
---|
106 | Assigner clearValues = new Assigner();
|
---|
107 | #endregion
|
---|
108 |
|
---|
109 | #region parameter wiring
|
---|
110 | simpleEvaluator.SymbolicExpressionTreeParameter.ActualName = SymbolicExpressionTreeParameter.Name;
|
---|
111 | simpleEvaluator.RegressionProblemDataParameter.ActualName = ProblemDataParameter.Name;
|
---|
112 | simpleEvaluator.SamplesStartParameter.ActualName = SamplesStartParameter.Name;
|
---|
113 | simpleEvaluator.SamplesEndParameter.ActualName = SamplesEndParameter.Name;
|
---|
114 | simpleEvaluator.LowerEstimationLimitParameter.ActualName = LowerEstimationLimitParameter.Name;
|
---|
115 | simpleEvaluator.UpperEstimationLimitParameter.ActualName = UpperEstimationLimitParameter.Name;
|
---|
116 | simpleEvaluator.SymbolicExpressionTreeInterpreterParameter.ActualName = SymbolicExpressionTreeInterpreterParameter.Name;
|
---|
117 | simpleEvaluator.ValuesParameter.ActualName = ValuesParameterName;
|
---|
118 |
|
---|
119 | simpleR2Evalator.ValuesParameter.ActualName = ValuesParameterName;
|
---|
120 | simpleR2Evalator.RSquaredParameter.ActualName = RSquaredQualityParameter.Name;
|
---|
121 |
|
---|
122 | simpleMseEvaluator.ValuesParameter.ActualName = ValuesParameterName;
|
---|
123 | simpleMseEvaluator.MeanSquaredErrorParameter.ActualName = MeanSquaredErrorQualityParameter.Name;
|
---|
124 |
|
---|
125 | simpleRelErrorEvaluator.ValuesParameter.ActualName = ValuesParameterName;
|
---|
126 | simpleRelErrorEvaluator.AverageRelativeErrorParameter.ActualName = AverageRelativeErrorQualityParameter.Name;
|
---|
127 |
|
---|
128 | clearValues.LeftSideParameter.ActualName = ValuesParameterName;
|
---|
129 | clearValues.RightSideParameter.Value = new DoubleMatrix();
|
---|
130 | #endregion
|
---|
131 |
|
---|
132 | #region operator graph
|
---|
133 | OperatorGraph.InitialOperator = simpleEvaluator;
|
---|
134 | simpleEvaluator.Successor = simpleR2Evalator;
|
---|
135 | simpleR2Evalator.Successor = simpleRelErrorEvaluator;
|
---|
136 | simpleRelErrorEvaluator.Successor = simpleMseEvaluator;
|
---|
137 | simpleMseEvaluator.Successor = clearValues;
|
---|
138 | clearValues.Successor = null;
|
---|
139 | #endregion
|
---|
140 |
|
---|
141 | }
|
---|
142 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
143 | return new SymbolicRegressionModelQualityCalculator(this, cloner);
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|