Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11888


Ignore:
Timestamp:
02/04/15 15:17:22 (10 years ago)
Author:
bburlacu
Message:

#2215: MaxCommonSubtreeSimilarityCalculator: added properties for matching settings, added storable constructor, fixed bug in similarity calculation.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.BottomUpTreeDistance/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SimilarityCalculators/MaxCommonSubtreeSimilarityCalculator.cs

    r11239 r11888  
    3131  [Item("MaxCommonSubtreeSimilarityCalculator", "A similarity calculator based on the size of the maximum common subtree between two trees")]
    3232  public class MaxCommonSubtreeSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    33     public MaxCommonSubtreeSimilarityCalculator() { }
     33    [Storable]
     34    private readonly SymbolicExpressionTreeNodeSimilarityComparer comparer;
     35    public bool MatchVariableNames {
     36      get { return comparer.MatchVariableNames; }
     37      set { comparer.MatchVariableNames = value; }
     38    }
     39
     40    public bool MatchVariableWeights {
     41      get { return comparer.MatchVariableWeights; }
     42      set { comparer.MatchVariableWeights = value; }
     43    }
     44
     45    public bool MatchConstantValues {
     46      get { return comparer.MatchConstantValues; }
     47      set { comparer.MatchConstantValues = value; }
     48    }
     49
     50    [StorableConstructor]
     51    protected MaxCommonSubtreeSimilarityCalculator(bool deserializing) : base(deserializing) { }
     52
     53    public override IDeepCloneable Clone(Cloner cloner) {
     54      return new MaxCommonSubtreeSimilarityCalculator(this, cloner);
     55    }
    3456
    3557    protected MaxCommonSubtreeSimilarityCalculator(MaxCommonSubtreeSimilarityCalculator original, Cloner cloner)
     
    3759    }
    3860
    39     public override IDeepCloneable Clone(Cloner cloner) {
    40       return new MaxCommonSubtreeSimilarityCalculator(this, cloner);
     61    public MaxCommonSubtreeSimilarityCalculator() {
     62      comparer = new SymbolicExpressionTreeNodeSimilarityComparer {
     63        MatchConstantValues = true,
     64        MatchVariableNames = true,
     65        MatchVariableWeights = true
     66      };
     67    }
     68
     69    public MaxCommonSubtreeSimilarityCalculator(bool matchVariableNames, bool matchVariableWeights, bool matchConstantValues) {
     70      comparer = new SymbolicExpressionTreeNodeSimilarityComparer {
     71        MatchConstantValues = matchConstantValues,
     72        MatchVariableNames = matchVariableNames,
     73        MatchVariableWeights = matchVariableWeights
     74      };
     75    }
     76
     77    public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
     78      return MaxCommonSubtreeSimilarity(t1, t2, comparer);
    4179    }
    4280
     
    4785      if (t1 == null || t2 == null)
    4886        throw new ArgumentException("Cannot calculate similarity when one of the arguments is null.");
    49       var comparer = new SymbolicExpressionTreeNodeSimilarityComparer {
    50         MatchConstantValues = true,
    51         MatchVariableNames = true,
    52         MatchVariableWeights = true
    53       };
    5487
    5588      return MaxCommonSubtreeSimilarity(t1, t2, comparer);
     
    67100          if (lenB <= max) continue;
    68101          int matches = SymbolicExpressionTreeMatching.Match(aa, bb, comparer);
    69           if (matches == lenB && max < matches)
     102          if (max < matches)
    70103            max = matches;
    71104        }
Note: See TracChangeset for help on using the changeset viewer.