Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/SymbolicRegressionModelQualityCalculator.cs @ 4468

Last change on this file since 4468 was 4468, checked in by mkommend, 14 years ago

Preparation for cross validation - removed the test samples from the trainining samples and added ValidationPercentage parameter (ticket #1199).

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