[3374] | 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 | 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 | }
|
---|