[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 {
|
---|
[5689] | 35 | [StorableClass]
|
---|
[5509] | 36 | public abstract class SymbolicDataAnalysisEvaluator<T> : SingleSuccessorOperator,
|
---|
[5720] | 37 | ISymbolicDataAnalysisEvaluator<T>, ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator
|
---|
[5509] | 38 | where T : class, IDataAnalysisProblemData {
|
---|
[5500] | 39 | private const string RandomParameterName = "Random";
|
---|
| 40 | private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree";
|
---|
[5514] | 41 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter";
|
---|
[5500] | 42 | private const string ProblemDataParameterName = "ProblemData";
|
---|
[5770] | 43 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
[5759] | 44 | private const string EvaluationPartitionParameterName = "EvaluationPartition";
|
---|
[5500] | 45 | private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
|
---|
| 46 |
|
---|
[5618] | 47 | public override bool CanChangeName { get { return false; } }
|
---|
| 48 |
|
---|
[5500] | 49 | #region parameter properties
|
---|
[5514] | 50 | public IValueLookupParameter<IRandom> RandomParameter {
|
---|
| 51 | get { return (IValueLookupParameter<IRandom>)Parameters[RandomParameterName]; }
|
---|
[5500] | 52 | }
|
---|
| 53 | public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter {
|
---|
| 54 | get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; }
|
---|
| 55 | }
|
---|
[5649] | 56 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
| 57 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
[5500] | 58 | }
|
---|
[5514] | 59 | public IValueLookupParameter<T> ProblemDataParameter {
|
---|
| 60 | get { return (IValueLookupParameter<T>)Parameters[ProblemDataParameterName]; }
|
---|
[5500] | 61 | }
|
---|
| 62 |
|
---|
[5759] | 63 | public IValueLookupParameter<IntRange> EvaluationPartitionParameter {
|
---|
| 64 | get { return (IValueLookupParameter<IntRange>)Parameters[EvaluationPartitionParameterName]; }
|
---|
[5500] | 65 | }
|
---|
[5770] | 66 | public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 67 | get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
[5500] | 68 | }
|
---|
[5759] | 69 | public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
| 70 | get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
[5500] | 71 | }
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | [StorableConstructor]
|
---|
| 76 | protected SymbolicDataAnalysisEvaluator(bool deserializing) : base(deserializing) { }
|
---|
[5509] | 77 | protected SymbolicDataAnalysisEvaluator(SymbolicDataAnalysisEvaluator<T> original, Cloner cloner)
|
---|
[5500] | 78 | : base(original, cloner) {
|
---|
| 79 | }
|
---|
| 80 | public SymbolicDataAnalysisEvaluator()
|
---|
| 81 | : base() {
|
---|
[5514] | 82 | Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
|
---|
[5649] | 83 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree."));
|
---|
[5618] | 84 | Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic data analysis solution encoded as a symbolic expression tree."));
|
---|
[5514] | 85 | Parameters.Add(new ValueLookupParameter<T>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated."));
|
---|
[5759] | 86 | Parameters.Add(new ValueLookupParameter<IntRange>(EvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated."));
|
---|
[5770] | 87 | Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees."));
|
---|
[5759] | 88 | Parameters.Add(new ValueLookupParameter<PercentValue>(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index."));
|
---|
[5500] | 89 | }
|
---|
| 90 |
|
---|
| 91 | protected IEnumerable<int> GenerateRowsToEvaluate() {
|
---|
[5914] | 92 | return GenerateRowsToEvaluate(RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | protected IEnumerable<int> GenerateRowsToEvaluate(double percentageOfRows) {
|
---|
| 96 |
|
---|
| 97 |
|
---|
| 98 | IEnumerable<int> rows;
|
---|
[5759] | 99 | int samplesStart = EvaluationPartitionParameter.ActualValue.Start;
|
---|
| 100 | int samplesEnd = EvaluationPartitionParameter.ActualValue.End;
|
---|
[5823] | 101 | int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
|
---|
| 102 | int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
|
---|
[5618] | 103 |
|
---|
[5759] | 104 | if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
|
---|
[5914] | 105 |
|
---|
| 106 | if (percentageOfRows.IsAlmost(1.0))
|
---|
| 107 | rows = Enumerable.Range(samplesStart, samplesEnd - samplesStart);
|
---|
| 108 | else {
|
---|
| 109 | int seed = RandomParameter.ActualValue.Next();
|
---|
| 110 | int count = (int)((samplesEnd - samplesStart) * percentageOfRows);
|
---|
| 111 | if (count == 0) count = 1;
|
---|
| 112 | rows = RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count);
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | return rows.Where(i => i < testPartitionStart || testPartitionEnd <= i);
|
---|
[5500] | 116 | }
|
---|
| 117 | }
|
---|
| 118 | }
|
---|