Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/27/14 10:29:38 (10 years ago)
Author:
mkommend
Message:

#2175: Merged trunk changes into complexity branch.

Location:
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression

  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4

    • Property svn:mergeinfo set to (toggle deleted branches)
      /branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.Regressionmergedeligible
      /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regressionmergedeligible
      /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4mergedeligible
      /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression6917-7005
      /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression4656-4721
      /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5471-5473
      /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5815-6180
      /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression4458-4459,​4462,​4464
      /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression10085-11101
      /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression6284-6795
      /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5060
      /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression8388-8942
      /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression10202-10483
      /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5138-5162
      /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5175-5192
      /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression7748-7810
      /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression6350-6627
      /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression6828
      /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression10204-10479
      /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5370-5682
      /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression6829-6865
      /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5594-5752
      /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression5959-6341
  • branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs

    r9456 r11310  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2020#endregion
    2121
     22using System.Collections.Generic;
     23using System.Linq;
     24using HeuristicLab.Analysis;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2428using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     29using HeuristicLab.Optimization;
    2530using HeuristicLab.Parameters;
    2631using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3742    private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
    3843    private const string EstimationLimitsParameterName = "EstimationLimits";
     44    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
     45
    3946    #region parameter properties
    4047    public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
     
    4653    public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
    4754      get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
     55    }
     56    public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
     57      get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
    4858    }
    4959    #endregion
     
    5767      Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
    5868      Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
     69      Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression."));
     70    }
     71
     72    [StorableHook(HookType.AfterDeserialization)]
     73    private void AfterDeserialization() {
     74      if (!Parameters.ContainsKey(MaximumSymbolicExpressionTreeLengthParameterName))
     75        Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression."));
    5976    }
    6077
     
    6885      return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
    6986    }
     87
     88    public override IOperation Apply() {
     89      var operation = base.Apply();
     90
     91      var paretoFront = TrainingBestSolutionsParameter.ActualValue;
     92
     93      IResult result;
     94      ScatterPlot qualityToTreeSize;
     95      if (!ResultCollection.TryGetValue("Pareto Front Analysis", out result)) {
     96        qualityToTreeSize = new ScatterPlot("Quality vs Tree Size", "");
     97        qualityToTreeSize.VisualProperties.XAxisMinimumAuto = false;
     98        qualityToTreeSize.VisualProperties.XAxisMaximumAuto = false;
     99        qualityToTreeSize.VisualProperties.YAxisMinimumAuto = false;
     100        qualityToTreeSize.VisualProperties.YAxisMaximumAuto = false;
     101
     102        qualityToTreeSize.VisualProperties.XAxisMinimumFixedValue = 0;
     103        qualityToTreeSize.VisualProperties.XAxisMaximumFixedValue = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;
     104        qualityToTreeSize.VisualProperties.YAxisMinimumFixedValue = 0;
     105        qualityToTreeSize.VisualProperties.YAxisMaximumFixedValue = 2;
     106        ResultCollection.Add(new Result("Pareto Front Analysis", qualityToTreeSize));
     107      } else {
     108        qualityToTreeSize = (ScatterPlot)result.Value;
     109      }
     110
     111      var problemData = ProblemDataParameter.ActualValue;
     112      var constantValue = problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices).Average();
     113      var constantSolution = CreateConstantSymbolicRegressionSolution(constantValue);
     114
     115      int previousTreeLength = constantSolution.Model.SymbolicExpressionTree.Length;
     116      var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>();
     117      sizeParetoFront.AddLast(constantSolution);
     118
     119      foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
     120        int treeLength = solution.Model.SymbolicExpressionTree.Length;
     121        if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution);
     122        if (solution.TrainingNormalizedMeanSquaredError < sizeParetoFront.Last.Value.TrainingNormalizedMeanSquaredError) {
     123          if (treeLength == previousTreeLength)
     124            sizeParetoFront.RemoveLast();
     125          sizeParetoFront.AddLast(solution);
     126        }
     127        previousTreeLength = treeLength;
     128      }
     129
     130      qualityToTreeSize.Rows.Clear();
     131      var trainingRow = new ScatterPlotDataRow("Training NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingNormalizedMeanSquaredError)));
     132      trainingRow.VisualProperties.PointSize = 5;
     133      var testRow = new ScatterPlotDataRow("Test NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TestNormalizedMeanSquaredError)));
     134      testRow.VisualProperties.PointSize = 5;
     135      qualityToTreeSize.Rows.Add(trainingRow);
     136      qualityToTreeSize.Rows.Add(testRow);
     137
     138      double trainingHyperVolume, testHyperVolume;
     139      CalculateNormalizedHyperVolume(sizeParetoFront, out trainingHyperVolume, out testHyperVolume);
     140
     141      DoubleValue trainingHyperVolumeResult, testHyperVolumeResult;
     142      if (!ResultCollection.TryGetValue("HyperVolume training", out result)) {
     143        trainingHyperVolumeResult = new DoubleValue();
     144        ResultCollection.Add(new Result("HyperVolume training", trainingHyperVolumeResult));
     145      } else trainingHyperVolumeResult = (DoubleValue)result.Value;
     146
     147      if (!ResultCollection.TryGetValue("HyperVolume test", out result)) {
     148        testHyperVolumeResult = new DoubleValue();
     149        ResultCollection.Add(new Result("HyperVolume test", testHyperVolumeResult));
     150      } else testHyperVolumeResult = (DoubleValue)result.Value;
     151
     152      trainingHyperVolumeResult.Value = trainingHyperVolume;
     153      testHyperVolumeResult.Value = testHyperVolume;
     154
     155      return operation;
     156    }
     157
     158    private void CalculateNormalizedHyperVolume(IEnumerable<ISymbolicRegressionSolution> solutions, out double trainingHyperVolume, out double testHyperVolume) {
     159      trainingHyperVolume = 0.0;
     160      testHyperVolume = 0.0;
     161
     162      var prevX = 0;
     163      var prevYTraining = 1.0;
     164      var prevYTest = 1.0;
     165      var treeSize = 0;
     166
     167      foreach (var solution in solutions) {
     168        treeSize = solution.Model.SymbolicExpressionTree.Length;
     169        trainingHyperVolume += (prevYTraining + solution.TrainingNormalizedMeanSquaredError) * (treeSize - prevX) / 2;
     170        testHyperVolume += (prevYTest + solution.TestNormalizedMeanSquaredError) * (treeSize - prevX) / 2;
     171        prevX = treeSize;
     172        prevYTraining = solution.TrainingNormalizedMeanSquaredError;
     173        prevYTest = solution.TestNormalizedMeanSquaredError;
     174      }
     175
     176      trainingHyperVolume = trainingHyperVolume / treeSize;
     177      testHyperVolume = testHyperVolume / treeSize;
     178    }
     179
     180    private ISymbolicRegressionSolution CreateConstantSymbolicRegressionSolution(double constantValue) {
     181      var grammar = new ArithmeticExpressionGrammar();
     182      var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode();
     183      var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode();
     184      var constantTreeNode = new ConstantTreeNode(new Constant()) { Value = constantValue };
     185      rootNode.AddSubtree(startNode);
     186      startNode.AddSubtree(constantTreeNode);
     187      var tree = new SymbolicExpressionTree();
     188      tree.Root = rootNode;
     189
     190      var model = new SymbolicRegressionModel(tree, SymbolicDataAnalysisTreeInterpreterParameter.ActualValue);
     191      var solution = new SymbolicRegressionSolution(model, ProblemDataParameter.ActualValue);
     192      return solution;
     193    }
    70194  }
    71195}
Note: See TracChangeset for help on using the changeset viewer.