Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/SymbolicRegressionEvaluator.cs @ 3452

Last change on this file since 3452 was 3452, checked in by gkronber, 14 years ago

Included tracking of best of run solution (based on validation set) and calculation of MSE, R² and rel. Error on training and test sets. #938 (Data types and operators for regression problems)

File size: 5.3 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 System.Collections.Generic;
24using System.Linq;
25using System.Drawing;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Optimization;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.PluginInfrastructure;
33using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
34using HeuristicLab.Problems.DataAnalysis;
35using HeuristicLab.Operators;
36
37namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
38  [Item("SymbolicRegressionEvaluator", "Evaluates a symbolic regression solution.")]
39  [StorableClass]
40  public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator {
41    private const string QualityParameterName = "Quality";
42    private const string FunctionTreeParameterName = "FunctionTree";
43    private const string RegressionProblemDataParameterName = "RegressionProblemData";
44    private const string SamplesStartParameterName = "SamplesStart";
45    private const string SamplesEndParameterName = "SamplesEnd";
46    private const string NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";
47    #region ISymbolicRegressionEvaluator Members
48
49    public ILookupParameter<DoubleValue> QualityParameter {
50      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
51    }
52
53    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
54      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; }
55    }
56
57    public ILookupParameter<DataAnalysisProblemData> RegressionProblemDataParameter {
58      get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[RegressionProblemDataParameterName]; }
59    }
60
61    public IValueLookupParameter<IntValue> SamplesStartParameter {
62      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
63    }
64
65    public IValueLookupParameter<IntValue> SamplesEndParameter {
66      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
67    }
68
69    public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter {
70      get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; }
71    }
72    #endregion
73    #region properties
74    public SymbolicExpressionTree SymbolicExpressionTree {
75      get { return SymbolicExpressionTreeParameter.ActualValue; }
76    }
77    public DataAnalysisProblemData RegressionProblemData {
78      get { return RegressionProblemDataParameter.ActualValue; }
79    }
80    public IntValue SamplesStart {
81      get { return SamplesStartParameter.ActualValue; }
82    }
83    public IntValue SamplesEnd {
84      get { return SamplesEndParameter.ActualValue; }
85    }
86    #endregion
87
88    public SymbolicRegressionEvaluator()
89      : base() {
90      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
91      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
92      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated."));
93      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated."));
94      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated."));
95      Parameters.Add(new LookupParameter<DoubleValue>(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)"));
96    }
97
98    public override IOperation Apply() {
99      DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
100      QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTree, RegressionProblemData.Dataset,
101        RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd, numberOfEvaluatedNodes));
102      return null;
103    }
104
105    protected abstract double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes);
106  }
107}
Note: See TracBrowser for help on using the repository browser.