Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 5624 was 5624, checked in by gkronber, 13 years ago

#1418 renamed interface for interpreter, worked on solutions and models and implemented SVM regression.

File size: 7.8 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<T> : SingleSuccessorOperator,
36    ISymbolicDataAnalysisBoundedEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator
37  where T : class, IDataAnalysisProblemData {
38    private const string RandomParameterName = "Random";
39    private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
40    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
41    private const string ProblemDataParameterName = "ProblemData";
42    private const string UpperEstimationLimitParameterName = "UpperEstimationLimit";
43    private const string LowerEstimationLimitParameterName = "LowerEstimationLimit";
44    private const string SamplesStartParameterName = "SamplesStart";
45    private const string SamplesEndParameterName = "SamplesEnd";
46    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
47
48    public override bool CanChangeName { get { return false; } }
49
50    #region parameter properties
51    public IValueLookupParameter<IRandom> RandomParameter {
52      get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; }
53    }
54    public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
55      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
56    }
57    public IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
58      get { return (IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
59    }
60    public IValueLookupParameter<T> ProblemDataParameter {
61      get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
62    }
63
64    public IFixedValueParameter<IntValue> SamplesStartParameter {
65      get { return (IFixedValueParameter<IntValue>)Parameters[SamplesStartParameterName]; }
66    }
67    public IFixedValueParameter<IntValue> SamplesEndParameter {
68      get { return (IFixedValueParameter<IntValue>)Parameters[SamplesEndParameterName]; }
69    }
70
71    public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
72      get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
73    }
74    public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
75      get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
76    }
77
78    public IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
79      get { return (IFixedValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
80    }
81    #endregion
82
83    #region properties
84    public IRandom Random {
85      get { return RandomParameter.ActualValue; }
86    }
87    public ISymbolicExpressionTree SymbolicExpressionTree {
88      get { return SymbolicExpressionTreeParameter.ActualValue; }
89    }
90    public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicDataAnalysisTreeInterpreter {
91      get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; }
92    }
93    public T ProblemData {
94      get { return ProblemDataParameter.ActualValue; }
95    }
96    public IntValue SamplesStart {
97      get { return SamplesStartParameter.Value; }
98    }
99    public IntValue SamplesEnd {
100      get { return SamplesEndParameter.Value; }
101    }
102    public DoubleValue UpperEstimationLimit {
103      get { return UpperEstimationLimitParameter.ActualValue; }
104    }
105    public DoubleValue LowerEstimationLimit {
106      get { return LowerEstimationLimitParameter.ActualValue; }
107    }
108    public PercentValue RelativeNumberOfEvaluatedSamples {
109      get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
110    }
111    #endregion
112
113    [StorableConstructor]
114    protected SymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { }
115    protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator<T> original, Cloner cloner)
116      : base(original, cloner) {
117    }
118    public SymbolicDataAnalysisEvaluator()
119      : base() {
120      Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
121      Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
122      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree."));
123      Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
124      Parameters.Add(new FixedValueParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.", new IntValue()));
125      Parameters.Add(new FixedValueParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic data analysis solution should be evaluated.", new IntValue()));
126      Parameters.Add(new ValueLookupParameter<DoubleValue>(UpperEstimationLimitParameterName, "The upper limit that should be used as cut off value for the output values of symbolic data analysis trees."));
127      Parameters.Add(new ValueLookupParameter<DoubleValue>(LowerEstimationLimitParameterName, "The lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
128      Parameters.Add(new FixedValueParameter<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)));
129    }
130
131    protected IEnumerable<int> GenerateRowsToEvaluate() {
132      int seed = RandomParameter.ActualValue.Next();
133
134      if (SamplesEnd.Value < SamplesStart.Value) throw new ArgumentException("Start value is larger than end value.");
135      int count = (int)((SamplesEnd.Value - SamplesStart.Value) * RelativeNumberOfEvaluatedSamples.Value);
136      if (count == 0) count = 1;
137      return RandomEnumerable.SampleRandomNumbers(seed, SamplesStart.Value, SamplesEnd.Value, count)
138        .Where(i => i < ProblemDataParameter.ActualValue.TestPartitionStart.Value || ProblemDataParameter.ActualValue.TestPartitionEnd.Value <= i);
139    }
140  }
141}
Note: See TracBrowser for help on using the repository browser.