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