Changeset 12049
- Timestamp:
- 02/21/15 15:55:47 (10 years ago)
- Location:
- branches/SymbolicExpressionTreeDiversityAnalyzers
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationPhenotypicDiversityAnalyzer.cs
r12030 r12049 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using System.Linq; 24 23 using HeuristicLab.Analysis; … … 30 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 30 32 namespace HeuristicLab.Problems.DataAnalysis.Symbolic. Analyzers{31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { 33 32 [Item("SymbolicClassificationPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 34 33 [StorableClass] … … 39 38 private const string SymbolicDataAnalysisTreeInterpreterParameterName = "SymbolicExpressionTreeInterpreter"; 40 39 private const string ProblemDataParameterName = "ProblemData"; 40 private const string ModelCreatorParameterName = "ModelCreator"; 41 41 private const string EstimationLimitsParameterName = "EstimationLimits"; 42 42 private const string UseClassValuesParameterName = "UseClassValues"; … … 53 53 get { return (ILookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>)Parameters[SymbolicDataAnalysisTreeInterpreterParameterName]; } 54 54 } 55 public ILookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator> ModelCreatorParameter { 56 get { return (ILookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator>)Parameters[ModelCreatorParameterName]; } 57 } 55 58 public IValueLookupParameter<IClassificationProblemData> ProblemDataParameter { 56 59 get { return (IValueLookupParameter<IClassificationProblemData>)Parameters[ProblemDataParameterName]; } … … 65 68 66 69 #region properties 67 bool UseClassValues {70 private bool UseClassValues { 68 71 get { return UseClassValuesParameter.Value.Value; } 69 72 set { UseClassValuesParameter.Value.Value = value; } … … 78 81 Parameters.Add(new LookupParameter<ISymbolicDataAnalysisExpressionTreeInterpreter>(SymbolicDataAnalysisTreeInterpreterParameterName, "The interpreter that should be used to calculate the output values of the symbolic data analysis tree.")); 79 82 Parameters.Add(new ValueLookupParameter<IClassificationProblemData>(ProblemDataParameterName, "The problem data on which the symbolic data analysis solution should be evaluated.")); 83 Parameters.Add(new LookupParameter<ISymbolicDiscriminantFunctionClassificationModelCreator>(ModelCreatorParameterName, "The model creator for creating discriminant function classification models.")); 80 84 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.")); 81 Parameters.Add(new FixedValueParameter<BoolValue>(UseClassValuesParameterName, 82 "Specifies whether the raw estimated values of the tree or the corresponding class values should be used for similarity calculation.", new BoolValue(false))); 85 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))); 83 86 #endregion 84 87 } … … 100 103 var trees = SymbolicExpressionTreeParameter.ActualValue; 101 104 var interpreter = SymbolicDataAnalysisTreeInterpreterParameter.ActualValue; 105 var problemData = ProblemDataParameter.ActualValue; 102 106 var ds = ProblemDataParameter.ActualValue.Dataset; 103 107 var rows = ProblemDataParameter.ActualValue.TrainingIndices; 104 105 if (UseClassValues) { 106 var problemData = ProblemDataParameter.ActualValue; 107 var evaluatedValues = new ItemArray<DoubleArray>(trees.Length); 108 for (int i = 0; i < trees.Length; ++i) { 109 var t = trees[i]; 110 double[] classValues, thresholds; 111 var estimatedValues = interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray(); 112 AccuracyMaximizationThresholdCalculator.CalculateThresholds(problemData, estimatedValues, 113 problemData.Dataset.GetDoubleValues(problemData.TargetVariable, problemData.TrainingIndices), 114 out classValues, out thresholds); 115 var estimatedClassValues = new List<double>(); 116 foreach (var x in estimatedValues) { 117 int classIndex = 0; 118 // find first threshold value which is larger than x => class index = threshold index + 1 119 for (int j = 0; j < thresholds.Length; j++) { 120 if (x > thresholds[j]) classIndex++; 121 else break; 122 } 123 estimatedClassValues.Add(classValues.ElementAt(classIndex - 1)); 124 } 125 evaluatedValues[i] = new DoubleArray(estimatedClassValues.ToArray()); 126 } 127 EvaluatedValuesParameter.ActualValue = evaluatedValues; 128 } else { 129 var evaluatedValues = new ItemArray<DoubleArray>(trees.Select(t => new DoubleArray(interpreter.GetSymbolicExpressionTreeValues(t, ds, rows).ToArray()))); 130 EvaluatedValuesParameter.ActualValue = evaluatedValues; 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()); 131 116 } 117 EvaluatedValuesParameter.ActualValue = evaluatedValues; 132 118 return base.Apply(); 133 119 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Classification/3.4/SingleObjective/SymbolicClassificationSingleObjectiveProblem.cs
r12030 r12049 24 24 using HeuristicLab.Parameters; 25 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers;27 26 28 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Classification { … … 147 146 op.ModelCreatorParameter.ActualName = ModelCreatorParameter.Name; 148 147 } 148 149 foreach (var op in Operators.OfType<SymbolicClassificationPhenotypicDiversityAnalyzer>()) { 150 var sim = op.SimilarityCalculator as SymbolicExpressionTreePhenotypicSimilarityCalculator; 151 if (sim == null) { 152 op.SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator { 153 SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName 154 }; 155 } else { 156 sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 157 } 158 } 149 159 } 150 160 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionPhenotypicDiversityAnalyzer.cs
r12030 r12049 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic. Analyzers{31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { 32 32 [Item("SymbolicRegressionPhenotypicDiversityAnalyzer", "An analyzer which calculates diversity based on the phenotypic distance between trees")] 33 33 [StorableClass] -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/SymbolicRegressionSingleObjectiveProblem.cs
r12030 r12049 25 25 using HeuristicLab.Parameters; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Problems.DataAnalysis.Symbolic.Analyzers;28 27 29 28 namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Regression { … … 113 112 Operators.Add(new SymbolicRegressionSolutionsAnalyzer()); 114 113 Operators.Add(new SymbolicRegressionPhenotypicDiversityAnalyzer()); 115 116 114 ParameterizeOperators(); 117 115 } … … 143 141 } 144 142 } 143 foreach (var op in Operators.OfType<SymbolicRegressionPhenotypicDiversityAnalyzer>()) { 144 var sim = op.SimilarityCalculator as SymbolicExpressionTreePhenotypicSimilarityCalculator; 145 if (sim == null) { 146 op.SimilarityCalculator = new SymbolicExpressionTreePhenotypicSimilarityCalculator { 147 SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName 148 }; 149 } else { 150 sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 151 } 152 } 145 153 } 146 154 } -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r12030 r12049 119 119 set { ProblemDataParameter.Value = value; } 120 120 } 121 122 121 public ISymbolicDataAnalysisGrammar SymbolicExpressionTreeGrammar { 123 122 get { return SymbolicExpressionTreeGrammarParameter.Value; } … … 128 127 set { SymbolicExpressionTreeInterpreterParameter.Value = value; } 129 128 } 130 131 129 public IntValue MaximumSymbolicExpressionTreeDepth { 132 130 get { return MaximumSymbolicExpressionTreeDepthParameter.Value; } … … 144 142 get { return RelativeNumberOfEvaluatedSamplesParameter.Value; } 145 143 } 146 147 144 public IntRange FitnessCalculationPartition { 148 145 get { return FitnessCalculationPartitionParameter.Value; } … … 352 349 op.EvaluatorParameter.ActualName = EvaluatorParameter.Name; 353 350 } 351 foreach (var op in operators.OfType<SymbolicDataAnalysisBottomUpDiversityAnalyzer>()) { 352 var sim = op.SimilarityCalculator as SymbolicExpressionTreeBottomUpSimilarityCalculator; 353 if (sim == null) { 354 op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { 355 SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName 356 }; 357 } else { 358 sim.SolutionVariableName = SolutionCreator.SymbolicExpressionTreeParameter.ActualName; 359 } 360 } 354 361 } 355 362 -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r12028 r12049 60 60 61 61 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 62 if (leftSolution == rightSolution) 63 return 1.0; 64 62 65 var t1 = leftSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree; 63 66 var t2 = rightSolution.Variables[SolutionVariableName].Value as ISymbolicExpressionTree; -
branches/SymbolicExpressionTreeDiversityAnalyzers/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreePhenotypicSimilarityCalculator.cs
r12029 r12049 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 63 63 64 64 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 65 if (leftSolution == rightSolution) 66 return 1.0; 67 65 68 var leftValues = (DoubleArray)leftSolution.Variables["EstimatedValues"].Value; 66 69 var rightValues = (DoubleArray)rightSolution.Variables["EstimatedValues"].Value;
Note: See TracChangeset
for help on using the changeset viewer.