Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityCalculator.cs @ 6315

Last change on this file since 6315 was 4722, checked in by swagner, 14 years ago

Merged cloning refactoring branch back into trunk (#922)

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