Changeset 11221 for branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators
- Timestamp:
- 07/23/14 22:49:51 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpSimilarityCalculator.cs
r11220 r11221 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 30 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic .SimilarityCalculators{31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 32 32 [StorableClass] 33 33 [Item("BottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] … … 59 59 return 1; 60 60 61 var map = ComputeBottomUpMapping(t1 , t2);61 var map = ComputeBottomUpMapping(t1.Root, t2.Root); 62 62 return 2.0 * map.Count / (t1.Length + t2.Length); 63 63 } 64 64 65 66 public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 67 var compactedGraph = Compact(t1, t2); 65 public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) { 66 var compactedGraph = Compact(n1, n2); 68 67 69 68 var forwardMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t1 => nodes of t2 70 69 var reverseMap = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); // nodes of t2 => nodes of t1 71 70 72 foreach (var v in t1.IterateNodesBreadth()) {71 foreach (var v in n1.IterateNodesBreadth()) { 73 72 if (forwardMap.ContainsKey(v)) continue; 74 73 var kv = compactedGraph[v]; 75 74 ISymbolicExpressionTreeNode w = null; 76 foreach (var t in t2.IterateNodesBreadth()) {75 foreach (var t in n2.IterateNodesBreadth()) { 77 76 if (reverseMap.ContainsKey(t) || compactedGraph[t] != kv) continue; 78 77 w = t; … … 103 102 /// <param name="t2">The second tree</param> 104 103 /// <returns>The compacted DAG representing the two trees</returns> 105 private Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {104 private Dictionary<ISymbolicExpressionTreeNode, IVertex> Compact(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) { 106 105 var nodesToVertices = new Dictionary<ISymbolicExpressionTreeNode, IVertex>(); // K 107 106 var labelsToVertices = new Dictionary<string, IVertex>(); // L … … 109 108 var vertices = new List<IVertex>(); // G 110 109 111 var nodes = t1.IterateNodesPostfix().Concat(t2.IterateNodesPostfix()); // the disjoint union F110 var nodes = n1.IterateNodesPostfix().Concat(n2.IterateNodesPostfix()); // the disjoint union F 112 111 var queue = new Queue<ISymbolicExpressionTreeNode>(); 113 112 -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs
r11219 r11221 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic .SimilarityCalculators{29 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 30 30 [StorableClass] 31 31 [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
Note: See TracChangeset
for help on using the changeset viewer.