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