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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
29 | using HeuristicLab.Operators;
|
---|
30 | using HeuristicLab.Parameters;
|
---|
31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
32 | using HeuristicLab.Random;
|
---|
33 |
|
---|
34 | namespace 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 | #region parameter properties
|
---|
49 | public IValueLookupParameter<IRandom> RandomParameter {
|
---|
50 | get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; }
|
---|
51 | }
|
---|
52 | public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
53 | get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
54 | }
|
---|
55 | public IValueLookupParameter<ISymbolicDataAnalysisTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
56 | get { return (IValueLookupParameter<ISymbolicDataAnalysisTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
57 | }
|
---|
58 | public IValueLookupParameter<T> ProblemDataParameter {
|
---|
59 | get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | public IValueLookupParameter<IntValue> SamplesStartParameter {
|
---|
63 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesStartParameterName]; }
|
---|
64 | }
|
---|
65 | public IValueLookupParameter<IntValue> SamplesEndParameter {
|
---|
66 | get { return (IValueLookupParameter<IntValue>)Parameters[SamplesEndParameterName]; }
|
---|
67 | }
|
---|
68 |
|
---|
69 | public IValueLookupParameter<DoubleValue> UpperEstimationLimitParameter {
|
---|
70 | get { return (IValueLookupParameter<DoubleValue>)Parameters[UpperEstimationLimitParameterName]; }
|
---|
71 | }
|
---|
72 | public IValueLookupParameter<DoubleValue> LowerEstimationLimitParameter {
|
---|
73 | get { return (IValueLookupParameter<DoubleValue>)Parameters[LowerEstimationLimitParameterName]; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public IValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
77 | get { return (IValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
78 | }
|
---|
79 | #endregion
|
---|
80 |
|
---|
81 | #region properties
|
---|
82 | public T ProblemData {
|
---|
83 | get { return ProblemDataParameter.ActualValue; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public IntValue SamplesStart {
|
---|
87 | get { return SamplesStartParameter.ActualValue; }
|
---|
88 | }
|
---|
89 | public IntValue SamplesEnd {
|
---|
90 | get { return SamplesEndParameter.ActualValue; }
|
---|
91 | }
|
---|
92 | public DoubleValue UpperEstimationLimit {
|
---|
93 | get { return UpperEstimationLimitParameter.ActualValue; }
|
---|
94 | }
|
---|
95 | public DoubleValue LowerEstimationLimit {
|
---|
96 | get { return LowerEstimationLimitParameter.ActualValue; }
|
---|
97 | }
|
---|
98 | public PercentValue RelativeNumberOfEvaluatedSamples {
|
---|
99 | get { return RelativeNumberOfEvaluatedSamplesParameter.Value; }
|
---|
100 | }
|
---|
101 | #endregion
|
---|
102 |
|
---|
103 | [StorableConstructor]
|
---|
104 | protected SymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { }
|
---|
105 | protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator<T> original, Cloner cloner)
|
---|
106 | : base(original, cloner) {
|
---|
107 | }
|
---|
108 | public SymbolicDataAnalysisEvaluator()
|
---|
109 | : base() {
|
---|
110 | Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
|
---|
111 | Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
|
---|
112 | Parameters.Add(new LookupParameter<SymbolicExpressionTree>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree."));
|
---|
113 | Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
|
---|
114 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesStartParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
|
---|
115 | Parameters.Add(new ValueLookupParameter<IntValue>(SamplesEndParameterName, "The end index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
|
---|
116 | 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."));
|
---|
117 | 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."));
|
---|
118 | 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)));
|
---|
119 | }
|
---|
120 |
|
---|
121 | protected IEnumerable<int> GenerateRowsToEvaluate() {
|
---|
122 | int seed = RandomParameter.ActualValue.Next();
|
---|
123 | if (SamplesEnd.Value < SamplesStart.Value) throw new ArgumentException("Start value is larger than end value.");
|
---|
124 | int count = (int)((SamplesEnd.Value - SamplesStart.Value) * RelativeNumberOfEvaluatedSamples.Value);
|
---|
125 | if (count == 0) count = 1;
|
---|
126 | return RandomEnumerable.SampleRandomNumbers(seed, SamplesEnd.Value, SamplesStart.Value, count)
|
---|
127 | .Where(i => i < ProblemDataParameter.ActualValue.TestPartitionStart.Value || ProblemDataParameter.ActualValue.TestPartitionEnd.Value <= i);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|