Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/30/14 13:44:14 (10 years ago)
Author:
bburlacu
Message:

#2215:

  • Renamed BottomUpSimilarityCalculator to BottomUpTreeSimilarityCalculator.
  • Refactored the BottomUpTreeSimilarityCalculator to accept a configurable list of commutative symbols (the children of commutative symbols need to be sorted according to their label).
  • Added MaxCommonSubtreeSimilarityCalculator performance test
  • Updated BottomUpTreeSimilarityCalculatorTest
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  
    3131namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    3232  [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    }
    3844
    3945    public override IDeepCloneable Clone(Cloner cloner) {
    40       return new BottomUpSimilarityCalculator(this, cloner);
    41     }
    42 
    43     protected BottomUpSimilarityCalculator(BottomUpSimilarityCalculator original, Cloner cloner)
     46      return new BottomUpTreeSimilarityCalculator(this, cloner);
     47    }
     48
     49    protected BottomUpTreeSimilarityCalculator(BottomUpTreeSimilarityCalculator original, Cloner cloner)
    4450      : base(original, cloner) {
    4551    }
     
    5763
    5864      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);
    5973    }
    6074
     
    187201    }
    188202
     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>
    189209    private IEnumerable<ISymbolicExpressionTreeNode> IterateBreadthOrdered(ISymbolicExpressionTreeNode node) {
    190210      var list = new List<ISymbolicExpressionTreeNode> { node };
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs

    r11230 r11239  
    5656    }
    5757
    58     public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, SymbolicExpressionTreeNodeSimilarityComparer comparer) {
     58    public static double MaxCommonSubtreeSimilarity(ISymbolicExpressionTree a, ISymbolicExpressionTree b, ISymbolicExpressionTreeNodeSimilarityComparer comparer) {
    5959      int max = 0;
    6060      var rootA = a.Root.GetSubtree(0).GetSubtree(0);
Note: See TracChangeset for help on using the changeset viewer.