Free cookie consent management tool by TermsFeed Policy Generator

Changeset 7721 for trunk/sources


Ignore:
Timestamp:
04/11/12 07:37:02 (13 years ago)
Author:
gkronber
Message:

#1817 added parameter to symbolic data analysis validation analyzers to determine the percentage of best solutions that should be evaluated on the validation set

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationAnalyzer.cs

    r7259 r7721  
    4545    private const string ValidationPartitionParameterName = "ValidationPartition";
    4646    private const string RelativeNumberOfEvaluatedSamplesParameterName = "RelativeNumberOfEvaluatedSamples";
     47    private const string PercentageOfBestSolutionsParameterName = "PercentageOfBestSolutions";
    4748
    4849    #region parameter properties
     
    6566      get { return (IValueLookupParameter<PercentValue>)Parameters[RelativeNumberOfEvaluatedSamplesParameterName]; }
    6667    }
     68    public IValueLookupParameter<PercentValue> PercentageOfBestSolutionsParameter {
     69      get { return (IValueLookupParameter<PercentValue>)Parameters[PercentageOfBestSolutionsParameterName]; }
     70    }
    6771    #endregion
    6872
     
    8084      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "Thes validation partition."));
    8185      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."));
     86      Parameters.Add(new ValueLookupParameter<PercentValue>(PercentageOfBestSolutionsParameterName,
     87                                                            "The percentage of the top solutions which should be analyzed.", new PercentValue(0.1)));
     88    }
     89
     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)));
    8295    }
    8396
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectiveValidationBestSolutionAnalyzer.cs

    r7259 r7721  
    2020#endregion
    2121
     22using System;
    2223using System.Collections.Generic;
    2324using System.Linq;
     
    7273
    7374    public override IOperation Apply() {
    74       #region find best tree
    75       double bestQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;
    76       ISymbolicExpressionTree bestTree = null;
    77       ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
    78       var evaluator = EvaluatorParameter.ActualValue;
    79       var problemData = ProblemDataParameter.ActualValue;
    8075      IEnumerable<int> rows = GenerateRowsToEvaluate();
    8176      if (!rows.Any()) return base.Apply();
    8277
     78      #region find best tree
     79      var evaluator = EvaluatorParameter.ActualValue;
     80      var problemData = ProblemDataParameter.ActualValue;
     81      double bestValidationQuality = Maximization.Value ? double.NegativeInfinity : double.PositiveInfinity;
     82      ISymbolicExpressionTree bestTree = null;
     83      ISymbolicExpressionTree[] tree = SymbolicExpressionTree.ToArray();
     84
     85      // sort is ascending and we take the first n% => order so that best solutions are smallest
     86      // sort order is determined by maximization parameter
     87      double[] trainingQuality;
     88      if (Maximization.Value) {
     89        // largest values must be sorted first
     90        trainingQuality = Quality.Select(x => -x.Value).ToArray();
     91      } else {
     92        // smallest values must be sorted first
     93        trainingQuality = Quality.Select(x => x.Value).ToArray();
     94      }
     95
     96      // sort trees by training qualities
     97      Array.Sort(trainingQuality, tree);
     98
     99      // number of best training solutions to validate (at least 1)
     100      int topN = (int)Math.Max(tree.Length * PercentageOfBestSolutionsParameter.ActualValue.Value, 1);
     101
    83102      IExecutionContext childContext = (IExecutionContext)ExecutionContext.CreateChildOperation(evaluator);
     103      // evaluate best n training trees on validiation set
    84104      var quality = tree
     105        .Take(topN)
    85106        .AsParallel()
    86107        .Select(t => evaluator.Evaluate(childContext, t, problemData, rows))
    87108        .ToArray();
    88109
    89       for (int i = 0; i < tree.Length; i++) {
    90         if (IsBetter(quality[i], bestQuality, Maximization.Value)) {
    91           bestQuality = quality[i];
     110      for (int i = 0; i < quality.Length; i++) {
     111        if (IsBetter(quality[i], bestValidationQuality, Maximization.Value)) {
     112          bestValidationQuality = quality[i];
    92113          bestTree = tree[i];
    93114        }
     
    97118      var results = ResultCollection;
    98119      if (ValidationBestSolutionQuality == null ||
    99         IsBetter(bestQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) {
    100         ValidationBestSolution = CreateSolution(bestTree, bestQuality);
    101         ValidationBestSolutionQuality = new DoubleValue(bestQuality);
     120        IsBetter(bestValidationQuality, ValidationBestSolutionQuality.Value, Maximization.Value)) {
     121        ValidationBestSolution = CreateSolution(bestTree, bestValidationQuality);
     122        ValidationBestSolutionQuality = new DoubleValue(bestValidationQuality);
    102123
    103124        if (!results.ContainsKey(ValidationBestSolutionParameter.Name)) {
Note: See TracChangeset for help on using the changeset viewer.