[5500] | 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 {
|
---|
[5509] | 35 | public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator,
|
---|
| 36 | ISymbolicDataAnalysisBoundedEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator
|
---|
| 37 | where T : class, IDataAnalysisProblemData {
|
---|
[5500] | 38 | private const string RandomParameterName = "Random";
|
---|
| 39 | private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
|
---|
[5514] | 40 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
[5500] | 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 |
|
---|
[5618] | 48 | public override bool CanChangeName { get { return false; } }
|
---|
| 49 |
|
---|
[5500] | 50 | #region parameter properties
|
---|
[5514] | 51 | public IValueLookupParameter<IRandom> RandomParameter {
|
---|
| 52 | get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; }
|
---|
[5500] | 53 | }
|
---|
| 54 | public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
| 55 | get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
| 56 | }
|
---|
[5624] | 57 | public IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
| 58 | get { return (IValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
[5500] | 59 | }
|
---|
[5514] | 60 | public IValueLookupParameter<T> ProblemDataParameter {
|
---|
| 61 | get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
|
---|
[5500] | 62 | }
|
---|
| 63 |
|
---|
[5618] | 64 | public IFixedValueParameter<IntValue> SamplesStartParameter {
|
---|
| 65 | get { return (IFixedValueParameter<IntValue>)Parameters[SamplesStartParameterName]; }
|
---|
[5500] | 66 | }
|
---|
[5618] | 67 | public IFixedValueParameter<IntValue> SamplesEndParameter {
|
---|
| 68 | get { return (IFixedValueParameter<IntValue>)Parameters[SamplesEndParameterName]; }
|
---|
[5500] | 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 |
|
---|
[5618] | 78 | public IFixedValueParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
| 79 | get { return (IFixedValueParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
[5500] | 80 | }
|
---|
| 81 | #endregion
|
---|
| 82 |
|
---|
| 83 | #region properties
|
---|
[5607] | 84 | public IRandom Random {
|
---|
| 85 | get { return RandomParameter.ActualValue; }
|
---|
| 86 | }
|
---|
| 87 | public ISymbolicExpressionTree SymbolicExpressionTree {
|
---|
| 88 | get { return SymbolicExpressionTreeParameter.ActualValue; }
|
---|
| 89 | }
|
---|
[5624] | 90 | public ISymbolicDataAnalysisExpressionTreeInterpreter SymbolicDataAnalysisTreeInterpreter {
|
---|
[5607] | 91 | get { return SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; }
|
---|
| 92 | }
|
---|
[5509] | 93 | public T ProblemData {
|
---|
[5500] | 94 | get { return ProblemDataParameter.ActualValue; }
|
---|
| 95 | }
|
---|
| 96 | public IntValue SamplesStart {
|
---|
[5618] | 97 | get { return SamplesStartParameter.Value; }
|
---|
[5500] | 98 | }
|
---|
| 99 | public IntValue SamplesEnd {
|
---|
[5618] | 100 | get { return SamplesEndParameter.Value; }
|
---|
[5500] | 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) { }
|
---|
[5509] | 115 | protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator<T> original, Cloner cloner)
|
---|
[5500] | 116 | : base(original, cloner) {
|
---|
| 117 | }
|
---|
| 118 | public SymbolicDataAnalysisEvaluator()
|
---|
| 119 | : base() {
|
---|
[5514] | 120 | Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
|
---|
[5624] | 121 | Parameters.Add(new ValueLookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
|
---|
[5618] | 122 | Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree."));
|
---|
[5514] | 123 | Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
|
---|
[5618] | 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()));
|
---|
[5509] | 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."));
|
---|
[5618] | 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)));
|
---|
[5500] | 129 | }
|
---|
| 130 |
|
---|
| 131 | protected IEnumerable<int> GenerateRowsToEvaluate() {
|
---|
| 132 | int seed = RandomParameter.ActualValue.Next();
|
---|
[5618] | 133 |
|
---|
[5500] | 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;
|
---|
[5618] | 137 | return RandomEnumerable.SampleRandomNumbers(seed, SamplesStart.Value, SamplesEnd.Value, count)
|
---|
[5586] | 138 | .Where(i => i < ProblemDataParameter.ActualValue.TestPartitionStart.Value || ProblemDataParameter.ActualValue.TestPartitionEnd.Value <= i);
|
---|
[5500] | 139 | }
|
---|
| 140 | }
|
---|
| 141 | }
|
---|