Changeset 11239 for branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators
- Timestamp:
- 07/30/14 13:44:14 (10 years ago)
- Location:
- branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/BottomUpTreeSimilarityCalculator.cs
r11236 r11239 31 31 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { 32 32 [StorableClass] 33 [Item("BottomUpSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 34 public class BottomUpSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 35 private readonly HashSet<string> commutativeSymbols = new HashSet<string> { "Addition", "Multiplication", "Average", "And", "Or", "Xor" }; 36 37 public BottomUpSimilarityCalculator() { } 33 [Item("BottomUpTreeSimilarityCalculator", "A similarity calculator which uses the tree bottom-up distance as a similarity metric.")] 34 public class BottomUpTreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 35 private readonly HashSet<string> commutativeSymbols; 36 37 public BottomUpTreeSimilarityCalculator() { 38 commutativeSymbols = new HashSet<string>(); 39 } 40 41 public BottomUpTreeSimilarityCalculator(IEnumerable<string> commutativeSymbols) { 42 this.commutativeSymbols = new HashSet<string>(commutativeSymbols); 43 } 38 44 39 45 public override IDeepCloneable Clone(Cloner cloner) { 40 return new BottomUp SimilarityCalculator(this, cloner);41 } 42 43 protected BottomUp SimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)46 return new BottomUpTreeSimilarityCalculator(this, cloner); 47 } 48 49 protected BottomUpTreeSimilarityCalculator(BottomUpTreeSimilarityCalculator original, Cloner cloner) 44 50 : base(original, cloner) { 45 51 } … … 57 63 58 64 return similarity; 65 } 66 67 public bool AddCommutativeSymbol(string symbolName) { 68 return commutativeSymbols.Add(symbolName); 69 } 70 71 public bool RemoveCommutativeSymbol(string symbolName) { 72 return commutativeSymbols.Remove(symbolName); 59 73 } 60 74 … … 187 201 } 188 202 203 /// <summary> 204 /// This method iterates the nodes of a subtree in breadth order while also sorting the subtrees of commutative symbols based on their label. 205 /// This is necessary in order for the mapping to be realized correctly. 206 /// </summary> 207 /// <param name="node">The root of the subtree</param> 208 /// <returns>A list of nodes in breadth order (with children of commutative symbols sorted by label)</returns> 189 209 private IEnumerable<ISymbolicExpressionTreeNode> IterateBreadthOrdered(ISymbolicExpressionTreeNode node) { 190 210 var list = new List<ISymbolicExpressionTreeNode> { node }; -
branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs
r11230 r11239 56 56 } 57 57 58 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) {58 public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer) { 59 59 int max = 0; 60 60 var rootA = a.Root.GetSubtree(0).GetSubtree(0);
Note: See TracChangeset
for help on using the changeset viewer.