Changeset 17450 for trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective
- Timestamp:
- 02/25/20 15:56:36 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/MultiObjective/SymbolicClassificationMultiObjectiveTrainingBestSolutionAnalyzer.cs
r17180 r17450 20 20 #endregion 21 21 22 using System.Collections.Generic; 23 using System.Linq; 24 using HEAL.Attic; 25 using HeuristicLab.Analysis; 22 26 using HeuristicLab.Common; 23 27 using HeuristicLab.Core; 28 using HeuristicLab.Data; 24 29 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 30 using HeuristicLab.Optimization; 25 31 using HeuristicLab.Parameters; 26 using HEAL.Attic;27 32 28 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 38 43 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicDataAnalysisTreeInterpreter"; 39 44 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"; 40 48 41 49 #region parameter properties … … 55 63 get { return (IValueLookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 56 64 } 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 } 57 78 #endregion 58 79 … … 66 87 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The symbolic data analysis tree interpreter for the symbolic expression tree.")); 67 88 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 68 93 } 69 94 public override IDeepCloneable Clone(Cloner cloner) { … … 87 112 return model.CreateClassificationSolution((IClassificationProblemData)ProblemDataParameter.ActualValue.Clone()); 88 113 } 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 } 89 177 } 90 178 }
Note: See TracChangeset
for help on using the changeset viewer.