Changeset 12075 for branches/SymbolicExpressionTreeDiversityAnalyzers
- Timestamp:
- 02/25/15 17:53:25 (10 years ago)
- Location:
- branches/SymbolicExpressionTreeDiversityAnalyzers
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic (added) merged: 12069
- Property svn:mergeinfo changed
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationPhenotypicDiversityAnalyzer.cs
r12064 r12075 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 34 [Item("SymbolicClassificationPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 33 35 [StorableClass] 34 public class SymbolicClassificationPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {36 public class SymbolicClassificationPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer { 35 37 #region parameter names 36 38 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; … … 74 76 #endregion 75 77 76 public SymbolicClassificationPhenotypicDiversityAnalyzer( ) {77 SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator() { SolutionVariableName = "SymbolicExpressionTree", QualityVariableName = "Quality" };78 public SymbolicClassificationPhenotypicDiversityAnalyzer(IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators) 79 : base(validSimilarityCalculators) { 78 80 #region add parameters 79 81 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees.")); … … 85 87 Parameters.Add(new FixedValueParameter<BoolValue>(UseClassValuesParameterName, "Specifies whether the raw estimated values of the tree or the corresponding class values should be used for similarity calculation.", new BoolValue(false))); 86 88 #endregion 89 90 UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter"; 87 91 } 88 92 … … 101 105 102 106 public override IOperation Apply() { 103 var trees = SymbolicExpressionTreeParameter.ActualValue; 104 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 105 var problemData = ProblemDataParameter.ActualValue; 106 var ds = ProblemDataParameter.ActualValue.Dataset; 107 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 108 var modelCreator = ModelCreatorParameter.ActualValue; 109 var estimationLimits = EstimationLimitsParameter.ActualValue; 110 var evaluatedValues = new ItemArray<DoubleArray>(trees.Length); 111 for (int i = 0; i < trees.Length; ++i) { 112 var model = (IDiscriminantFunctionClassificationModel)modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(trees[i], interpreter, estimationLimits.Lower, estimationLimits.Upper); 113 model.RecalculateModelParameters(problemData, rows); 114 var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows); 115 evaluatedValues[i] = new DoubleArray(values.ToArray()); 107 int updateInterval = UpdateIntervalParameter.Value.Value; 108 IntValue updateCounter = UpdateCounterParameter.ActualValue; 109 110 if (updateCounter == null) { 111 updateCounter = new IntValue(updateInterval); 112 UpdateCounterParameter.ActualValue = updateCounter; 116 113 } 117 EvaluatedValuesParameter.ActualValue = evaluatedValues; 114 115 if (updateCounter.Value == updateInterval) { 116 var trees = SymbolicExpressionTreeParameter.ActualValue; 117 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 118 var problemData = ProblemDataParameter.ActualValue; 119 var ds = ProblemDataParameter.ActualValue.Dataset; 120 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 121 var modelCreator = ModelCreatorParameter.ActualValue; 122 var estimationLimits = EstimationLimitsParameter.ActualValue; 123 var evaluatedValues = new ItemArray<DoubleArray>(trees.Length); 124 for (int i = 0; i < trees.Length; ++i) { 125 var model = 126 (IDiscriminantFunctionClassificationModel) 127 modelCreator.CreateSymbolicDiscriminantFunctionClassificationModel(trees[i], interpreter, 128 estimationLimits.Lower, estimationLimits.Upper); 129 model.RecalculateModelParameters(problemData, rows); 130 var values = UseClassValues ? model.GetEstimatedClassValues(ds, rows) : model.GetEstimatedValues(ds, rows); 131 evaluatedValues[i] = new DoubleArray(values.ToArray()); 132 } 133 EvaluatedValuesParameter.ActualValue = evaluatedValues; 134 } 118 135 return base.Apply(); 119 136 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r12068 r12075 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Optimization; 24 25 using HeuristicLab.Parameters; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 115 116 Operators.Add(new SymbolicClassificationSingleObjectiveTrainingParetoBestSolutionAnalyzer()); 116 117 Operators.Add(new SymbolicClassificationSingleObjectiveValidationParetoBestSolutionAnalyzer()); 117 Operators.Add(new SymbolicClassificationPhenotypicDiversityAnalyzer());118 118 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 119 Operators.Add(new SymbolicClassificationPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Similarity" }); 119 120 ParameterizeOperators(); 120 121 } … … 148 149 } 149 150 150 foreach (var op in Operators.OfType< SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {151 foreach (var op in Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>()) { 151 152 op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 152 op.ProblemData = ProblemData; 153 op.Interpreter = SymbolicExpressionTreeInterpreter; 154 } 153 op.QualityVariableName = Evaluator.QualityParameter.ActualName; 155 154 156 foreach (var op in Operators.OfType<SymbolicClassificationPhenotypicDiversityAnalyzer>()) { 157 var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault(); 158 if (sim != null) 159 op.SimilarityCalculator = sim; 155 if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) { 156 var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op; 157 phenotypicSimilarityCalculator.ProblemData = ProblemData; 158 phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter; 159 } 160 160 } 161 161 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression
- Property svn:mergeinfo changed (with no actual effect on merging)
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionPhenotypicDiversityAnalyzer.cs
r12049 r12075 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Linq; 23 24 using HeuristicLab.Analysis; … … 26 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 29 using HeuristicLab.Optimization; 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 32 34 [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 33 35 [StorableClass] 34 public class SymbolicRegressionPhenotypicDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {36 public class SymbolicRegressionPhenotypicDiversityAnalyzer : PopulationSimilarityAnalyzer { 35 37 #region parameter names 36 38 private const string SymbolicExpressionTreeParameterName = "SymbolicExpressionTree"; … … 59 61 #endregion 60 62 61 public SymbolicRegressionPhenotypicDiversityAnalyzer( ) {62 SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree", QualityVariableName = "Quality" };63 public SymbolicRegressionPhenotypicDiversityAnalyzer(IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators) 64 : base(validSimilarityCalculators) { 63 65 #region add parameters 64 66 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(SymbolicExpressionTreeParameterName, "The symbolic expression trees.")); … … 68 70 Parameters.Add(new ValueLookupParameter<DoubleLimit>(EstimationLimitsParameterName, "The upper and lower limit that should be used as cut off value for the output values of symbolic data analysis trees.")); 69 71 #endregion 72 73 UpdateCounterParameter.ActualName = "PhenotypicDiversityAnalyzerUpdateCounter"; 70 74 } 71 75 … … 84 88 85 89 public override IOperation Apply() { 86 var trees = SymbolicExpressionTreeParameter.ActualValue; 87 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 88 var ds = ProblemDataParameter.ActualValue.Dataset; 89 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 90 int updateInterval = UpdateIntervalParameter.Value.Value; 91 IntValue updateCounter = UpdateCounterParameter.ActualValue; 90 92 91 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 92 EvaluatedValuesParameter.ActualValue = evaluatedValues; 93 if (updateCounter == null) { 94 updateCounter = new IntValue(updateInterval); 95 UpdateCounterParameter.ActualValue = updateCounter; 96 } 93 97 98 if (updateCounter.Value == updateInterval) { 99 var trees = SymbolicExpressionTreeParameter.ActualValue; 100 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 101 var ds = ProblemDataParameter.ActualValue.Dataset; 102 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 103 104 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 105 EvaluatedValuesParameter.ActualValue = evaluatedValues; 106 } 94 107 return base.Apply(); 95 108 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r12068 r12075 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Parameters; 26 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 111 112 Operators.Add(new SymbolicRegressionSingleObjectiveValidationParetoBestSolutionAnalyzer()); 112 113 Operators.Add(new SymbolicRegressionSolutionsAnalyzer()); 113 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer());114 114 Operators.Add(new SymbolicExpressionTreePhenotypicSimilarityCalculator()); 115 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>()) { DiversityResultName = "Phenotypic Diversity" }); 115 116 ParameterizeOperators(); 116 117 } … … 143 144 } 144 145 145 foreach (var op in Operators.OfType< SymbolicExpressionTreePhenotypicSimilarityCalculator>()) {146 foreach (var op in Operators.OfType<ISingleObjectiveSolutionSimilarityCalculator>()) { 146 147 op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 147 op.ProblemData = ProblemData; 148 op.Interpreter = SymbolicExpressionTreeInterpreter; 149 } 148 op.QualityVariableName = Evaluator.QualityParameter.ActualName; 150 149 151 foreach (var op in Operators.OfType<SymbolicRegressionPhenotypicDiversityAnalyzer>()) { 152 var sim = Operators.OfType<SymbolicExpressionTreePhenotypicSimilarityCalculator>().FirstOrDefault(); 153 if (sim != null) 154 op.SimilarityCalculator = sim; 150 if (op is SymbolicExpressionTreePhenotypicSimilarityCalculator) { 151 var phenotypicSimilarityCalculator = (SymbolicExpressionTreePhenotypicSimilarityCalculator)op; 152 phenotypicSimilarityCalculator.ProblemData = ProblemData; 153 phenotypicSimilarityCalculator.Interpreter = SymbolicExpressionTreeInterpreter; 154 } 155 155 } 156 156 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisBottomUpDiversityAnalyzer.cs
r12064 r12075 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using HeuristicLab.Analysis; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; 26 using HeuristicLab.Optimization; 25 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 28 … … 28 30 [Item("SymbolicDataAnalysisBottomUpDiversityAnalyzer", "A diversity analyzer based on the bottom-up distance between trees.")] 29 31 [StorableClass] 30 public class SymbolicDataAnalysisBottomUpDiversityAnalyzer : SingleObjectivePopulationDiversityAnalyzer {32 public class SymbolicDataAnalysisBottomUpDiversityAnalyzer : PopulationSimilarityAnalyzer { 31 33 [StorableConstructor] 32 34 protected SymbolicDataAnalysisBottomUpDiversityAnalyzer(bool deserializing) : base(deserializing) { } … … 40 42 } 41 43 42 public SymbolicDataAnalysisBottomUpDiversityAnalyzer() { 43 SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { SolutionVariableName = "SymbolicExpressionTree" }; 44 public SymbolicDataAnalysisBottomUpDiversityAnalyzer( 45 IEnumerable<ISingleObjectiveSolutionSimilarityCalculator> validSimilarityCalculators) 46 : base(validSimilarityCalculators) { 47 UpdateCounterParameter.ActualName = "GenotypicDiversityAnalyzerUpdateCounter"; 44 48 } 45 49 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r12068 r12075 118 118 set { ProblemDataParameter.Value = value; } 119 119 } 120 120 121 public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar { 121 122 get { return SymbolicExpressionTreeGrammarParameter.Value; } … … 126 127 set { SymbolicExpressionTreeInterpreterParameter.Value = value; } 127 128 } 129 128 130 public IntValue MaximumSymbolicExpressionTreeDepth { 129 131 get { return MaximumSymbolicExpressionTreeDepthParameter.Value; } … … 141 143 get { return RelativeNumberOfEvaluatedSamplesParameter.Value; } 142 144 } 145 143 146 public IntRange FitnessCalculationPartition { 144 147 get { return FitnessCalculationPartitionParameter.Value; } … … 228 231 Operators.Add(new MinAverageMaxSymbolicExpressionTreeLengthAnalyzer()); 229 232 Operators.Add(new SymbolicExpressionTreeLengthAnalyzer()); 230 Operators.Add(new SymbolicDataAnalysisBottomUpDiversityAnalyzer());231 233 Operators.Add(new SymbolicExpressionTreeBottomUpSimilarityCalculator()); 234 Operators.Add(new SymbolicDataAnalysisBottomUpDiversityAnalyzer(Operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>()) { DiversityResultName = "Genotypic Diversity" }); 232 235 ParameterizeOperators(); 233 236 } … … 349 352 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 350 353 } 351 foreach (var op in operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>()) {352 op.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName;353 }354 foreach (var op in operators.OfType<SymbolicDataAnalysisBottomUpDiversityAnalyzer>()) {355 var sim = Operators.OfType<SymbolicExpressionTreeBottomUpSimilarityCalculator>().FirstOrDefault();356 if (sim != null)357 op.SimilarityCalculator = sim;358 }359 354 } 360 355
Note: See TracChangeset
for help on using the changeset viewer.