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