Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisMultiObjectiveValidationAnalyzer.cs @ 17886

Last change on this file since 17886 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 5.4 KB
RevLine 
[5607]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) 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
[6059]22using System;
23using System.Collections.Generic;
[5882]24using System.Linq;
[5607]25using HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Parameters;
[16565]29using HEAL.Attic;
[5882]30using HeuristicLab.Random;
[5607]31
32namespace 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>
[16565]36  [StorableType("506B8D0E-891C-453B-842C-18CB33F5CE32")]
[5747]37  public abstract class SymbolicDataAnalysisMultiObjectiveValidationAnalyzer<T, U> : SymbolicDataAnalysisMultiObjectiveAnalyzer,
[5607]38    ISymbolicDataAnalysisValidationAnalyzer<T, U>
[5747]39    where T : class, ISymbolicDataAnalysisMultiObjectiveEvaluator<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";
[5607]47
48    #region parameter properties
[5882]49    public ILookupParameter<IRandom> RandomParameter {
50      get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; }
51    }
[5607]52    public ILookupParameter<U> ProblemDataParameter {
53      get { return (ILookupParameter<U>)Parameters[ProblemDataParameterName]; }
54    }
55    public ILookupParameter<T> EvaluatorParameter {
56      get { return (ILookupParameter<T>)Parameters[EvaluatorParameterName]; }
57    }
[5685]58    public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
59      get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
60    }
[5759]61    public IValueLookupParameter<IntRange> ValidationPartitionParameter {
62      get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
[5607]63    }
[5759]64    public IValueLookupParameter<PercentValue> RelativeNumberOfEvaluatedSamplesParameter {
65      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
[5607]66    }
67    #endregion
[5685]68
[5607]69    [StorableConstructor]
[16565]70    protected SymbolicDataAnalysisMultiObjectiveValidationAnalyzer(StorableConstructorFlag _) : base(_) { }
[5747]71    protected SymbolicDataAnalysisMultiObjectiveValidationAnalyzer(SymbolicDataAnalysisMultiObjectiveValidationAnalyzer<T, U> original, Cloner cloner)
[5607]72      : base(original, cloner) {
73    }
[5747]74    public SymbolicDataAnalysisMultiObjectiveValidationAnalyzer()
[5607]75      : base() {
[6059]76      Parameters.Add(new ValueLookupParameter<IRandom>(RandomParameterName, "The random generator to use."));
[5607]77      Parameters.Add(new LookupParameter<U>(ProblemDataParameterName, "The problem data of the symbolic data analysis problem."));
78      Parameters.Add(new LookupParameter<T>(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition."));
[5685]79      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees."));
[7739]80      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
[5759]81      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."));
[5607]82    }
[5882]83
84    protected IEnumerable<int> GenerateRowsToEvaluate() {
85      int seed = RandomParameter.ActualValue.Next();
86      int samplesStart = ValidationPartitionParameter.ActualValue.Start;
87      int samplesEnd = ValidationPartitionParameter.ActualValue.End;
88      int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start;
89      int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End;
90
91      if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value.");
92      int count = (int)((samplesEnd - samplesStart) * RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value);
93      if (count == 0) count = 1;
94      return RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count)
95        .Where(i => i < testPartitionStart || testPartitionEnd <= i);
96    }
[5607]97  }
98}
Note: See TracBrowser for help on using the repository browser.