Changeset 4941 for branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers
- Timestamp:
- 11/25/10 23:16:23 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis.PopulationDiversityAnalysis/HeuristicLab.Problems.DataAnalysis.Regression/3.3/Symbolic/Analyzers/FineGrainedStructuralPopulationDiversityAnalyzer.cs
r4938 r4941 68 68 69 69 protected override double[,] CalculateSimilarities(SymbolicExpressionTree[] solutions) { 70 Constant c = null;70 Constant constant = null; 71 71 foreach (Symbol symbol in FunctionTreeGrammar.Symbols) { 72 72 if (symbol is Constant) { 73 if (c != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar.");74 c = (Constant)symbol;73 if (constant != null) throw new InvalidProgramException("There are more and one constnat definitions in the given function tree grammar."); 74 constant = (Constant)symbol; 75 75 } 76 76 } … … 81 81 } 82 82 variableNames.Add(ProblemData.TargetVariable.Value); 83 IList<GeneticInformationItem>[] geneticInformationItemsList = new List<GeneticInformationItem>[n];83 IList<GeneticInformationItem>[] geneticInformationItemsLists = new List<GeneticInformationItem>[n]; 84 84 for (int i = 0; i < n; i++) { 85 geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue); 85 // geneticInformationItemsList[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, MinimumLEvelDelta, MaximumLevelDelta); 86 geneticInformationItemsLists[i] = GeneticInformationItem.getGeneticInformationItems(solutions[i].Root, variableNames, 0, int.MaxValue); 86 87 } 87 88 double[,] result = new double[n, n]; … … 90 91 if (i == j) 91 92 result[i, j] = 1; 92 else 93 result[i, j] = 0; 93 else { 94 IList<GeneticInformationItem> solution1GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[i]); 95 IList<GeneticInformationItem> solution2GeneticItems = GeneticInformationItem.CopyList(geneticInformationItemsLists[j]); 96 double similarity = 0; 97 for (int k = 0; k < solution1GeneticItems.Count; k++) { 98 double bestPendantSimilarity; 99 // GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], 100 // ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset, 101 // LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient, 102 // VariableWeightCoefficient, AdditiveSimilarityCalculation, out bestPendantSimilarity); 103 GeneticInformationItem bestPendant = GeneticInformationItem.FindBestPendant(solution1GeneticItems[k], solution2GeneticItems, 104 -10, 10, 1, 100, 10, 105 1, 1, 1, 1, 1, 1, true, out bestPendantSimilarity); 106 if (bestPendant != null) { 107 similarity += bestPendantSimilarity; 108 // if (PreventMultipleComparisonContribution) 109 if (true) 110 solution2GeneticItems.Remove(bestPendant); 111 } 112 } 113 result[i, j] = similarity / solution1GeneticItems.Count; 114 } 94 115 } 95 116 } … … 151 172 } 152 173 153 /* 154 public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, List<GeneticInformationItem> ComparisonItems, 155 StructuralSimilarityAnalysisParameters Parameters, 156 int MaxTreeHeight, int MaxTimeOffset, 174 public static IList<GeneticInformationItem> CopyList(IList<GeneticInformationItem> GeneticInformationItemsList) { 175 List<GeneticInformationItem> list = new List<GeneticInformationItem>(GeneticInformationItemsList.Count); 176 list.AddRange(GeneticInformationItemsList); 177 return list; 178 } 179 180 public static GeneticInformationItem FindBestPendant(GeneticInformationItem Item, IList<GeneticInformationItem> ComparisonItems, 181 double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma, 182 int MaximumTreeHeight, int MaximumTimeOffset, 183 double LevelDifferenceCoefficient, double AncestorIndexCoefficient, 184 double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient, 185 bool AdditiveSimilarityCalculation, 157 186 out double BestPendantSimilarity) { 158 187 int maxSimilarityIndex = -1; 159 188 double similarity, maxSimilarity = -double.MaxValue; 160 189 for (int i = 0; i < ComparisonItems.Count; i++) { 161 similarity = Similarity(Item, ComparisonItems[i], Parameters, MaxTreeHeight, MaxTimeOffset); 190 similarity = Similarity(Item, ComparisonItems[i], ConstantMinimum, ConstantMaximum, VariableWeightSigma, MaximumTreeHeight, MaximumTimeOffset, 191 LevelDifferenceCoefficient, AncestorIndexCoefficient, ConstantValueCoefficient, VariableWeightSigma, TimeOffsetCoefficient, 192 VariableWeightCoefficient, AdditiveSimilarityCalculation); 162 193 if (!double.IsNaN(similarity) && similarity > maxSimilarity) { 163 194 maxSimilarity = similarity; … … 170 201 else 171 202 return null; 172 } */203 } 173 204 174 205 public static double Similarity(GeneticInformationItem Item1, GeneticInformationItem Item2, 175 GlobalSymbolicExpressionGrammar ExpressionGrammar,double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma,206 double ConstantMinimum, double ConstantMaximum, double VariableWeightSigma, 176 207 int MaximumTreeHeight, int MaximumTimeOffset, 177 // StructuralSimilarityAnalysisParameters Parameters, 178 double LevelDifferenceCoefficient, 179 double AncestorIndexCoefficient, 180 double ConstantValueCoefficient, 181 double VariableWeightCoefficient, 182 double TimeOffsetCoefficient, 183 double VariableIndexCoefficient, 184 bool AdditiveSimilarityCalculation 185 ) { 208 double LevelDifferenceCoefficient, double AncestorIndexCoefficient, 209 double ConstantValueCoefficient, double VariableWeightCoefficient, double TimeOffsetCoefficient, double VariableIndexCoefficient, 210 bool AdditiveSimilarityCalculation) { 186 211 187 212 if (Item1.AncestorDefinition != Item2.AncestorDefinition || Item1.DescendantDefinition != Item2.DescendantDefinition)
Note: See TracChangeset
for help on using the changeset viewer.