- Timestamp:
- 07/23/14 22:49:51 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj
r11219 r11221 197 197 </ItemGroup> 198 198 <ItemGroup> 199 <Compile Include="Analyzers\SymbolicDataAnalysisInternalDiversityAnalyzer.cs" /> 199 200 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectivePruningAnalyzer.cs" /> 200 201 <Compile Include="Analyzers\SymbolicDataAnalysisSingleObjectiveValidationParetoBestSolutionAnalyzer.cs" /> -
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")] -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SymbolicDataAnalysisProblem.cs
r11219 r11221 34 34 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 35 35 using HeuristicLab.PluginInfrastructure; 36 using HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators;37 36 using HeuristicLab.Problems.Instances; 38 37 -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Tests/BottomUpSimilarityCalculatorTest.cs
r11220 r11221 8 8 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 9 9 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views; 10 using HeuristicLab.Problems.DataAnalysis.Symbolic.SimilarityCalculators;11 10 using HeuristicLab.Random; 12 11 using Microsoft.VisualStudio.TestTools.UnitTesting; … … 33 32 TestMatchedNodes("(+ 1 2)", "(+ 2 1)", 5); 34 33 TestMatchedNodes("(- 2 1)", "(- 1 2)", 2); 34 TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (+ (variable 1 X2) 1))", 2); 35 35 36 36 TestMatchedNodes("(* (variable 1 X1) (variable 1 X2))", "(* (+ (variable 1 X1) 1) (variable 1 X2))", 2); … … 52 52 var t2 = importer.Import(expr2); 53 53 54 var mapping = busCalculator.ComputeBottomUpMapping(t1 , t2);54 var mapping = busCalculator.ComputeBottomUpMapping(t1.Root, t2.Root); 55 55 var c = mapping.Count; 56 56
Note: See TracChangeset
for help on using the changeset viewer.