Changeset 11310 for branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
- Timestamp:
- 08/27/14 10:29:38 (10 years ago)
- Location:
- branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/branches/HLScript/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged eligible /stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged eligible /trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4 merged eligible /branches/Benchmarking/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6917-7005 /branches/CloningRefactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5471-5473 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5815-6180 /branches/DataAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 4458-4459,4462,4464 /branches/DataPreprocessing/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10085-11101 /branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5060 /branches/HeuristicLab.TreeSimplifier/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 8388-8942 /branches/LogResidualEvaluator/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10202-10483 /branches/NET40/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5138-5162 /branches/ParallelEngine/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 7748-7810 /branches/QAPAlgorithms/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6828 /branches/SpectralKernelForGaussianProcesses/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 10204-10479 /branches/SuccessProgressAnalysis/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5370-5682 /branches/Trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 6829-6865 /branches/VNS/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5594-5752 /branches/histogram/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/DataAnalysis.ComplexityAnalyzer/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/MultiObjective/SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs
r9456 r11310 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 24 using HeuristicLab.Analysis; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 24 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 25 30 using HeuristicLab.Parameters; 26 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 37 42 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 38 43 private const string EstimationLimitsParameterName = "EstimationLimits"; 44 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 45 39 46 #region parameter properties 40 47 public ILookupParameter<IRegressionProblemData> ProblemDataParameter { … … 46 53 public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter { 47 54 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 55 } 56 public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { 57 get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; } 48 58 } 49 59 #endregion … … 57 67 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 58 68 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.")); 59 76 } 60 77 … … 68 85 return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone()); 69 86 } 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 } 70 194 } 71 195 }
Note: See TracChangeset
for help on using the changeset viewer.