[5557] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[11310] | 3 | * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[5557] | 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
[11310] | 22 | using System.Collections.Generic;
|
---|
| 23 | using System.Linq;
|
---|
| 24 | using HeuristicLab.Analysis;
|
---|
[5557] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[11310] | 27 | using HeuristicLab.Data;
|
---|
[5557] | 28 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
[11310] | 29 | using HeuristicLab.Optimization;
|
---|
[5557] | 30 | using HeuristicLab.Parameters;
|
---|
| 31 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 32 |
|
---|
| 33 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression {
|
---|
| 34 | /// <summary>
|
---|
| 35 | /// An operator that analyzes the training best symbolic regression solution for multi objective symbolic regression problems.
|
---|
| 36 | /// </summary>
|
---|
| 37 | [Item("SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer", "An operator that analyzes the training best symbolic regression solution for multi objective symbolic regression problems.")]
|
---|
| 38 | [StorableClass]
|
---|
[5685] | 39 | public sealed class SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer : SymbolicDataAnalysisMultiObjectiveTrainingBestSolutionAnalyzer<ISymbolicRegressionSolution>,
|
---|
[5747] | 40 | ISymbolicDataAnalysisInterpreterOperator, ISymbolicDataAnalysisBoundedOperator {
|
---|
[5685] | 41 | private const string ProblemDataParameterName = "ProblemData";
|
---|
| 42 | private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter";
|
---|
[5770] | 43 | private const string EstimationLimitsParameterName = "EstimationLimits";
|
---|
[11310] | 44 | private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
| 45 |
|
---|
[5685] | 46 | #region parameter properties
|
---|
| 47 | public ILookupParameter<IRegressionProblemData> ProblemDataParameter {
|
---|
| 48 | get { return (ILookupParameter<IRegressionProblemData>)Parameters[ProblemDataParameterName]; }
|
---|
| 49 | }
|
---|
| 50 | public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> SymbolicDataAnalysisTreeInterpreterParameter {
|
---|
| 51 | get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; }
|
---|
| 52 | }
|
---|
[5770] | 53 | public IValueLookupParameter<DoubleLimit> EstimationLimitsParameter {
|
---|
| 54 | get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }
|
---|
[5720] | 55 | }
|
---|
[11310] | 56 | public ILookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {
|
---|
| 57 | get { return (ILookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }
|
---|
| 58 | }
|
---|
[5685] | 59 | #endregion
|
---|
| 60 |
|
---|
[5557] | 61 | [StorableConstructor]
|
---|
| 62 | private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
| 63 | private SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 64 | public SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer()
|
---|
| 65 | : base() {
|
---|
[5685] | 66 | Parameters.Add(new LookupParameter<IRegressionProblemData>(ProblemDataParameterName, "The problem data for the symbolic regression solution."));
|
---|
| 67 | Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree."));
|
---|
[5770] | 68 | Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The lower and upper limit for the estimated values produced by the symbolic regression model."));
|
---|
[11310] | 69 | Parameters.Add(new LookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "Maximal length of the symbolic expression."));
|
---|
[5557] | 70 | }
|
---|
[5685] | 71 |
|
---|
[11310] | 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."));
|
---|
| 76 | }
|
---|
| 77 |
|
---|
[5557] | 78 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 79 | return new SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer(this, cloner);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | protected override ISymbolicRegressionSolution CreateSolution(ISymbolicExpressionTree bestTree, double[] bestQuality) {
|
---|
[5914] | 83 | var model = new SymbolicRegressionModel((ISymbolicExpressionTree)bestTree.Clone(), SymbolicDataAnalysisTreeInterpreterParameter.ActualValue, EstimationLimitsParameter.ActualValue.Lower, EstimationLimitsParameter.ActualValue.Upper);
|
---|
[8972] | 84 | if (ApplyLinearScalingParameter.ActualValue.Value) model.Scale(ProblemDataParameter.ActualValue);
|
---|
[5914] | 85 | return new SymbolicRegressionSolution(model, (IRegressionProblemData)ProblemDataParameter.ActualValue.Clone());
|
---|
[5557] | 86 | }
|
---|
[11310] | 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 |
|
---|
[11883] | 112 | int previousTreeLength = -1;
|
---|
[11310] | 113 | var sizeParetoFront = new LinkedList<ISymbolicRegressionSolution>();
|
---|
| 114 | foreach (var solution in paretoFront.OrderBy(s => s.Model.SymbolicExpressionTree.Length)) {
|
---|
| 115 | int treeLength = solution.Model.SymbolicExpressionTree.Length;
|
---|
| 116 | if (!sizeParetoFront.Any()) sizeParetoFront.AddLast(solution);
|
---|
| 117 | if (solution.TrainingNormalizedMeanSquaredError < sizeParetoFront.Last.Value.TrainingNormalizedMeanSquaredError) {
|
---|
| 118 | if (treeLength == previousTreeLength)
|
---|
| 119 | sizeParetoFront.RemoveLast();
|
---|
| 120 | sizeParetoFront.AddLast(solution);
|
---|
| 121 | }
|
---|
| 122 | previousTreeLength = treeLength;
|
---|
| 123 | }
|
---|
| 124 |
|
---|
| 125 | qualityToTreeSize.Rows.Clear();
|
---|
| 126 | var trainingRow = new ScatterPlotDataRow("Training NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TrainingNormalizedMeanSquaredError)));
|
---|
| 127 | trainingRow.VisualProperties.PointSize = 5;
|
---|
| 128 | var testRow = new ScatterPlotDataRow("Test NMSE", "", sizeParetoFront.Select(x => new Point2D<double>(x.Model.SymbolicExpressionTree.Length, x.TestNormalizedMeanSquaredError)));
|
---|
| 129 | testRow.VisualProperties.PointSize = 5;
|
---|
| 130 | qualityToTreeSize.Rows.Add(trainingRow);
|
---|
| 131 | qualityToTreeSize.Rows.Add(testRow);
|
---|
| 132 |
|
---|
[11883] | 133 | double trainingArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TrainingNormalizedMeanSquaredError).Average();
|
---|
| 134 | double testArea = sizeParetoFront.Select(s => s.Model.SymbolicExpressionTree.Length * s.TestNormalizedMeanSquaredError).Average();
|
---|
[11310] | 135 |
|
---|
[11883] | 136 | ResultCollection paretoFrontResults;
|
---|
| 137 | if (!ResultCollection.TryGetValue("Pareto Front Results", out result)) {
|
---|
| 138 | paretoFrontResults = new ResultCollection();
|
---|
| 139 | ResultCollection.Add(new Result("Pareto Front Results", paretoFrontResults));
|
---|
| 140 | } else paretoFrontResults = (ResultCollection)result.Value;
|
---|
[11310] | 141 |
|
---|
[11883] | 142 | DoubleValue trainingAreaResult, testAreaResult, areaDifferenceResult, avgTrainingNMSE, avgTestNMSE;
|
---|
| 143 | if (!paretoFrontResults.TryGetValue("Non Dominated Area (training)", out result)) {
|
---|
| 144 | trainingAreaResult = new DoubleValue();
|
---|
| 145 | paretoFrontResults.Add(new Result("Non Dominated Area (training)", trainingAreaResult));
|
---|
| 146 | } else trainingAreaResult = (DoubleValue)result.Value;
|
---|
| 147 | if (!paretoFrontResults.TryGetValue("Non Dominated Area (test)", out result)) {
|
---|
| 148 | testAreaResult = new DoubleValue();
|
---|
| 149 | paretoFrontResults.Add(new Result("Non Dominated Area (test)", testAreaResult));
|
---|
| 150 | } else testAreaResult = (DoubleValue)result.Value;
|
---|
| 151 | if (!paretoFrontResults.TryGetValue("Non Dominated Area Difference", out result)) {
|
---|
| 152 | areaDifferenceResult = new DoubleValue();
|
---|
| 153 | paretoFrontResults.Add(new Result("Non Dominated Area Difference", areaDifferenceResult));
|
---|
| 154 | } else areaDifferenceResult = (DoubleValue)result.Value;
|
---|
| 155 | if (!paretoFrontResults.TryGetValue("Average Training NMSE", out result)) {
|
---|
| 156 | avgTrainingNMSE = new DoubleValue();
|
---|
| 157 | paretoFrontResults.Add(new Result("Average Training NMSE", avgTrainingNMSE));
|
---|
| 158 | } else avgTrainingNMSE = (DoubleValue)result.Value;
|
---|
| 159 | if (!paretoFrontResults.TryGetValue("Average Test NMSE", out result)) {
|
---|
| 160 | avgTestNMSE = new DoubleValue();
|
---|
| 161 | paretoFrontResults.Add(new Result("Average Test NMSE", avgTestNMSE));
|
---|
| 162 | } else avgTestNMSE = (DoubleValue)result.Value;
|
---|
[11310] | 163 |
|
---|
[11883] | 164 | trainingAreaResult.Value = trainingArea;
|
---|
| 165 | testAreaResult.Value = testArea;
|
---|
| 166 | areaDifferenceResult.Value = trainingArea - testArea;
|
---|
| 167 | avgTrainingNMSE.Value = sizeParetoFront.Select(s => s.TrainingNormalizedMeanSquaredError).Average();
|
---|
| 168 | avgTestNMSE.Value = sizeParetoFront.Select(s => s.TestNormalizedMeanSquaredError).Average();
|
---|
[11310] | 169 |
|
---|
| 170 | return operation;
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[5557] | 173 | }
|
---|
| 174 | }
|
---|