#region License Information /* HeuristicLab * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System.Linq; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using System.Collections.Generic; using System; using HeuristicLab.Random; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { /// /// Abstract base class for symbolic data analysis analyzers that validate a solution on a separate data partition using the evaluator. /// [StorableClass] public abstract class SymbolicDataAnalysisSingleObjectiveValidationAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer, ISymbolicDataAnalysisValidationAnalyzer where T : class, ISymbolicDataAnalysisSingleObjectiveEvaluator where U : class, IDataAnalysisProblemData { private const string RandomParameterName = "Random"; private const string ProblemDataParameterName = "ProblemData"; private const string EvaluatorParameterName = "Evaluator"; private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; private const string ValidationPartitionParameterName = "ValidationPartition"; private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples"; #region parameter properties public ILookupParameter RandomParameter { get { return (ILookupParameter)Parameters[RandomParameterName]; } } public ILookupParameter ProblemDataParameter { get { return (ILookupParameter)Parameters[ProblemDataParameterName]; } } public ILookupParameter EvaluatorParameter { get { return (ILookupParameter)Parameters[EvaluatorParameterName]; } } public ILookupParameter SymbolicDataAnalysisTreeInterpreterParameter { get { return (ILookupParameter)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } } public IValueLookupParameter ValidationPartitionParameter { get { return (IValueLookupParameter)Parameters[ValidationPartitionParameterName]; } } public IValueLookupParameter RelativeNumberOfEvaluatedSamplesParameter { get { return (IValueLookupParameter)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; } } #endregion [StorableConstructor] protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(bool deserializing) : base(deserializing) { } protected SymbolicDataAnalysisSingleObjectiveValidationAnalyzer(SymbolicDataAnalysisSingleObjectiveValidationAnalyzer original, Cloner cloner) : base(original, cloner) { } public SymbolicDataAnalysisSingleObjectiveValidationAnalyzer() : base() { Parameters.Add(new LookupParameter(RandomParameterName, "The random generator.")); Parameters.Add(new LookupParameter(ProblemDataParameterName, "The problem data of the symbolic data analysis problem.")); Parameters.Add(new LookupParameter(EvaluatorParameterName, "The operator to use for fitness evaluation on the validation partition.")); Parameters.Add(new LookupParameter(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter for symbolic data analysis expression trees.")); Parameters.Add(new ValueLookupParameter(ValidationPartitionParameterName, "Thes validation partition.")); Parameters.Add(new ValueLookupParameter(RelativeNumberOfEvaluatedSamplesParameterName, "The relative number of samples of the dataset partition, which should be randomly chosen for evaluation between the start and end index.")); } protected IEnumerable GenerateRowsToEvaluate() { int seed = RandomParameter.ActualValue.Next(); int samplesStart = ValidationPartitionParameter.ActualValue.Start; int samplesEnd = ValidationPartitionParameter.ActualValue.End; int testPartitionStart = ProblemDataParameter.ActualValue.TestPartition.Start; int testPartitionEnd = ProblemDataParameter.ActualValue.TestPartition.End; if (samplesEnd < samplesStart) throw new ArgumentException("Start value is larger than end value."); int count = (int)((samplesEnd - samplesStart) * RelativeNumberOfEvaluatedSamplesParameter.ActualValue.Value); if (count == 0) count = 1; return RandomEnumerable.SampleRandomNumbers(seed, samplesStart, samplesEnd, count) .Where(i => i < testPartitionStart || testPartitionEnd <= i); } } }