Free cookie consent management tool by TermsFeed Policy Generator

Changeset 17450


Ignore:
Timestamp:
02/25/20 15:56:36 (5 years ago)
Author:
fholzing
Message:

#3019: Copied and adapted Pareto Front Analysis functionality from SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer to SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r17180 r17450  
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
     24using HEAL.Attic;
     25using HeuristicLab.Analysis;
    2226using HeuristicLab.Common;
    2327using HeuristicLab.Core;
     28using HeuristicLab.Data;
    2429using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     30using HeuristicLab.Optimization;
    2531using HeuristicLab.Parameters;
    26 using HEAL.Attic;
    2732
    2833namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification {
     
    3843    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3944    private const string EstimationLimitsParameterName = "EstimationLimits";
     45    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     46    private const string ValidationPartitionParameterName = "ValidationPartition";
     47    private const string AnalyzeTestErrorParameterName = "Analyze Test Error";
    4048
    4149    #region parameter properties
     
    5563      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
    5664    }
     65    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     66      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
     67    }
     68    public IValueLookupParameter<IntRange> ValidationPartitionParameter {
     69      get { return (IValueLookupParameter<IntRange>)Parameters[ValidationPartitionParameterName]; }
     70    }
     71    public IFixedValueParameter<BoolValue> AnalyzeTestErrorParameter {
     72      get { return (IFixedValueParameter<BoolValue>)Parameters[AnalyzeTestErrorParameterName]; }
     73    }
     74    public bool AnalyzeTestError {
     75      get { return AnalyzeTestErrorParameter.Value.Value; }
     76      set { AnalyzeTestErrorParameter.Value.Value = value; }
     77    }
    5778    #endregion
    5879
     
    6687      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    6788      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic classification model."));
     89      Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression.") { Hidden = true });
     90      Parameters.Add(new ValueLookupParameter<IntRange>(ValidationPartitionParameterName, "The validation partition."));
     91      Parameters.Add(new FixedValueParameter<BoolValue>(AnalyzeTestErrorParameterName, "Flag whether the test error should be displayed in the Pareto-Front", new BoolValue(false)));
     92
    6893    }
    6994    public override IDeepCloneable Clone(Cloner cloner) {
     
    87112      return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone());
    88113    }
     114
     115    public override IOperation Apply() {
     116      var operation = base.Apply();
     117      var paretoFront = TrainingBestSolutionsParameter.ActualValue;
     118
     119      IResult result;
     120      ScatterPlot qualityToTreeSize;
     121      if (!ResultCollection.TryGetValue("Pareto Front Analysis", out result)) {
     122        qualityToTreeSize = new ScatterPlot("Quality vs Tree Size", "");
     123        qualityToTreeSize.VisualProperties.XAxisMinimumAuto = false;
     124        qualityToTreeSize.VisualProperties.XAxisMaximumAuto = false;
     125        qualityToTreeSize.VisualProperties.YAxisMinimumAuto = false;
     126        qualityToTreeSize.VisualProperties.YAxisMaximumAuto = false;
     127
     128        qualityToTreeSize.VisualProperties.XAxisMinimumFixedValue = 0;
     129        qualityToTreeSize.VisualProperties.XAxisMaximumFixedValue = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     130        qualityToTreeSize.VisualProperties.YAxisMinimumFixedValue = 0;
     131        qualityToTreeSize.VisualProperties.YAxisMaximumFixedValue = 1;
     132        ResultCollection.Add(new Result("Pareto Front Analysis", qualityToTreeSize));
     133      } else {
     134        qualityToTreeSize = (ScatterPlot)result.Value;
     135      }
     136
     137      int previousTreeLength = -1;
     138      var sizeParetoFront = new LinkedList<ISymbolicClassificationSolution>();
     139      foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
     140        int treeLength = solution.Model.SymbolicExpressionTree.Length;
     141        if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution);
     142        if (solution.TrainingAccuracy > sizeParetoFront.Last.Value.TrainingAccuracy) {
     143          if (treeLength == previousTreeLength)
     144            sizeParetoFront.RemoveLast();
     145          sizeParetoFront.AddLast(solution);
     146        }
     147        previousTreeLength = treeLength;
     148      }
     149
     150      qualityToTreeSize.Rows.Clear();
     151      var trainingRow = new ScatterPlotDataRow("Training Accuracy", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingAccuracy, x)));
     152      trainingRow.VisualProperties.PointSize = 8;
     153      qualityToTreeSize.Rows.Add(trainingRow);
     154
     155      if (AnalyzeTestError) {
     156        var testRow = new ScatterPlotDataRow("Test Accuracy", "",
     157          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TestAccuracy, x)));
     158        testRow.VisualProperties.PointSize = 8;
     159        qualityToTreeSize.Rows.Add(testRow);
     160      }
     161
     162      var validationPartition = ValidationPartitionParameter.ActualValue;
     163      if (validationPartition.Size != 0) {
     164        var problemData = ProblemDataParameter.ActualValue;
     165        var validationIndizes = Enumerable.Range(validationPartition.Start, validationPartition.Size).ToList();
     166        var targetValues = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, validationIndizes).ToList();
     167        OnlineCalculatorError error;
     168        var validationRow = new ScatterPlotDataRow("Validation Accuracy", "",
     169          sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length,
     170          OnlineAccuracyCalculator.Calculate(targetValues, x.GetEstimatedClassValues(validationIndizes), out error))));
     171        validationRow.VisualProperties.PointSize = 7;
     172        qualityToTreeSize.Rows.Add(validationRow);
     173      }
     174
     175      return operation;
     176    }
    89177  }
    90178}
Note: See TracChangeset for help on using the changeset viewer.