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 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
37 |
|
---|
38 | namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
|
---|
39 | [Item("SymbolicRegressionEvaluator", "Evaluates a symbolic regression solution.")]
|
---|
40 | [StorableClass]
|
---|
41 | public abstract class SymbolicRegressionEvaluator : SingleSuccessorOperator, ISymbolicRegressionEvaluator {
|
---|
42 | private const string QualityParameterName = "Quality";
|
---|
43 | private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
44 | private const string FunctionTreeParameterName = "FunctionTree";
|
---|
45 | private const string RegressionProblemDataParameterName = "RegressionProblemData";
|
---|
46 | private const string SamplesStartParameterName = "SamplesStart";
|
---|
47 | private const string SamplesEndParameterName = "SamplesEnd";
|
---|
48 | #region ISymbolicRegressionEvaluator Members
|
---|
49 |
|
---|
50 | public ILookupParameter<DoubleValue> QualityParameter {
|
---|
51 | get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
|
---|
55 | get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
59 | get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public ILookupParameter<DataAnalysisProblemData> RegressionProblemDataParameter {
|
---|
63 | get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[RegressionProblemDataParameterName]; }
|
---|
64 | }
|
---|
65 |
|
---|
66 | public IValueLookupParameter<IntValue> SamplesStartParameter {
|
---|
67 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
|
---|
68 | }
|
---|
69 |
|
---|
70 | public IValueLookupParameter<IntValue> SamplesEndParameter {
|
---|
71 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
|
---|
72 | }
|
---|
73 |
|
---|
74 | #endregion
|
---|
75 | #region properties
|
---|
76 | public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
|
---|
77 | get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
|
---|
78 | }
|
---|
79 | public SymbolicExpressionTree SymbolicExpressionTree {
|
---|
80 | get { return SymbolicExpressionTreeParameter.ActualValue; }
|
---|
81 | }
|
---|
82 | public DataAnalysisProblemData RegressionProblemData {
|
---|
83 | get { return RegressionProblemDataParameter.ActualValue; }
|
---|
84 | }
|
---|
85 | public IntValue SamplesStart {
|
---|
86 | get { return SamplesStartParameter.ActualValue; }
|
---|
87 | }
|
---|
88 | public IntValue SamplesEnd {
|
---|
89 | get { return SamplesEndParameter.ActualValue; }
|
---|
90 | }
|
---|
91 | #endregion
|
---|
92 |
|
---|
93 | public SymbolicRegressionEvaluator()
|
---|
94 | : base() {
|
---|
95 | Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName, "The quality of the evaluated symbolic regression solution."));
|
---|
96 | Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
|
---|
97 | Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
|
---|
98 | Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated."));
|
---|
99 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated."));
|
---|
100 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated."));
|
---|
101 | }
|
---|
102 |
|
---|
103 | public override IOperation Apply() {
|
---|
104 | QualityParameter.ActualValue = new DoubleValue(Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset,
|
---|
105 | RegressionProblemData.TargetVariable, SamplesStart, SamplesEnd));
|
---|
106 | return base.Apply();
|
---|
107 | }
|
---|
108 |
|
---|
109 | protected abstract double Evaluate(ISymbolicExpressionTreeInterpreter interpreter,
|
---|
110 | SymbolicExpressionTree solution,
|
---|
111 | Dataset dataset,
|
---|
112 | StringValue targetVariable,
|
---|
113 | IntValue samplesStart, IntValue samplesEnd);
|
---|
114 | }
|
---|
115 | }
|
---|