Free cookie consent management tool by TermsFeed Policy Generator

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

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

Implemented basic framework for symbolic regression problems for HL 3.3. #938 (Data types and operators for regression problems)

File size: 4.7 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    #region ISymbolicRegressionEvaluator Members
42
43    public ILookupParameter<DoubleValue> QualityParameter {
44      get { return (ILookupParameter<DoubleValue>)Parameters["Quality"]; }
45    }
46
47    public ILookupParameter<SymbolicExpressionTree> FunctionTreeParameter {
48      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["FunctionTree"]; }
49    }
50
51    public ILookupParameter<Dataset> DatasetParameter {
52      get { return (ILookupParameter<Dataset>)Parameters["Dataset"]; }
53    }
54
55    public ILookupParameter<StringValue> TargetVariableParameter {
56      get { return (ILookupParameter<StringValue>)Parameters["TargetVariable"]; }
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["NumberOfEvaluatedNodes"]; }
69    }
70
71    #endregion
72
73    public SymbolicRegressionEvaluator()
74      : base() {
75      Parameters.Add(new LookupParameter<DoubleValue>("Quality", "The quality of the evaluated symbolic regression solution."));
76      Parameters.Add(new LookupParameter<SymbolicExpressionTree>("FunctionTree", "The symbolic regression solution encoded as a symbolic expression tree."));
77      Parameters.Add(new LookupParameter<Dataset>("Dataset", "The data set on which the symbolic regression solution should be evaluated."));
78      Parameters.Add(new LookupParameter<StringValue>("TargetVariable", "The target variable of the symbolic regression solution."));
79      Parameters.Add(new LookupParameter<IntValue>("SamplesStart", "The start index of the partition of the data set on which the symbolic regression solution should be evaluated."));
80      Parameters.Add(new LookupParameter<IntValue>("SamplesEnd", "The end index of the partition of the data set on which the symbolic regression solution should be evaluated."));
81      Parameters.Add(new LookupParameter<DoubleValue>("NumberOfEvaluatedNodes", "The number of evaluated nodes so far (for performance measurements.)"));
82    }
83
84    public override IOperation Apply() {
85      SymbolicExpressionTree solution = FunctionTreeParameter.ActualValue;
86      Dataset dataset = DatasetParameter.ActualValue;
87      StringValue targetVariable = TargetVariableParameter.ActualValue;
88      IntValue samplesStart = SamplesStartParameter.ActualValue;
89      IntValue samplesEnd = SamplesEndParameter.ActualValue;
90      DoubleValue numberOfEvaluatedNodes = NumberOfEvaluatedNodesParameter.ActualValue;
91     
92      QualityParameter.ActualValue = new DoubleValue(Evaluate(solution, dataset, targetVariable, samplesStart, samplesEnd, numberOfEvaluatedNodes));
93      return null;
94    }
95
96    protected abstract double Evaluate(SymbolicExpressionTree solution, Dataset dataset, StringValue targetVariable, IntValue samplesStart, IntValue samplesEnd, DoubleValue numberOfEvaluatedNodes);
97  }
98}
Note: See TracBrowser for help on using the repository browser.