Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 3381 was 3374, checked in by gkronber, 15 years ago

Refactored HeuristicLab.Problems.DataAnalysis namespace. #938 (Data types and operators for regression problems)

File size: 4.5 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 NumberOfEvaluatedNodexParameterName = "NumberOfEvaluatedNodes";
45    #region ISymbolicRegressionEvaluator Members
46
47    public ILookupParameter<DoubleValue> QualityParameter {
48      get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
49    }
50
51    public ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter {
52      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; }
53    }
54
55    public ILookupParameter<DataAnalysisProblemData> RegressionProblemDataParameter {
56      get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[RegressionProblemDataParameterName]; }
57    }
58
59    //public ILookupParameter<IntValue> SamplesStartParameter {
60    //  get { return (ILookupParameter<IntValue>)Parameters["SamplesStart"]; }
61    //}
62
63    //public ILookupParameter<IntValue> SamplesEndParameter {
64    //  get { return (ILookupParameter<IntValue>)Parameters["SamplesEnd"]; }
65    //}
66
67    public ILookupParameter<DoubleValue> NumberOfEvaluatedNodesParameter {
68      get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfEvaluatedNodexParameterName]; }
69    }
70
71    #endregion
72
73    public SymbolicRegressionEvaluator()
74      : base() {
75      Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
76      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
77      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The data set on which the symbolic regression solution should be evaluated."));
78      Parameters.Add(new LookupParameter<DoubleValue>(NumberOfEvaluatedNodexParameterName, "The number of evaluated nodes so far (for performance measurements.)"));
79    }
80
81    public override IOperation Apply() {
82      SymbolicExpressionTree solution = FunctionTreeParameter.ActualValue;
83      DataAnalysisProblemData regressionProblemData = RegressionProblemDataParameter.ActualValue;
84      DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
85     
86      QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, regressionProblemData.Dataset, regressionProblemData.TargetVariable, regressionProblemData.TrainingSamplesStart, regressionProblemData.TrainingSamplesEnd, numberOfEvaluatedNodes));
87      return null;
88    }
89
90    protected abstract double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes);
91  }
92}
Note: See TracBrowser for help on using the repository browser.