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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Drawing;
|
---|
26 | using HeuristicLab.Common;
|
---|
27 | using HeuristicLab.Core;
|
---|
28 | using HeuristicLab.Data;
|
---|
29 | using HeuristicLab.Optimization;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.PluginInfrastructure;
|
---|
33 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
34 | using HeuristicLab.Problems.DataAnalysis;
|
---|
35 | using HeuristicLab.Operators;
|
---|
36 |
|
---|
37 | namespace 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 | }
|
---|