Free cookie consent management tool by TermsFeed Policy Generator

source: branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Evaluators/SymbolicDataAnalysisEvaluator.cs @ 5507

Last change on this file since 5507 was 5500, checked in by mkommend, 14 years ago

#1418: Added all single objective symbolic regression analyzers.

File size: 7.7 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;
23using System.Collections.Generic;
24using System.Linq;
25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
29using HeuristicLab.Operators;
30using HeuristicLab.Parameters;
31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
32using HeuristicLab.Random;
33
34namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
35  public abstract class SymbolicDataAnalysisEvaluator : SingleSuccessorOperator,
36    ISymbolicDataAnalysisEvaluator, ISymbolicDataAnalysisBoundedEvaluator, ISymbolicDataAnalysisInterpreterOperator {
37    private const string RandomParameterName = "Random";
38    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
39    private const string SymbolicExpressionTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
40    private const string ProblemDataParameterName = "ProblemData";
41    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
42    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
43    private const string SamplesStartParameterName = "SamplesStart";
44    private const string SamplesEndParameterName = "SamplesEnd";
45    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
46
47    #region parameter properties
48    public ILookupParameter<IRandom> RandomParameter {
49      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
50    }
51    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
52      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
53    }
54    public ILookupParameter<ISymbolicDataAnalysisTreeInterpreter> SymbolicExpressionTreeInterpreterParameter {
55      get { return (ILookupParameter<ISymbolicDataAnalysisTreeInterpreter>)Parameters[SymbolicExpressionTreeInterpreterParameterName]; }
56    }
57    public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter {
58      get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; }
59    }
60
61    public IValueLookupParameter<IntValue> SamplesStartParameter {
62      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
63    }
64    public IValueLookupParameter<IntValue> SamplesEndParameter {
65      get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
66    }
67
68    public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
69      get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
70    }
71    public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
72      get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
73    }
74
75    public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
76      get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
77    }
78    #endregion
79
80    #region properties
81    public IDataAnalysisProblemData ProblemData {
82      get { return ProblemDataParameter.ActualValue; }
83    }
84
85    public IntValue SamplesStart {
86      get { return SamplesStartParameter.ActualValue; }
87    }
88    public IntValue SamplesEnd {
89      get { return SamplesEndParameter.ActualValue; }
90    }
91    public DoubleValue UpperEstimationLimit {
92      get { return UpperEstimationLimitParameter.ActualValue; }
93    }
94    public DoubleValue LowerEstimationLimit {
95      get { return LowerEstimationLimitParameter.ActualValue; }
96    }
97    public PercentValue RelativeNumberOfEvaluatedSamples {
98      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
99    }
100    #endregion
101
102    [StorableConstructor]
103    protected SymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { }
104    protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator original, Cloner cloner)
105      : base(original, cloner) {
106    }
107    public SymbolicDataAnalysisEvaluator()
108      : base() {
109      Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
110      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisTreeInterpreter>(SymbolicExpressionTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic expression tree."));
111      Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicExpressionTreeInterpreterParameterName, "The symbolic regression solution encoded as a symbolic expression tree."));
112      Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data on which the symbolic regression solution should be evaluated."));
113      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic regression solution should be evaluated."));
114      Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic regression solution should be evaluated."));
115      Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper limit that should be used as cut off value for the output values of symbolic expression trees."));
116      Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower limit that should be used as cut off value for the output values of symbolic expression trees."));
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    protected IEnumerable<int> GenerateRowsToEvaluate() {
121      int seed = RandomParameter.ActualValue.Next();
122      if (SamplesEnd.Value < SamplesStart.Value) throw new ArgumentException("Start value is larger than end value.");
123      int count = (int)((SamplesEnd.Value - SamplesStart.Value) * RelativeNumberOfEvaluatedSamples.Value);
124      if (count == 0) count = 1;
125      return RandomEnumerable.SampleRandomNumbers(seed, SamplesEnd.Value, SamplesStart.Value, count)
126        .Where(i => i < ProblemDataParameter.ActualValue.TestSamplesStart || ProblemDataParameter.ActualValue.TestSamplesEnd <= i);
127    }
128
129    public static IEnumerable<double> BoundEstimatedValues(IEnumerable<double> estimatedValues, double lowerEstimationLimit, double upperEstimationLimit) {
130      return estimatedValues.Select(v => {
131        if (double.IsNaN(v)) return v;
132        else if (v < lowerEstimationLimit) return lowerEstimationLimit;
133        else if (v > upperEstimationLimit) return upperEstimationLimit;
134        return v;
135      });
136    }
137  }
138}
Note: See TracBrowser for help on using the repository browser.