Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PersistenceSpeedUp/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Evaluators/MultiObjectiveSymbolicRegressionEvaluator.cs @ 15802

Last change on this file since 15802 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 7.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
28using HeuristicLab.Operators;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.Problems.DataAnalysis.Symbolic;
32
33namespace HeuristicLab.Problems.DataAnalysis.Regression.Symbolic {
34  [Item("MultiObjectiveSymbolicRegressionEvaluator", "Evaluates a symbolic regression solution.")]
35  [StorableClass]
36  public abstract class MultiObjectiveSymbolicRegressionEvaluator : SingleSuccessorOperator, IMultiObjectiveSymbolicRegressionEvaluator {
37    private const string RandomParameterName = "Random";
38    private const string QualitiesParameterName = "Qualities";
39    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
40    private const string FunctionTreeParameterName = "FunctionTree";
41    private const string RegressionProblemDataParameterName = "RegressionProblemData";
42    private const string SamplesStartParameterName = "SamplesStart";
43    private const string SamplesEndParameterName = "SamplesEnd";
44    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
45    #region ISymbolicRegressionEvaluator Members
46
47    public ILookupParameter<DoubleArray> QualitiesParameter {
48      get { return (ILookupParameter<DoubleArray>)Parameters[QualitiesParameterName]; }
49    }
50
51    public ILookupParameter<ISymbolicExpressionTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
52      get { return (ILookupParameter<ISymbolicExpressionTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
53    }
54
55    public ILookupParameter<SymbolicExpressionTree> SymbolicExpressionTreeParameter {
56      get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[FunctionTreeParameterName]; }
57    }
58
59    public ILookupParameter<DataAnalysisProblemData> RegressionProblemDataParameter {
60      get { return (ILookupParameter<DataAnalysisProblemData>)Parameters[RegressionProblemDataParameterName]; }
61    }
62
63    public IValueLookupParameter<IntValue> SamplesStartParameter {
64      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
65    }
66
67    public IValueLookupParameter<IntValue> SamplesEndParameter {
68      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
69    }
70
71    public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
72      get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
73    }
74
75    public ILookupParameter<IRandom> RandomParameter {
76      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
77    }
78
79    #endregion
80    #region properties
81    public IRandom Random {
82      get { return RandomParameter.ActualValue; }
83    }
84    public ISymbolicExpressionTreeInterpreter SymbolicExpressionTreeInterpreter {
85      get { return SymbolicExpressionTreeInterpreterParameter.ActualValue; }
86    }
87    public SymbolicExpressionTree SymbolicExpressionTree {
88      get { return SymbolicExpressionTreeParameter.ActualValue; }
89    }
90    public DataAnalysisProblemData RegressionProblemData {
91      get { return RegressionProblemDataParameter.ActualValue; }
92    }
93    public IntValue SamplesStart {
94      get { return SamplesStartParameter.ActualValue; }
95    }
96    public IntValue SamplesEnd {
97      get { return SamplesEndParameter.ActualValue; }
98    }
99
100    public PercentValue RelativeNumberOfEvaluatedSamples {
101      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
102    }
103    #endregion
104
105    [StorableConstructor]
106    protected MultiObjectiveSymbolicRegressionEvaluator(bool deserializing) : base(deserializing) { }
107    protected MultiObjectiveSymbolicRegressionEvaluator(MultiObjectiveSymbolicRegressionEvaluator original, Cloner cloner) : base(original, cloner) { }
108    public MultiObjectiveSymbolicRegressionEvaluator()
109      : base() {
110      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
111      Parameters.Add(new LookupParameter<DoubleArray>(QualitiesParameterName, "The qualities of the evaluated symbolic regression solution."));
112      Parameters.Add(new LookupParameter<ISymbolicExpressionTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
113      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(FunctionTreeParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
114      Parameters.Add(new LookupParameter<DataAnalysisProblemData>(RegressionProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated."));
115      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated."));
116      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated."));
117      Parameters.Add(new ValueParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.", new PercentValue(1)));
118    }
119
120    public override IOperation Apply() {
121      int seed = Random.Next();
122      IEnumerable<int> rows = SingleObjectiveSymbolicRegressionEvaluator.GenerateRowsToEvaluate(seed, RelativeNumberOfEvaluatedSamples.Value, SamplesStart.Value, SamplesEnd.Value)
123         .Where(i => i < RegressionProblemData.TestSamplesStart.Value || RegressionProblemData.TestSamplesEnd.Value <= i);
124      double[] qualities = Evaluate(SymbolicExpressionTreeInterpreter, SymbolicExpressionTree, RegressionProblemData.Dataset,
125        RegressionProblemData.TargetVariable, rows);
126      QualitiesParameter.ActualValue = new DoubleArray(qualities);
127      return base.Apply();
128    }
129
130
131    protected abstract double[] Evaluate(ISymbolicExpressionTreeInterpreter interpreter,
132      SymbolicExpressionTree solution,
133      Dataset dataset,
134      StringValue targetVariable,
135      IEnumerable<int> rows);
136  }
137}
Note: See TracBrowser for help on using the repository browser.