Changeset 11910
- Timestamp:
- 02/05/15 12:09:18 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance
- Files:
-
- 5 deleted
- 6 edited
- 3 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.BottomUpTreeDistance.sln
r11894 r11910 36 36 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|Any CPU.ActiveCfg = Release|Any CPU 37 37 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|Any CPU.Build.0 = Release|Any CPU 38 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x64.ActiveCfg = Release|x64 39 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x64.Build.0 = Release|x64 40 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x86.ActiveCfg = Release|x86 41 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x86.Build.0 = Release|x86 38 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x64.ActiveCfg = Release|Any CPU 39 {07C05C8F-0769-4607-96C6-D90A219F4C85}.Release|x86.ActiveCfg = Release|Any CPU 42 40 EndGlobalSection 43 41 GlobalSection(SolutionProperties) = preSolution -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11887 r11910 203 203 </ItemGroup> 204 204 <ItemGroup> 205 <Compile Include="Analyzers\SymbolicDataAnalysisInternalDiversityAnalyzer.cs" />206 205 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 207 206 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> … … 221 220 <Compile Include="Importer\Token.cs" /> 222 221 <Compile Include="Interfaces\IModelBacktransformator.cs" /> 223 <Compile Include="Matching\SymbolicExpressionTreeCanonicalSorter.cs" /> 224 <Compile Include="Matching\SymbolicExpressionTreeEqualityComparer.cs" /> 225 <Compile Include="Matching\SymbolicExpressionTreeMatching.cs" /> 226 <Compile Include="Matching\SymbolicExpressionTreeMaxCommonSequenceCalculator.cs" /> 227 <Compile Include="Matching\SymbolicExpressionTreeNodeComparer.cs" /> 228 <Compile Include="Matching\SymbolicExpressionTreeNodeSimilarityComparer.cs" /> 229 <Compile Include="SimilarityCalculators\BottomUpSimilarityCalculator.cs" /> 230 <Compile Include="SimilarityCalculators\MaxCommonSubtreeSimilarityCalculator.cs" /> 222 <Compile Include="TreeMatching\SymbolicExpressionTreeCanonicalSorter.cs" /> 223 <Compile Include="TreeMatching\SymbolicExpressionTreeEqualityComparer.cs" /> 224 <Compile Include="TreeMatching\SymbolicExpressionTreeMatching.cs" /> 225 <Compile Include="TreeMatching\SymbolicExpressionTreeNodeComparer.cs" /> 226 <Compile Include="TreeMatching\SymbolicExpressionTreeNodeEqualityComparer.cs" /> 227 <Compile Include="TreeMatching\SymbolicExpressionTreeBottomUpSimilarityCalculator.cs" /> 228 <Compile Include="TreeMatching\SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs" /> 231 229 <Compile Include="SymbolicExpressionTreeBacktransformator.cs" /> 232 230 <Compile Include="SymbolicDataAnalysisExpressionPruningOperator.cs" /> -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r11486 r11910 358 358 } 359 359 foreach (var op in operators.OfType<SingleObjectivePopulationDiversityAnalyzer>()) { 360 op.SimilarityCalculator = new BottomUpSimilarityCalculator();360 op.SimilarityCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator(); 361 361 } 362 362 } -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r11900 r11910 33 33 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 34 34 [StorableClass] 35 [Item(" BottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")]36 public class BottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {35 [Item("SymbolicExpressionTreeBottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 36 public class SymbolicExpressionTreeBottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 37 37 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 38 38 public bool MatchVariableWeights { get; set; } 39 39 public bool MatchConstantValues { get; set; } 40 40 41 public BottomUpSimilarityCalculator() { }42 43 protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)41 public SymbolicExpressionTreeBottomUpSimilarityCalculator() { } 42 43 protected SymbolicExpressionTreeBottomUpSimilarityCalculator(SymbolicExpressionTreeBottomUpSimilarityCalculator original, Cloner cloner) 44 44 : base(original, cloner) { 45 45 MatchVariableWeights = original.MatchVariableWeights; … … 48 48 49 49 public override IDeepCloneable Clone(Cloner cloner) { 50 return new BottomUpSimilarityCalculator(this, cloner);50 return new SymbolicExpressionTreeBottomUpSimilarityCalculator(this, cloner); 51 51 } 52 52 -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeEqualityComparer.cs
r10562 r11910 5 5 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 6 6 public class SymbolicExpressionTreeEqualityComparer : IEqualityComparer<ISymbolicExpressionTree> { 7 public SymbolicExpressionTreeNode SimilarityComparer SimilarityComparer { get; set; }7 public SymbolicExpressionTreeNodeEqualityComparer SimilarityComparer { get; set; } 8 8 9 9 public bool Equals(ISymbolicExpressionTree a, ISymbolicExpressionTree b) { 10 10 if (SimilarityComparer == null) throw new Exception("SimilarityComparer needs to be initialized first."); 11 return a.Length == b.Length && 12 SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length); 11 return a.Length == b.Length && SymbolicExpressionTreeMatching.Match(a.Root, b.Root, SimilarityComparer) == Math.Min(a.Length, b.Length); 13 12 } 14 13 -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMatching.cs
r11887 r11910 30 30 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 31 31 public static class SymbolicExpressionTreeMatching { 32 public static bool ContainsSubtree(this ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNode SimilarityComparer comparer) {32 public static bool ContainsSubtree(this ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comparer) { 33 33 return FindMatches(root, subtree, comparer).Any(); 34 34 } 35 public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNode SimilarityComparer comparer) {35 public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comparer) { 36 36 return FindMatches(tree.Root, subtree, comparer); 37 37 } 38 38 39 public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNode SimilarityComparer comp) {39 public static IEnumerable<ISymbolicExpressionTreeNode> FindMatches(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode subtree, SymbolicExpressionTreeNodeEqualityComparer comp) { 40 40 var fragmentLength = subtree.GetLength(); 41 41 // below, we use ">=" for Match(n, subtree, comp) >= fragmentLength because in case of relaxed conditions, -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs
r11900 r11910 29 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 30 [StorableClass] 31 [Item(" MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]32 public class MaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {31 [Item("SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")] 32 public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 33 33 [Storable] 34 private readonly SymbolicExpressionTreeNode SimilarityComparer comparer;34 private readonly SymbolicExpressionTreeNodeEqualityComparer comparer; 35 35 public bool MatchVariableWeights { 36 36 get { return comparer.MatchVariableWeights; } … … 44 44 45 45 [StorableConstructor] 46 protected MaxCommonSubtreeSimilarityCalculator(bool deserializing) : base(deserializing) { }46 protected SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool deserializing) : base(deserializing) { } 47 47 48 48 public override IDeepCloneable Clone(Cloner cloner) { 49 return new MaxCommonSubtreeSimilarityCalculator(this, cloner);49 return new SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(this, cloner); 50 50 } 51 51 52 protected MaxCommonSubtreeSimilarityCalculator(MaxCommonSubtreeSimilarityCalculator original, Cloner cloner)52 protected SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator original, Cloner cloner) 53 53 : base(original, cloner) { 54 54 comparer = cloner.Clone(original.comparer); 55 55 } 56 56 57 public MaxCommonSubtreeSimilarityCalculator() {58 comparer = new SymbolicExpressionTreeNode SimilarityComparer {57 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator() { 58 comparer = new SymbolicExpressionTreeNodeEqualityComparer { 59 59 MatchConstantValues = true, 60 60 MatchVariableNames = true, … … 63 63 } 64 64 65 public MaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool matchConstantValues) {66 comparer = new SymbolicExpressionTreeNode SimilarityComparer {65 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool matchConstantValues) { 66 comparer = new SymbolicExpressionTreeNodeEqualityComparer { 67 67 MatchConstantValues = matchConstantValues, 68 68 MatchVariableNames = true, -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs
r11894 r11910 21 21 22 22 using System; 23 using System.Collections.Generic;24 23 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 25 24 … … 30 29 // - used for bringing subtrees to a "canonical" form when the operation allows reordering of arguments 31 30 public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer { 32 public static int Compare (ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) {31 public static int CompareNodes(ISymbolicExpressionTreeNode a, ISymbolicExpressionTreeNode b) { 33 32 var ta = a as SymbolicExpressionTreeTerminalNode; 34 33 var tb = b as SymbolicExpressionTreeTerminalNode; … … 66 65 } 67 66 68 int IComparer<ISymbolicExpressionTreeNode>.Compare(ISymbolicExpressionTreeNode x, ISymbolicExpressionTreeNode y) {69 return Compare (x, y);67 public int Compare(ISymbolicExpressionTreeNode x, ISymbolicExpressionTreeNode y) { 68 return CompareNodes(x, y); 70 69 } 71 70 } -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs
r11900 r11910 26 26 27 27 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 28 [Item("SymbolicExpressionTreeNode SimilarityComparer", "A comparison operator that checks node equality based on different similarity measures.")]28 [Item("SymbolicExpressionTreeNodeEqualityComparer", "An operator that checks node equality based on different similarity measures.")] 29 29 [StorableClass] 30 public class SymbolicExpressionTreeNode SimilarityComparer : Item, ISymbolicExpressionTreeNodeSimilarityComparer {30 public class SymbolicExpressionTreeNodeEqualityComparer : Item, ISymbolicExpressionTreeNodeSimilarityComparer { 31 31 [StorableConstructor] 32 protected SymbolicExpressionTreeNode SimilarityComparer(bool deserializing) : base(deserializing) { }33 protected SymbolicExpressionTreeNode SimilarityComparer(SymbolicExpressionTreeNodeSimilarityComparer original, Cloner cloner)32 protected SymbolicExpressionTreeNodeEqualityComparer(bool deserializing) : base(deserializing) { } 33 protected SymbolicExpressionTreeNodeEqualityComparer(SymbolicExpressionTreeNodeEqualityComparer original, Cloner cloner) 34 34 : base(original, cloner) { 35 35 matchConstantValues = original.matchConstantValues; … … 37 37 matchVariableWeights = original.matchVariableWeights; 38 38 } 39 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicExpressionTreeNode SimilarityComparer(this, cloner); }39 public override IDeepCloneable Clone(Cloner cloner) { return new SymbolicExpressionTreeNodeEqualityComparer(this, cloner); } 40 40 41 41 // more flexible matching criteria … … 65 65 } 66 66 67 public SymbolicExpressionTreeNode SimilarityComparer() {67 public SymbolicExpressionTreeNodeEqualityComparer() { 68 68 matchConstantValues = true; 69 69 matchVariableNames = true; -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Tests/SymbolicExpressionTreeBottomUpSimilarityCalculatorTest.cs
r11900 r11910 14 14 [TestClass] 15 15 public class BottomUpSimilarityCalculatorTest { 16 private readonly BottomUpSimilarityCalculator busCalculator;16 private readonly SymbolicExpressionTreeBottomUpSimilarityCalculator busCalculator; 17 17 private readonly SymbolicExpressionImporter importer; 18 18 … … 22 22 23 23 public BottomUpSimilarityCalculatorTest() { 24 busCalculator = new BottomUpSimilarityCalculator { MatchConstantValues = true, MatchVariableWeights = true };24 busCalculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchConstantValues = true, MatchVariableWeights = true }; 25 25 importer = new SymbolicExpressionImporter(); 26 26 } -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Tests/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest.cs
r11900 r11910 12 12 /// </summary> 13 13 [TestClass] 14 public class MaxCommonSubtreeSimilarityCalculatorTest {14 public class SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest { 15 15 private readonly ISymbolicExpressionTreeNodeSimilarityComparer comparer; 16 16 … … 19 19 private const int Columns = 10; 20 20 21 public MaxCommonSubtreeSimilarityCalculatorTest() {22 comparer = new SymbolicExpressionTreeNode SimilarityComparer();21 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculatorTest() { 22 comparer = new SymbolicExpressionTreeNodeEqualityComparer(); 23 23 } 24 24 … … 61 61 for (int i = 0; i < trees.Length - 1; ++i) { 62 62 for (int j = i + 1; j < trees.Length; ++j) { 63 s += MaxCommonSubtreeSimilarityCalculator.MaxCommonSubtreeSimilarity(trees[i], trees[j], comparer);63 s += SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.MaxCommonSubtreeSimilarity(trees[i], trees[j], comparer); 64 64 } 65 65 }
Note: See TracChangeset
for help on using the changeset viewer.