[5607] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9539] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5607] | 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 |
|
---|
[7172] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
[5882] | 24 | using System.Linq;
|
---|
[5607] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
| 27 | using HeuristicLab.Data;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[5882] | 30 | using HeuristicLab.Random;
|
---|
[5607] | 31 |
|
---|
| 32 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 33 | /// <summary>
|
---|
| 34 | /// Abstract base class for symbolic data analysis analyzers that validate a solution on a separate data partition using the evaluator.
|
---|
| 35 | /// </summary>
|
---|
| 36 | [StorableClass]
|
---|
[5747] | 37 | public abstract class SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<T, U> : SymbolicDataAnalysisSingleObjectiveAnalyzer,
|
---|
[5607] | 38 | ISymbolicDataAnalysisValidationAnalyzer<T, U>
|
---|
[5747] | 39 | where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator<U>
|
---|
[5607] | 40 | where U : class, IDataAnalysisProblemData {
|
---|
[5882] | 41 | private const string RandomParameterName = "Random";
|
---|
[5607] | 42 | private const string ProblemDataParameterName = "ProblemData";
|
---|
| 43 | private const string EvaluatorParameterName = "Evaluator";
|
---|
[5685] | 44 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
|
---|
[5759] | 45 | private const string ValidationPartitionParameterName = "ValidationPartition";
|
---|
| 46 | private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
|
---|
[7721] | 47 | private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions";
|
---|
[5607] | 48 |
|
---|
| 49 | #region parameter properties
|
---|
[5882] | 50 | public ILookupParameter<IRandom> RandomParameter {
|
---|
| 51 | get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
|
---|
| 52 | }
|
---|
[5607] | 53 | public ILookupParameter<U> ProblemDataParameter {
|
---|
| 54 | get { return (ILookupParameter<U>)Parameters[ProblemDataParameterName]; }
|
---|
| 55 | }
|
---|
| 56 | public ILookupParameter<T> EvaluatorParameter {
|
---|
| 57 | get { return (ILookupParameter<T>)Parameters[EvaluatorParameterName]; }
|
---|
| 58 | }
|
---|
[5685] | 59 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
| 60 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
| 61 | }
|
---|
[5759] | 62 | public IValueLookupParameter<IntRange> ValidationPartitionParameter {
|
---|
| 63 | get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
|
---|
[5607] | 64 | }
|
---|
[5759] | 65 | public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
|
---|
| 66 | get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
|
---|
[5607] | 67 | }
|
---|
[7721] | 68 | public IValueLookupParameter<PercentValue> PercentageOfBestSolutionsParameter {
|
---|
| 69 | get { return (IValueLookupParameter<PercentValue>)Parameters[PercentageOfBestSolutionsParameterName]; }
|
---|
| 70 | }
|
---|
[5607] | 71 | #endregion
|
---|
[5685] | 72 |
|
---|
[5607] | 73 | [StorableConstructor]
|
---|
[5747] | 74 | protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 75 | protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(SymbolicDataAnalysisSingleObjectiveValidationAnalyzer<T, U> original, Cloner cloner)
|
---|
[5607] | 76 | : base(original, cloner) {
|
---|
| 77 | }
|
---|
[8828] | 78 |
|
---|
| 79 | protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(): base() {
|
---|
[5882] | 80 | Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random generator."));
|
---|
[5607] | 81 | Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem."));
|
---|
| 82 | Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition."));
|
---|
[5685] | 83 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees."));
|
---|
[8793] | 84 | Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
|
---|
[5759] | 85 | 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."));
|
---|
[7721] | 86 | Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName,
|
---|
| 87 | "The percentage of the top solutions which should be analyzed.", new PercentValue(0.1)));
|
---|
[5607] | 88 | }
|
---|
[5882] | 89 |
|
---|
[7721] | 90 | [StorableHook(HookType.AfterDeserialization)]
|
---|
| 91 | private void AfterDeserialization() {
|
---|
| 92 | if (!Parameters.ContainsKey(PercentageOfBestSolutionsParameterName))
|
---|
| 93 | Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName,
|
---|
| 94 | "The percentage of the top solutions which should be analyzed.", new PercentValue(1)));
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[5882] | 97 | protected IEnumerable<int> GenerateRowsToEvaluate() {
|
---|
| 98 | int seed = RandomParameter.ActualValue.Next();
|
---|
| 99 | int samplesStart = ValidationPartitionParameter.ActualValue.Start;
|
---|
| 100 | int samplesEnd = ValidationPartitionParameter.ActualValue.End;
|
---|
| 101 | int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
|
---|
| 102 | int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
|
---|
| 103 |
|
---|
| 104 | if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
|
---|
| 105 | int count = (int)((samplesEnd - samplesStart) * RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);
|
---|
| 106 | if (count == 0) count = 1;
|
---|
| 107 | return RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count)
|
---|
| 108 | .Where(i => i < testPartitionStart || testPartitionEnd <= i);
|
---|
| 109 | }
|
---|
[5607] | 110 | }
|
---|
| 111 | }
|
---|