Changeset 11145
- Timestamp:
- 07/08/14 19:29:00 (10 years ago)
- Location:
- stable
- Files:
-
- 12 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 10368,10375,10378,10414,10417-10418,10428,10469-10470,11013,11025-11027
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic merged: 10368,10375,10378,10414,10417,10428,10469-10470,11013,11025-11027
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification merged: 10368,10375,10378,10418,10469,11025-11026
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification-3.4.csproj
r9288 r11145 120 120 <Compile Include="ModelCreators\NormalDistributedThresholdsModelCreator.cs" /> 121 121 <Compile Include="MultiObjective\SymbolicClassificationMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 122 <Compile Include="SymbolicClassificationPruningAnalyzer.cs" /> 122 123 <Compile Include="SymbolicClassificationSolutionImpactValuesCalculator.cs" /> 123 124 <Compile Include="SymbolicNearestNeighbourClassificationModel.cs" /> … … 149 150 <SubType>Code</SubType> 150 151 </Compile> 152 <Compile Include="SymbolicClassificationPruningOperator.cs" /> 151 153 <None Include="HeuristicLab.snk" /> 152 154 <None Include="Plugin.cs.frame" /> -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningAnalyzer.cs
r10368 r11145 1 using System; 1 #region License Information 2 /* HeuristicLab 3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 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 2 22 using HeuristicLab.Common; 3 23 using HeuristicLab.Core; 4 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;5 24 using HeuristicLab.Parameters; 6 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 10 29 [StorableClass] 11 30 public sealed class SymbolicClassificationPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer { 12 private const string ModelCreatorParameterName = "ModelCreator"; 13 #region parameter properties 14 public ILookupParameter<ISymbolicClassificationModelCreator> ModelCreatorParameter { 15 get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 16 } 17 #endregion 18 #region properties 19 private ISymbolicClassificationModelCreator ModelCreator { 20 get { return ModelCreatorParameter.ActualValue; } 21 set { ModelCreatorParameter.ActualValue = value; } 22 } 23 #endregion 24 25 protected SymbolicClassificationPruningAnalyzer(SymbolicClassificationPruningAnalyzer original, Cloner cloner) 31 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator"; 32 private const string PruningOperatorParameterName = "PruningOperator"; 33 private SymbolicClassificationPruningAnalyzer(SymbolicClassificationPruningAnalyzer original, Cloner cloner) 26 34 : base(original, cloner) { 27 35 } … … 30 38 } 31 39 40 [StorableConstructor] 41 private SymbolicClassificationPruningAnalyzer(bool deserializing) : base(deserializing) { } 42 32 43 public SymbolicClassificationPruningAnalyzer() { 33 // pruning parameters 34 Parameters.Add(new LookupParameter<ISymbolicClassificationModelCreator>(ModelCreatorParameterName)); 35 impactValuesCalculator = new SymbolicClassificationSolutionImpactValuesCalculator(); 36 } 37 38 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, 39 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = Double.MinValue, 40 double upperEstimationLimit = Double.MaxValue) { 41 var model = ModelCreator.CreateSymbolicClassificationModel(tree, Interpreter, lowerEstimationLimit, upperEstimationLimit); 42 model.RecalculateModelParameters((IClassificationProblemData)ProblemData, ProblemData.TrainingIndices); 43 return model; 44 Parameters.Add(new ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator", new SymbolicClassificationSolutionImpactValuesCalculator())); 45 Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicClassificationPruningOperator())); 44 46 } 45 47 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationPruningOperator.cs
r10470 r11145 1 using System.Linq; 1 #region License Information 2 3 /* HeuristicLab 4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #endregion 23 24 using System.Linq; 2 25 using HeuristicLab.Common; 3 26 using HeuristicLab.Core; 4 using HeuristicLab.Data;5 27 using HeuristicLab.Parameters; 6 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 12 34 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator"; 13 35 private const string ModelCreatorParameterName = "ModelCreator"; 14 private const string ApplyLinearScalingParmameterName = "ApplyLinearScaling";15 36 16 37 #region parameter properties … … 18 39 get { return (ILookupParameter<ISymbolicClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 19 40 } 20 21 public ILookupParameter<BoolValue> ApplyLinearScalingParameter {22 get { return (ILookupParameter<BoolValue>)Parameters[ApplyLinearScalingParmameterName]; }23 }24 #endregion25 #region properties26 private ISymbolicClassificationModelCreator ModelCreator { get { return ModelCreatorParameter.ActualValue; } }27 private BoolValue ApplyLinearScaling { get { return ApplyLinearScalingParameter.ActualValue; } }28 41 #endregion 29 42 … … 31 44 : base(original, cloner) { 32 45 } 46 33 47 public override IDeepCloneable Clone(Cloner cloner) { 34 48 return new SymbolicClassificationPruningOperator(this, cloner); … … 44 58 45 59 protected override ISymbolicDataAnalysisModel CreateModel() { 46 var model = ModelCreator.CreateSymbolicClassificationModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper); 47 var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 60 var model = ModelCreatorParameter.ActualValue.CreateSymbolicClassificationModel(SymbolicExpressionTree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper); 48 61 var problemData = (IClassificationProblemData)ProblemData; 62 var rows = problemData.TrainingIndices; 49 63 model.RecalculateModelParameters(problemData, rows); 50 64 return model; … … 54 68 var classificationModel = (IClassificationModel)model; 55 69 var classificationProblemData = (IClassificationProblemData)ProblemData; 56 var trainingIndices = ProblemData.TrainingIndices.ToList();70 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 57 71 var estimatedValues = classificationModel.GetEstimatedClassValues(ProblemData.Dataset, trainingIndices); 58 72 var targetValues = ProblemData.Dataset.GetDoubleValues(classificationProblemData.TargetVariable, trainingIndices); 59 73 OnlineCalculatorError errorState; 60 var quality = Online PearsonsRSquaredCalculator.Calculate(targetValues, estimatedValues, out errorState);74 var quality = OnlineAccuracyCalculator.Calculate(targetValues, estimatedValues, out errorState); 61 75 if (errorState != OnlineCalculatorError.None) return double.NaN; 62 76 return quality; -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SymbolicClassificationSolutionImpactValuesCalculator.cs
r10281 r11145 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 28 26 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 30 [StorableClass] 31 [Item("SymbolicClassificationSolutionImpactValuesCalculator", "Calculate symbolic expression tree node impact values for classification problems.")] 27 32 public class SymbolicClassificationSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 33 public SymbolicClassificationSolutionImpactValuesCalculator() { } 34 protected SymbolicClassificationSolutionImpactValuesCalculator(SymbolicClassificationSolutionImpactValuesCalculator original, Cloner cloner) 35 : base(original, cloner) { } 36 public override IDeepCloneable Clone(Cloner cloner) { 37 return new SymbolicClassificationSolutionImpactValuesCalculator(this, cloner); 38 } 39 [StorableConstructor] 40 protected SymbolicClassificationSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 41 28 42 public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 29 43 var classificationModel = (ISymbolicClassificationModel)model; … … 34 48 35 49 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) { 50 double impactValue, replacementValue; 51 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality); 52 return impactValue; 53 } 54 55 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 56 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 57 double originalQuality = Double.NaN) { 36 58 var classificationModel = (ISymbolicClassificationModel)model; 37 59 var classificationProblemData = (IClassificationProblemData)problemData; … … 47 69 } 48 70 49 varreplacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows);71 replacementValue = CalculateReplacementValue(classificationModel, node, classificationProblemData, rows); 50 72 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue }; 51 73 … … 63 85 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 64 86 65 returnoriginalQuality - newQuality;87 impactValue = originalQuality - newQuality; 66 88 } 67 68 89 } 69 90 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression merged: 10368,10375,10378,10469,11025-11026
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression-3.4.csproj
r10907 r11145 117 117 </ItemGroup> 118 118 <ItemGroup> 119 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" />120 119 <Compile Include="Plugin.cs" /> 121 120 <Compile Include="SingleObjective\ConstantOptimizationAnalyzer.cs" /> 122 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 123 <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" /> 121 <Compile Include="SingleObjective\SymbolicRegressionSolutionsAnalyzer.cs" /> 122 <Compile Include="SymbolicRegressionPruningAnalyzer.cs" /> 123 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveProblem.cs" /> 124 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs" /> 125 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 126 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs" /> 127 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> 128 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs" /> 124 129 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionLogResidualEvaluator.cs" /> 125 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 126 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> 130 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionMeanRelativeErrorEvaluator.cs" /> 127 131 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMaxAbsoluteErrorEvaluator.cs" /> 128 132 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMeanAbsoluteErrorEvaluator.cs" /> 129 133 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionConstantOptimizationEvaluator.cs" /> 130 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveOverfittingAnalyzer.cs" /> 134 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveEvaluator.cs" /> 135 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" /> 136 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" /> 131 137 <Compile Include="SymbolicRegressionModel.cs" /> 132 138 <Compile Include="Interfaces\ISymbolicRegressionModel.cs" /> … … 137 143 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveProblem.cs" /> 138 144 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveTrainingBestSolutionAnalyzer.cs" /> 139 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveProblem.cs" />140 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveValidationBestSolutionAnalyzer.cs" />141 <Compile Include="SingleObjective\SymbolicRegressionSingleObjectiveTrainingBestSolutionAnalyzer.cs" />142 145 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveEvaluator.cs" /> 146 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveValidationBestSolutionAnalyzer.cs" /> 143 147 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectiveMeanSquaredErrorTreeSizeEvaluator.cs" /> 144 148 <Compile Include="MultiObjective\SymbolicRegressionMultiObjectivePearsonRSquaredTreeSizeEvaluator.cs" /> 145 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveEvaluator.cs" /> 146 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectiveMeanSquaredErrorEvaluator.cs" /> 147 <Compile Include="SingleObjective\Evaluators\SymbolicRegressionSingleObjectivePearsonRSquaredEvaluator.cs" /> 149 <Compile Include="SymbolicRegressionPruningOperator.cs" /> 148 150 <Compile Include="SymbolicRegressionSolution.cs" /> 149 151 <Compile Include="SymbolicRegressionSolutionImpactValuesCalculator.cs" /> -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningAnalyzer.cs
r10368 r11145 1 using System; 1 #region License Information 2 3 /* HeuristicLab 4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #endregion 23 2 24 using HeuristicLab.Common; 3 25 using HeuristicLab.Core; 4 using HeuristicLab. Encodings.SymbolicExpressionTreeEncoding;26 using HeuristicLab.Parameters; 5 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 6 28 … … 9 31 [StorableClass] 10 32 public sealed class SymbolicRegressionPruningAnalyzer : SymbolicDataAnalysisSingleObjectivePruningAnalyzer { 11 protected SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner) 33 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator"; 34 private const string PruningOperatorParameterName = "PruningOperator"; 35 private SymbolicRegressionPruningAnalyzer(SymbolicRegressionPruningAnalyzer original, Cloner cloner) 12 36 : base(original, cloner) { 13 37 } … … 16 40 } 17 41 42 [StorableConstructor] 43 private SymbolicRegressionPruningAnalyzer(bool deserializing) : base(deserializing) { } 44 18 45 public SymbolicRegressionPruningAnalyzer() { 19 impactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator(); 20 } 21 22 protected override ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, 23 ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, double lowerEstimationLimit = Double.MinValue, 24 double upperEstimationLimit = Double.MaxValue) { 25 return new SymbolicRegressionModel(tree, interpreter, lowerEstimationLimit, upperEstimationLimit); 46 Parameters.Add(new ValueParameter<SymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator", new SymbolicRegressionSolutionImpactValuesCalculator())); 47 Parameters.Add(new ValueParameter<SymbolicDataAnalysisExpressionPruningOperator>(PruningOperatorParameterName, "The operator used to prune trees", new SymbolicRegressionPruningOperator())); 26 48 } 27 49 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionPruningOperator.cs
r10470 r11145 1 using System.Linq; 1 #region License Information 2 3 /* HeuristicLab 4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #endregion 23 24 using System.Linq; 2 25 using HeuristicLab.Common; 3 26 using HeuristicLab.Core; … … 10 33 public class SymbolicRegressionPruningOperator : SymbolicDataAnalysisExpressionPruningOperator { 11 34 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator"; 12 private const string ImpactValuesCalculatorParameterDescription = "The impact values calculator to be used for figuring out the node impacts.";13 14 private const string EvaluatorParameterName = "Evaluator";15 16 public ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator> EvaluatorParameter {17 get { return (ILookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>)Parameters[EvaluatorParameterName]; }18 }19 35 20 36 protected SymbolicRegressionPruningOperator(SymbolicRegressionPruningOperator original, Cloner cloner) … … 30 46 public SymbolicRegressionPruningOperator() { 31 47 var impactValuesCalculator = new SymbolicRegressionSolutionImpactValuesCalculator(); 32 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, ImpactValuesCalculatorParameterDescription, impactValuesCalculator)); 33 Parameters.Add(new LookupParameter<ISymbolicRegressionSingleObjectiveEvaluator>(EvaluatorParameterName)); 48 Parameters.Add(new ValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>(ImpactValuesCalculatorParameterName, "The impact values calculator to be used for figuring out the node impacts.", impactValuesCalculator)); 34 49 } 35 50 … … 41 56 var regressionModel = (IRegressionModel)model; 42 57 var regressionProblemData = (IRegressionProblemData)ProblemData; 43 var trainingIndices = ProblemData.TrainingIndices.ToList();58 var trainingIndices = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 44 59 var estimatedValues = regressionModel.GetEstimatedValues(ProblemData.Dataset, trainingIndices); // also bounds the values 45 60 var targetValues = ProblemData.Dataset.GetDoubleValues(regressionProblemData.TargetVariable, trainingIndices); -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SymbolicRegressionSolutionImpactValuesCalculator.cs
r9976 r11145 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 24 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 28 26 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 30 [StorableClass] 31 [Item("SymbolicRegressionSolutionImpactValuesCalculator", "Calculate symbolic expression tree node impact values for regression problems.")] 27 32 public class SymbolicRegressionSolutionImpactValuesCalculator : SymbolicDataAnalysisSolutionImpactValuesCalculator { 33 public SymbolicRegressionSolutionImpactValuesCalculator() { } 34 35 protected SymbolicRegressionSolutionImpactValuesCalculator(SymbolicRegressionSolutionImpactValuesCalculator original, Cloner cloner) 36 : base(original, cloner) { } 37 public override IDeepCloneable Clone(Cloner cloner) { 38 return new SymbolicRegressionSolutionImpactValuesCalculator(this, cloner); 39 } 40 41 [StorableConstructor] 42 protected SymbolicRegressionSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 28 43 public override double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows) { 29 44 var regressionModel = (ISymbolicRegressionModel)model; … … 34 49 35 50 public override double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN) { 51 double impactValue, replacementValue; 52 CalculateImpactAndReplacementValues(model, node, problemData, rows, out impactValue, out replacementValue, originalQuality); 53 return impactValue; 54 } 55 56 public override void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, 57 IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, 58 double originalQuality = Double.NaN) { 36 59 var regressionModel = (ISymbolicRegressionModel)model; 37 60 var regressionProblemData = (IRegressionProblemData)problemData; … … 47 70 } 48 71 49 varreplacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows);72 replacementValue = CalculateReplacementValue(regressionModel, node, regressionProblemData, rows); 50 73 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue }; 51 74 … … 63 86 if (errorState != OnlineCalculatorError.None) newQuality = 0.0; 64 87 65 returnoriginalQuality - newQuality;88 impactValue = originalQuality - newQuality; 66 89 } 67 68 90 } 69 91 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs
r10368 r11145 1 using System; 1 #region License Information 2 3 /* HeuristicLab 4 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 * 6 * This file is part of HeuristicLab. 7 * 8 * HeuristicLab is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 * 13 * HeuristicLab is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 #endregion 23 24 using System; 2 25 using System.Linq; 3 26 using HeuristicLab.Analysis; … … 5 28 using HeuristicLab.Core; 6 29 using HeuristicLab.Data; 7 using HeuristicLab. Encodings.SymbolicExpressionTreeEncoding;8 using HeuristicLab.Optimization ;30 using HeuristicLab.Operators; 31 using HeuristicLab.Optimization.Operators; 9 32 using HeuristicLab.Parameters; 10 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 14 37 [Item("SymbolicDataAnalysisSingleObjectivePruningAnalyzer", "An analyzer that prunes introns from trees in single objective symbolic data analysis problems.")] 15 38 public abstract class SymbolicDataAnalysisSingleObjectivePruningAnalyzer : SymbolicDataAnalysisSingleObjectiveAnalyzer { 39 #region parameter names 16 40 private const string ProblemDataParameterName = "ProblemData"; 17 private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter";18 19 41 private const string UpdateIntervalParameterName = "UpdateInverval"; 20 42 private const string UpdateCounterParameterName = "UpdateCounter"; 21 22 43 private const string PopulationSliceParameterName = "PopulationSlice"; 23 44 private const string PruningProbabilityParameterName = "PruningProbability"; 24 25 private const string NumberOfPrunedSubtreesParameterName = "PrunedSubtrees"; 26 private const string NumberOfPrunedTreesParameterName = "PrunedTrees"; 27 45 private const string TotalNumberOfPrunedSubtreesParameterName = "Number of pruned subtrees"; 46 private const string TotalNumberOfPrunedTreesParameterName = "Number of pruned trees"; 28 47 private const string RandomParameterName = "Random"; 29 private const string EstimationLimitsParameterName = "EstimationLimits";30 31 48 private const string PruneOnlyZeroImpactNodesParameterName = "PruneOnlyZeroImpactNodes"; 32 49 private const string NodeImpactThresholdParameterName = "ImpactThreshold"; 33 34 private bool reentry; 35 [Storable] 36 protected ISymbolicDataAnalysisSolutionImpactValuesCalculator impactValuesCalculator; 50 private const string PruningOperatorParameterName = "PruningOperator"; 51 private const string ResultsParameterName = "Results"; 52 private const string PopulationSizeParameterName = "PopulationSize"; 53 #endregion 54 55 #region private members 56 private DataReducer prunedSubtreesReducer; 57 private DataReducer prunedTreesReducer; 58 private DataTableValuesCollector valuesCollector; 59 private ResultsCollector resultsCollector; 60 #endregion 37 61 38 62 #region parameter properties 63 public IValueParameter<SymbolicDataAnalysisExpressionPruningOperator> PruningOperatorParameter { 64 get { return (IValueParameter<SymbolicDataAnalysisExpressionPruningOperator>)Parameters[PruningOperatorParameterName]; } 65 } 39 66 public IFixedValueParameter<BoolValue> PruneOnlyZeroImpactNodesParameter { 40 67 get { return (IFixedValueParameter<BoolValue>)Parameters[PruneOnlyZeroImpactNodesParameterName]; } … … 43 70 get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; } 44 71 } 45 public ILookupParameter<DoubleLimit> EstimationLimitsParameter {46 get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; }47 }48 72 public ILookupParameter<IRandom> RandomParameter { 49 73 get { return (ILookupParameter<IRandom>)Parameters[RandomParameterName]; } 50 74 } 51 private ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter { 52 get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; } 53 } 54 private ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter { 55 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; } 56 } 57 public IValueParameter<IntValue> UpdateIntervalParameter { 58 get { return (IValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 59 } 60 public IValueParameter<IntValue> UpdateCounterParameter { 61 get { return (IValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; } 62 } 63 public IValueParameter<DoubleRange> PopulationSliceParameter { 64 get { return (IValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; } 65 } 66 public IValueParameter<DoubleValue> PruningProbabilityParameter { 67 get { return (IValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; } 68 } 69 public IFixedValueParameter<DoubleValue> NumberOfPrunedSubtreesParameter { 70 get { return (IFixedValueParameter<DoubleValue>)Parameters[NumberOfPrunedSubtreesParameterName]; } 71 } 72 public IFixedValueParameter<DoubleValue> NumberOfPrunedTreesParameter { 73 get { return (IFixedValueParameter<DoubleValue>)Parameters[NumberOfPrunedTreesParameterName]; } 74 } 75 #endregion 75 public IFixedValueParameter<IntValue> UpdateIntervalParameter { 76 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; } 77 } 78 public IFixedValueParameter<IntValue> UpdateCounterParameter { 79 get { return (IFixedValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; } 80 } 81 public IFixedValueParameter<DoubleRange> PopulationSliceParameter { 82 get { return (IFixedValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; } 83 } 84 public IFixedValueParameter<DoubleValue> PruningProbabilityParameter { 85 get { return (IFixedValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; } 86 } 87 public ILookupParameter<IntValue> PopulationSizeParameter { 88 get { return (ILookupParameter<IntValue>)Parameters[PopulationSizeParameterName]; } 89 } 90 #endregion 91 76 92 #region properties 77 protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } 78 protected ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } } 79 protected IntValue UpdateInterval { get { return UpdateIntervalParameter.Value; } } 80 protected IntValue UpdateCounter { get { return UpdateCounterParameter.Value; } } 81 protected DoubleRange PopulationSlice { get { return PopulationSliceParameter.Value; } } 82 protected DoubleValue PruningProbability { get { return PruningProbabilityParameter.Value; } } 83 protected DoubleValue PrunedSubtrees { get { return NumberOfPrunedSubtreesParameter.Value; } } 84 protected DoubleValue PrunedTrees { get { return NumberOfPrunedTreesParameter.Value; } } 85 protected DoubleLimit EstimationLimits { get { return EstimationLimitsParameter.ActualValue; } } 86 protected IRandom Random { get { return RandomParameter.ActualValue; } } 87 protected DoubleValue NodeImpactThreshold { get { return NodeImpactThresholdParameter.Value; } } 88 protected BoolValue PruneOnlyZeroImpactNodes { get { return PruneOnlyZeroImpactNodesParameter.Value; } } 89 #endregion 93 protected SymbolicDataAnalysisExpressionPruningOperator PruningOperator { get { return PruningOperatorParameter.Value; } } 94 protected int UpdateInterval { get { return UpdateIntervalParameter.Value.Value; } } 95 96 protected int UpdateCounter { 97 get { return UpdateCounterParameter.Value.Value; } 98 set { UpdateCounterParameter.Value.Value = value; } 99 } 100 101 protected double PopulationSliceStart { 102 get { return PopulationSliceParameter.Value.Start; } 103 set { PopulationSliceParameter.Value.Start = value; } 104 } 105 106 protected double PopulationSliceEnd { 107 get { return PopulationSliceParameter.Value.End; } 108 set { PopulationSliceParameter.Value.End = value; } 109 } 110 111 protected double PruningProbability { 112 get { return PruningProbabilityParameter.Value.Value; } 113 set { PruningProbabilityParameter.Value.Value = value; } 114 } 115 116 protected bool PruneOnlyZeroImpactNodes { 117 get { return PruneOnlyZeroImpactNodesParameter.Value.Value; } 118 set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; } 119 } 120 protected double NodeImpactThreshold { 121 get { return NodeImpactThresholdParameter.Value.Value; } 122 set { NodeImpactThresholdParameter.Value.Value = value; } 123 } 124 #endregion 125 126 #region IStatefulItem members 127 public override void InitializeState() { 128 base.InitializeState(); 129 UpdateCounter = 0; 130 } 131 public override void ClearState() { 132 base.ClearState(); 133 UpdateCounter = 0; 134 } 135 #endregion 136 137 [StorableConstructor] 138 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(bool deserializing) : base(deserializing) { } 139 90 140 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer(SymbolicDataAnalysisSingleObjectivePruningAnalyzer original, Cloner cloner) 91 141 : base(original, cloner) { 92 impactValuesCalculator = original.impactValuesCalculator; 93 } 142 if (original.prunedSubtreesReducer != null) 143 this.prunedSubtreesReducer = (DataReducer)original.prunedSubtreesReducer.Clone(); 144 if (original.prunedTreesReducer != null) 145 this.prunedTreesReducer = (DataReducer)original.prunedTreesReducer.Clone(); 146 if (original.valuesCollector != null) 147 this.valuesCollector = (DataTableValuesCollector)original.valuesCollector.Clone(); 148 if (original.resultsCollector != null) 149 this.resultsCollector = (ResultsCollector)original.resultsCollector.Clone(); 150 } 151 152 [StorableHook(HookType.AfterDeserialization)] 153 private void AfterDeserialization() { 154 if (!Parameters.ContainsKey(PopulationSizeParameterName)) { 155 Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals.")); 156 } 157 if (Parameters.ContainsKey(UpdateCounterParameterName)) { 158 var fixedValueParameter = Parameters[UpdateCounterParameterName] as FixedValueParameter<IntValue>; 159 if (fixedValueParameter == null) { 160 var valueParameter = (ValueParameter<IntValue>)Parameters[UpdateCounterParameterName]; 161 Parameters.Remove(UpdateCounterParameterName); 162 Parameters.Add(new FixedValueParameter<IntValue>(UpdateCounterParameterName, valueParameter.Value)); 163 } 164 } 165 if (Parameters.ContainsKey(UpdateIntervalParameterName)) { 166 var fixedValueParameter = Parameters[UpdateIntervalParameterName] as FixedValueParameter<IntValue>; 167 if (fixedValueParameter == null) { 168 var valueParameter = (ValueParameter<IntValue>)Parameters[UpdateIntervalParameterName]; 169 Parameters.Remove(UpdateIntervalParameterName); 170 Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, valueParameter.Value)); 171 } 172 } 173 if (Parameters.ContainsKey(PopulationSliceParameterName)) { 174 var fixedValueParameter = Parameters[PopulationSliceParameterName] as FixedValueParameter<DoubleRange>; 175 if (fixedValueParameter == null) { 176 var valueParameter = (ValueParameter<DoubleRange>)Parameters[PopulationSliceParameterName]; 177 Parameters.Remove(PopulationSliceParameterName); 178 Parameters.Add(new FixedValueParameter<DoubleRange>(PopulationSliceParameterName, valueParameter.Value)); 179 } 180 } 181 if (Parameters.ContainsKey(PruningProbabilityParameterName)) { 182 var fixedValueParameter = Parameters[PruningProbabilityParameterName] as FixedValueParameter<DoubleValue>; 183 if (fixedValueParameter == null) { 184 var valueParameter = (ValueParameter<DoubleValue>)Parameters[PruningProbabilityParameterName]; 185 Parameters.Remove(PruningProbabilityParameterName); 186 Parameters.Add(new FixedValueParameter<DoubleValue>(PruningProbabilityParameterName, valueParameter.Value)); 187 } 188 } 189 } 190 94 191 protected SymbolicDataAnalysisSingleObjectivePruningAnalyzer() { 95 Parameters.Add(new ValueParameter<DoubleRange>(PopulationSliceParameterName, new DoubleRange(0.75, 1))); 96 Parameters.Add(new ValueParameter<DoubleValue>(PruningProbabilityParameterName, new DoubleValue(0.5))); 97 // analyzer parameters 98 Parameters.Add(new ValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 99 Parameters.Add(new ValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0))); 100 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName)); 101 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName)); 102 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName)); 103 104 Parameters.Add(new FixedValueParameter<DoubleValue>(NumberOfPrunedSubtreesParameterName, new DoubleValue(0))); 105 Parameters.Add(new FixedValueParameter<DoubleValue>(NumberOfPrunedTreesParameterName, new DoubleValue(0))); 106 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 107 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, new DoubleValue(0.0))); 108 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, new BoolValue(false))); 192 #region add parameters 193 Parameters.Add(new FixedValueParameter<DoubleRange>(PopulationSliceParameterName, "The slice of the population where pruning should be applied.", new DoubleRange(0.75, 1))); 194 Parameters.Add(new FixedValueParameter<DoubleValue>(PruningProbabilityParameterName, "The probability for pruning an individual.", new DoubleValue(0.5))); 195 Parameters.Add(new FixedValueParameter<IntValue>(UpdateIntervalParameterName, "The interval in which the tree length analysis should be applied.", new IntValue(1))); 196 Parameters.Add(new FixedValueParameter<IntValue>(UpdateCounterParameterName, "The value which counts how many times the operator was called", new IntValue(0))); 197 Parameters.Add(new LookupParameter<IRandom>(RandomParameterName, "The random number generator.")); 198 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName, "The problem data.")); 199 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "The impact threshold below which an individual should be pruned.", new DoubleValue(0.0))); 200 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Switch to determine of only zero impact individuals should be pruned.", new BoolValue(false))); 201 Parameters.Add(new LookupParameter<IntValue>(PopulationSizeParameterName, "The population of individuals.")); 202 #endregion 203 } 204 205 // 206 /// <summary> 207 /// Computes the closed interval bounding the portion of the population that is to be pruned. 208 /// </summary> 209 /// <returns>Returns an int range [start, end]</returns> 210 private IntRange GetSliceBounds() { 211 if (PopulationSliceStart < 0 || PopulationSliceEnd < 0) throw new ArgumentOutOfRangeException("The slice bounds cannot be negative."); 212 if (PopulationSliceStart > 1 || PopulationSliceEnd > 1) throw new ArgumentOutOfRangeException("The slice bounds should be expressed as unit percentages."); 213 var count = PopulationSizeParameter.ActualValue.Value; 214 var start = (int)Math.Round(PopulationSliceStart * count); 215 var end = (int)Math.Round(PopulationSliceEnd * count); 216 if (end > count) end = count; 217 218 if (start >= end) throw new ArgumentOutOfRangeException("Invalid PopulationSlice bounds."); 219 return new IntRange(start, end); 220 } 221 222 private IOperation CreatePruningOperation() { 223 var operations = new OperationCollection { Parallel = true }; 224 var range = GetSliceBounds(); 225 var qualities = Quality.Select(x => x.Value).ToArray(); 226 var indices = Enumerable.Range(0, qualities.Length).ToArray(); 227 Array.Sort(qualities, indices); 228 if (!Maximization.Value) Array.Reverse(indices); 229 230 var subscopes = ExecutionContext.Scope.SubScopes; 231 var random = RandomParameter.ActualValue; 232 233 var empty = new EmptyOperator(); 234 235 for (int i = 0; i < subscopes.Count; ++i) { 236 IOperator @operator; 237 if (range.Start <= i && i < range.End && random.NextDouble() <= PruningProbability) 238 @operator = PruningOperator; 239 else @operator = empty; 240 var index = indices[i]; 241 var subscope = subscopes[index]; 242 operations.Add(ExecutionContext.CreateChildOperation(@operator, subscope)); 243 } 244 return operations; 109 245 } 110 246 111 247 public override IOperation Apply() { 112 if (reentry) { 113 UpdateCounter.Value++; 114 115 if (UpdateCounter.Value != UpdateInterval.Value) return base.Apply(); 116 UpdateCounter.Value = 0; 117 118 var trees = SymbolicExpressionTreeParameter.ActualValue.ToList(); 119 var qualities = QualityParameter.ActualValue.ToList(); 120 121 var population = trees.Zip(qualities, (tree, quality) => new { Tree = tree, Quality = quality }).ToList(); 122 Func<double, double, int> compare = (a, b) => Maximization.Value ? a.CompareTo(b) : b.CompareTo(a); 123 population.Sort((a, b) => compare(a.Quality.Value, b.Quality.Value)); 124 125 var start = (int)Math.Round(PopulationSlice.Start * trees.Count); 126 var end = (int)Math.Round(PopulationSlice.End * trees.Count); 127 128 if (end == population.Count) end--; 129 130 if (start >= end || end >= population.Count) throw new Exception("Invalid PopulationSlice bounds."); 131 132 PrunedSubtrees.Value = 0; 133 PrunedTrees.Value = 0; 134 135 reentry = false; 136 137 var operations = new OperationCollection { Parallel = true }; 138 foreach (var p in population.Skip(start).Take(end)) { 139 if (Random.NextDouble() > PruningProbability.Value) continue; 140 var op = new SymbolicDataAnalysisExpressionPruningOperator { 141 Model = CreateModel(p.Tree, Interpreter, EstimationLimits.Lower, EstimationLimits.Upper), 142 ImpactsCalculator = impactValuesCalculator, 143 ProblemData = ProblemData, 144 Random = Random, 145 PruneOnlyZeroImpactNodes = PruneOnlyZeroImpactNodes.Value, 146 NodeImpactThreshold = NodeImpactThreshold.Value 147 }; 148 operations.Add(ExecutionContext.CreateChildOperation(op, ExecutionContext.Scope)); 149 } 150 return new OperationCollection { operations, ExecutionContext.CreateOperation(this) }; 151 } 152 153 DataTable table; 154 155 if (ResultCollection.ContainsKey("Population Pruning")) { 156 table = (DataTable)ResultCollection["Population Pruning"].Value; 157 } else { 158 table = new DataTable("Population Pruning"); 159 table.Rows.Add(new DataRow("Pruned Trees") { VisualProperties = { StartIndexZero = true } }); 160 table.Rows.Add(new DataRow("Pruned Subtrees") { VisualProperties = { StartIndexZero = true } }); 161 ResultCollection.Add(new Result("Population Pruning", table)); 162 } 163 164 table.Rows["Pruned Trees"].Values.Add(PrunedTrees.Value); 165 table.Rows["Pruned Subtrees"].Values.Add(PrunedSubtrees.Value); 166 167 reentry = true; 168 169 return base.Apply(); 170 } 171 172 protected abstract ISymbolicDataAnalysisModel CreateModel(ISymbolicExpressionTree tree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter, 173 double lowerEstimationLimit = double.MinValue, double upperEstimationLimit = double.MaxValue); 248 UpdateCounter++; 249 if (UpdateCounter != UpdateInterval) return base.Apply(); 250 UpdateCounter = 0; 251 252 if (prunedSubtreesReducer == null || prunedTreesReducer == null || valuesCollector == null || resultsCollector == null) { InitializeOperators(); } 253 254 var prune = CreatePruningOperation(); 255 var reducePrunedSubtrees = ExecutionContext.CreateChildOperation(prunedSubtreesReducer); 256 var reducePrunedTrees = ExecutionContext.CreateChildOperation(prunedTreesReducer); 257 var collectValues = ExecutionContext.CreateChildOperation(valuesCollector); 258 var collectResults = ExecutionContext.CreateChildOperation(resultsCollector); 259 260 return new OperationCollection { prune, reducePrunedSubtrees, reducePrunedTrees, collectValues, collectResults, base.Apply() }; 261 } 262 263 private void InitializeOperators() { 264 prunedSubtreesReducer = new DataReducer(); 265 prunedSubtreesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedSubtreesParameter.ActualName; 266 prunedSubtreesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); // sum all the pruned subtrees parameter values 267 prunedSubtreesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); // asign the sum to the target parameter 268 prunedSubtreesReducer.TargetParameter.ActualName = TotalNumberOfPrunedSubtreesParameterName; 269 270 prunedTreesReducer = new DataReducer(); 271 prunedTreesReducer.ParameterToReduce.ActualName = PruningOperator.PrunedTreesParameter.ActualName; 272 prunedTreesReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); 273 prunedTreesReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 274 prunedTreesReducer.TargetParameter.ActualName = TotalNumberOfPrunedTreesParameterName; 275 276 valuesCollector = new DataTableValuesCollector(); 277 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedSubtreesParameterName)); 278 valuesCollector.CollectedValues.Add(new LookupParameter<IntValue>(TotalNumberOfPrunedTreesParameterName)); 279 valuesCollector.DataTableParameter.ActualName = "Population pruning"; 280 281 resultsCollector = new ResultsCollector(); 282 resultsCollector.CollectedValues.Add(new LookupParameter<DataTable>("Population pruning")); 283 resultsCollector.ResultsParameter.ActualName = ResultsParameterName; 284 } 174 285 } 175 286 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r10910 r11145 112 112 </ItemGroup> 113 113 <ItemGroup> 114 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 114 115 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> 115 116 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveTrainingParetoBestSolutionAnalyzer.cs" /> … … 125 126 <SubType>Code</SubType> 126 127 </Compile> 128 <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" /> 127 129 <Compile Include="Analyzers\SymbolicDataAnalysisVariableFrequencyAnalyzer.cs" /> 128 130 <Compile Include="Analyzers\SymbolicDataAnalysisAlleleFrequencyAnalyzer.cs" /> -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interfaces/ISymbolicDataAnalysisImpactValuesCalculator.cs
r8946 r11145 1 1 using System.Collections.Generic; 2 using HeuristicLab.Core; 2 3 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 3 4 4 5 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 5 public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator {6 public interface ISymbolicDataAnalysisSolutionImpactValuesCalculator : IItem { 6 7 double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 7 8 double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN); 9 void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, 10 IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality = double.NaN); 8 11 } 9 12 } -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Plugin.cs.frame
r10032 r11145 38 38 [PluginDependency("HeuristicLab.Operators", "3.3")] 39 39 [PluginDependency("HeuristicLab.Optimization", "3.3")] 40 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 40 41 [PluginDependency("HeuristicLab.Parameters", "3.3")] 41 42 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisExpressionPruningOperator.cs
r10368 r11145 34 34 [StorableClass] 35 35 [Item("SymbolicExpressionTreePruningOperator", "An operator that replaces introns with constant values in a symbolic expression tree.")] 36 public class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator { 37 private const string NumberOfPrunedSubtreesParameterName = "PrunedSubtrees"; 38 private const string NumberOfPrunedTreesParameterName = "PrunedTrees"; 36 public abstract class SymbolicDataAnalysisExpressionPruningOperator : SingleSuccessorOperator { 37 #region parameter names 38 private const string ProblemDataParameterName = "ProblemData"; 39 private const string SymbolicDataAnalysisModelParameterName = "SymbolicDataAnalysisModel"; 40 private const string ImpactValuesCalculatorParameterName = "ImpactValuesCalculator"; 41 private const string PrunedSubtreesParameterName = "PrunedSubtrees"; 42 private const string PrunedTreesParameterName = "PrunedTrees"; 43 private const string FitnessCalculationPartitionParameterName = "FitnessCalculationPartition"; 44 private const string NodeImpactThresholdParameterName = "ImpactThreshold"; 45 private const string PruneOnlyZeroImpactNodesParameterName = "PruneOnlyZeroImpactNodes"; 46 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; // the tree to be pruned 47 private const string QualityParameterName = "Quality"; // the quality 48 private const string EstimationLimitsParameterName = "EstimationLimits"; 49 private const string InterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 50 #endregion 51 39 52 #region parameter properties 40 public ILookupParameter< DoubleValue> NumberOfPrunedSubtreesParameter {41 get { return (ILookupParameter< DoubleValue>)Parameters[NumberOfPrunedSubtreesParameterName]; }53 public ILookupParameter<ISymbolicExpressionTree> SymbolicExpressionTreeParameter { 54 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[SymbolicExpressionTreeParameterName]; } 42 55 } 43 public ILookupParameter<DoubleValue> NumberOfPrunedTreesParameter { 44 get { return (ILookupParameter<DoubleValue>)Parameters[NumberOfPrunedTreesParameterName]; } 56 public ILookupParameter<DoubleValue> QualityParameter { 57 get { return (ILookupParameter<DoubleValue>)Parameters[QualityParameterName]; } 58 } 59 public ILookupParameter<IDataAnalysisProblemData> ProblemDataParameter { 60 get { return (ILookupParameter<IDataAnalysisProblemData>)Parameters[ProblemDataParameterName]; } 61 } 62 public IValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator> ImpactValuesCalculatorParameter { 63 get { return (IValueParameter<ISymbolicDataAnalysisSolutionImpactValuesCalculator>)Parameters[ImpactValuesCalculatorParameterName]; } 64 } 65 public ILookupParameter<IntRange> FitnessCalculationPartitionParameter { 66 get { return (ILookupParameter<IntRange>)Parameters[FitnessCalculationPartitionParameterName]; } 67 } 68 public ILookupParameter<IntValue> PrunedSubtreesParameter { 69 get { return (ILookupParameter<IntValue>)Parameters[PrunedSubtreesParameterName]; } 70 } 71 public ILookupParameter<IntValue> PrunedTreesParameter { 72 get { return (ILookupParameter<IntValue>)Parameters[PrunedTreesParameterName]; } 73 } 74 public IFixedValueParameter<DoubleValue> NodeImpactThresholdParameter { 75 get { return (IFixedValueParameter<DoubleValue>)Parameters[NodeImpactThresholdParameterName]; } 76 } 77 public IFixedValueParameter<BoolValue> PruneOnlyZeroImpactNodesParameter { 78 get { return (IFixedValueParameter<BoolValue>)Parameters[PruneOnlyZeroImpactNodesParameterName]; } 79 } 80 public ILookupParameter<DoubleLimit> EstimationLimitsParameter { 81 get { return (ILookupParameter<DoubleLimit>)Parameters[EstimationLimitsParameterName]; } 82 } 83 public ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter> InterpreterParameter { 84 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[InterpreterParameterName]; } 45 85 } 46 86 #endregion 87 47 88 #region properties 48 private DoubleValue PrunedSubtrees { get { return NumberOfPrunedSubtreesParameter.ActualValue; } } 49 private DoubleValue PrunedTrees { get { return NumberOfPrunedTreesParameter.ActualValue; } } 89 protected IDataAnalysisProblemData ProblemData { get { return ProblemDataParameter.ActualValue; } } 90 protected ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactValuesCalculator { get { return ImpactValuesCalculatorParameter.Value; } } 91 protected IntRange FitnessCalculationPartition { get { return FitnessCalculationPartitionParameter.ActualValue; } } 92 protected bool PruneOnlyZeroImpactNodes { 93 get { return PruneOnlyZeroImpactNodesParameter.Value.Value; } 94 set { PruneOnlyZeroImpactNodesParameter.Value.Value = value; } 95 } 96 protected double NodeImpactThreshold { 97 get { return NodeImpactThresholdParameter.Value.Value; } 98 set { NodeImpactThresholdParameter.Value.Value = value; } 99 } 100 protected ISymbolicExpressionTree SymbolicExpressionTree { get { return SymbolicExpressionTreeParameter.ActualValue; } } 101 protected DoubleValue Quality { get { return QualityParameter.ActualValue; } } 102 protected DoubleLimit EstimationLimits { get { return EstimationLimitsParameter.ActualValue; } } 103 protected ISymbolicDataAnalysisExpressionTreeInterpreter Interpreter { get { return InterpreterParameter.ActualValue; } } 50 104 #endregion 51 public override IDeepCloneable Clone(Cloner cloner) { 52 return new SymbolicDataAnalysisExpressionPruningOperator(this, cloner); 53 } 54 private SymbolicDataAnalysisExpressionPruningOperator(SymbolicDataAnalysisExpressionPruningOperator original, Cloner cloner) 55 : base(original, cloner) { 105 106 [StorableConstructor] 107 protected SymbolicDataAnalysisExpressionPruningOperator(bool deserializing) : base(deserializing) { } 108 protected SymbolicDataAnalysisExpressionPruningOperator(SymbolicDataAnalysisExpressionPruningOperator original, Cloner cloner) 109 : base(original, cloner) { } 110 111 protected SymbolicDataAnalysisExpressionPruningOperator() { 112 #region add parameters 113 Parameters.Add(new LookupParameter<IDataAnalysisProblemData>(ProblemDataParameterName)); 114 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisModel>(SymbolicDataAnalysisModelParameterName)); 115 Parameters.Add(new LookupParameter<IntRange>(FitnessCalculationPartitionParameterName)); 116 Parameters.Add(new LookupParameter<IntValue>(PrunedSubtreesParameterName, "A counter of how many subtrees were replaced.")); 117 Parameters.Add(new LookupParameter<IntValue>(PrunedTreesParameterName, "A counter of how many trees were pruned.")); 118 Parameters.Add(new FixedValueParameter<BoolValue>(PruneOnlyZeroImpactNodesParameterName, "Specify whether or not only zero impact nodes should be pruned.")); 119 Parameters.Add(new FixedValueParameter<DoubleValue>(NodeImpactThresholdParameterName, "Specifies an impact value threshold below which nodes should be pruned.")); 120 Parameters.Add(new LookupParameter<DoubleLimit>(EstimationLimitsParameterName)); 121 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(InterpreterParameterName)); 122 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName)); 123 Parameters.Add(new LookupParameter<DoubleValue>(QualityParameterName)); 124 #endregion 56 125 } 57 126 58 public SymbolicDataAnalysisExpressionPruningOperator() { 59 Parameters.Add(new LookupParameter<DoubleValue>(NumberOfPrunedSubtreesParameterName)); 60 Parameters.Add(new LookupParameter<DoubleValue>(NumberOfPrunedTreesParameterName)); 61 } 127 protected abstract ISymbolicDataAnalysisModel CreateModel(); 62 128 63 public ISymbolicDataAnalysisModel Model { get; set; } 64 public IDataAnalysisProblemData ProblemData { get; set; } 65 public ISymbolicDataAnalysisSolutionImpactValuesCalculator ImpactsCalculator { get; set; } 66 public IRandom Random { get; set; } 67 68 public bool PruneOnlyZeroImpactNodes { get; set; } 69 public double NodeImpactThreshold { get; set; } 129 protected abstract double Evaluate(IDataAnalysisModel model); 70 130 71 131 public override IOperation Apply() { 72 int prunedSubtrees = 0; 132 var model = CreateModel(); 133 var nodes = SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList(); 134 var rows = Enumerable.Range(FitnessCalculationPartition.Start, FitnessCalculationPartition.Size); 135 var prunedSubtrees = 0; 136 var prunedTrees = 0; 73 137 74 var nodes = Model.SymbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0).IterateNodesPrefix().ToList();138 double quality = Evaluate(model); 75 139 76 for (int j = 0; j < nodes.Count; ++j) {77 var node = nodes[ j];140 for (int i = 0; i < nodes.Count; ++i) { 141 var node = nodes[i]; 78 142 if (node is ConstantTreeNode) continue; 79 143 80 var impact = ImpactsCalculator.CalculateImpactValue(Model, node, ProblemData, ProblemData.TrainingIndices); 144 double impactValue, replacementValue; 145 ImpactValuesCalculator.CalculateImpactAndReplacementValues(model, node, ProblemData, rows, out impactValue, out replacementValue, quality); 81 146 82 147 if (PruneOnlyZeroImpactNodes) { 83 if (!impact .IsAlmost(0.0)) continue;84 } else {85 if (NodeImpactThreshold < impact)continue;148 if (!impactValue.IsAlmost(0.0)) continue; 149 } else if (NodeImpactThreshold < impactValue) { 150 continue; 86 151 } 87 152 88 var replacementValue = ImpactsCalculator.CalculateReplacementValue(Model, node, ProblemData, ProblemData.TrainingIndices); 89 var constantNode = new ConstantTreeNode(new Constant()) { Value = replacementValue }; 153 var constantNode = (ConstantTreeNode)node.Grammar.GetSymbol("Constant").CreateTreeNode(); 154 constantNode.Value = replacementValue; 155 90 156 ReplaceWithConstant(node, constantNode); 91 j += node.GetLength() - 1; // skip subtrees under the node that was folded 157 i += node.GetLength() - 1; // skip subtrees under the node that was folded 158 159 quality -= impactValue; 92 160 93 161 prunedSubtrees++; 94 162 } 95 163 96 if (prunedSubtrees > 0) {97 lock (PrunedSubtrees) { PrunedSubtrees.Value += prunedSubtrees; }98 lock (PrunedTrees) { PrunedTrees.Value += 1; }99 } 164 if (prunedSubtrees > 0) prunedTrees = 1; 165 PrunedSubtreesParameter.ActualValue = new IntValue(prunedSubtrees); 166 PrunedTreesParameter.ActualValue = new IntValue(prunedTrees); 167 100 168 return base.Apply(); 101 169 } 170 102 171 private static void ReplaceWithConstant(ISymbolicExpressionTreeNode original, ISymbolicExpressionTreeNode replacement) { 103 172 var parent = original.Parent; -
stable/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisSolutionImpactValuesCalculator.cs
r9456 r11145 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Common; 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 27 26 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 27 public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : ISymbolicDataAnalysisSolutionImpactValuesCalculator { 29 [StorableClass] 30 [Item("SymbolicDataAnalysisSolutionImpactValuesCalculator", "Calculates the impact values and replacements values for symbolic expression tree nodes.")] 31 public abstract class SymbolicDataAnalysisSolutionImpactValuesCalculator : Item, ISymbolicDataAnalysisSolutionImpactValuesCalculator { 32 protected SymbolicDataAnalysisSolutionImpactValuesCalculator() { } 33 34 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(SymbolicDataAnalysisSolutionImpactValuesCalculator original, Cloner cloner) 35 : base(original, cloner) { } 36 [StorableConstructor] 37 protected SymbolicDataAnalysisSolutionImpactValuesCalculator(bool deserializing) : base(deserializing) { } 28 38 public abstract double CalculateReplacementValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows); 29 39 public abstract double CalculateImpactValue(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, double originalQuality = double.NaN); 40 public abstract void CalculateImpactAndReplacementValues(ISymbolicDataAnalysisModel model, ISymbolicExpressionTreeNode node, IDataAnalysisProblemData problemData, IEnumerable<int> rows, out double impactValue, out double replacementValue, double originalQuality = double.NaN); 30 41 31 42 protected static double CalculateReplacementValue(ISymbolicExpressionTreeNode node, ISymbolicExpressionTree sourceTree, ISymbolicDataAnalysisExpressionTreeInterpreter interpreter,
Note: See TracChangeset
for help on using the changeset viewer.