Changeset 11910 for branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching
- Timestamp:
- 02/05/15 12:09:18 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching
- Files:
-
- 2 deleted
- 3 edited
- 3 copied
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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;
Note: See TracChangeset
for help on using the changeset viewer.