Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs @ 13402

Last change on this file since 13402 was 12012, checked in by ascheibe, 10 years ago

#2212 merged r12008, r12009, r12010 back into trunk

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