Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/15/21 11:50:57 (3 years ago)
Author:
gkronber
Message:

#3140: merged r18091:18131 from branch to trunk

Location:
trunk
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic

  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs

    r17180 r18132  
    4141    protected override bool IsCommutative { get { return true; } }
    4242
    43     public bool MatchConstantValues { get; set; }
     43    public bool MatchParameterValues { get; set; }
    4444    public bool MatchVariableWeights { get; set; }
    4545
     
    6666
    6767    public static double CalculateSimilarity(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) {
    68       var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchConstantValues = strict, MatchVariableWeights = strict };
    6968      return CalculateSimilarity(n1, n2, strict);
    7069    }
    7170
    72     public static Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, bool strict = false) {
     71    public static NodeMap ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2, bool strict = false) {
    7372      return ComputeBottomUpMapping(ActualRoot(t1), ActualRoot(t2), strict);
    7473    }
    7574
    76     public static Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) {
    77       var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchConstantValues = strict, MatchVariableWeights = strict };
     75    public static NodeMap ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) {
     76      var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchParameterValues = strict, MatchVariableWeights = strict };
    7877      return calculator.ComputeBottomUpMapping(n1, n2);
    7978    }
     
    8180
    8281    public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
    83       return CalculateSimilarity(t1, t2, out Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> map);
     82      return CalculateSimilarity(t1, t2, out _);
    8483    }
    8584
     
    110109    }
    111110
    112     public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
     111    public NodeMap ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {
    113112      return ComputeBottomUpMapping(ActualRoot(t1), ActualRoot(t2));
    114113    }
    115114
    116     public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
     115    public NodeMap ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {
    117116      var compactedGraph = Compact(n1, n2);
    118117
     
    211210        return node.Symbol.Name;
    212211
    213       if (node is ConstantTreeNode constant)
    214         return MatchConstantValues ? constant.Value.ToString(CultureInfo.InvariantCulture) : constant.Symbol.Name;
     212      if (node is INumericTreeNode numNode)
     213        return MatchParameterValues ? numNode.Value.ToString(CultureInfo.InvariantCulture) : "Numeric";
    215214
    216215      if (node is VariableTreeNode variable)
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs

    r17180 r18132  
    3838    }
    3939
    40     public bool MatchConstantValues {
    41       get { return comparer.MatchConstantValues; }
    42       set { comparer.MatchConstantValues = value; }
     40    public bool MatchParameterValues {
     41      get { return comparer.MatchParameterValues; }
     42      set { comparer.MatchParameterValues = value; }
    4343    }
    4444
     
    5959    public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator() {
    6060      comparer = new SymbolicExpressionTreeNodeEqualityComparer {
    61         MatchConstantValues = true,
     61        MatchParameterValues = true,
    6262        MatchVariableNames = true,
    6363        MatchVariableWeights = true
     
    6565    }
    6666
    67     public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool matchConstantValues) {
     67    public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool matchParameterValues) {
    6868      comparer = new SymbolicExpressionTreeNodeEqualityComparer {
    69         MatchConstantValues = matchConstantValues,
     69        MatchParameterValues = matchParameterValues,
    7070        MatchVariableNames = true,
    7171        MatchVariableWeights = matchVariableWeights
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs

    r17180 r18132  
    2828  // this comparer considers that a < b if the type of a is "greater" than the type of b, for example:
    2929  // - A function node is "greater" than a terminal node
    30   // - A variable terminal is "greater" than a constant terminal
     30  // - A variable terminal is "greater" than a numeric terminal
    3131  // - used for bringing subtrees to a "canonical" form when the operation allows reordering of arguments
    3232  public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer {
     
    5252
    5353      // at this point we know a and b are not variables
    54       var ca = a as ConstantTreeNode;
    55       var cb = b as ConstantTreeNode;
     54      var ca = a as INumericTreeNode;
     55      var cb = b as INumericTreeNode;
    5656
    5757      if (ca != null && cb != null)
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs

    r17180 r18132  
    3333    protected SymbolicExpressionTreeNodeEqualityComparer(SymbolicExpressionTreeNodeEqualityComparer original, Cloner cloner)
    3434      : base(original, cloner) {
    35       matchConstantValues = original.matchConstantValues;
     35      matchParameterValues = original.matchParameterValues;
    3636      matchVariableNames = original.matchVariableNames;
    3737      matchVariableWeights = original.matchVariableWeights;
     
    4141    // more flexible matching criteria
    4242    [Storable]
    43     private bool matchConstantValues;
    44     public bool MatchConstantValues {
    45       get { return matchConstantValues; }
    46       set { matchConstantValues = value; }
     43    private bool matchParameterValues;
     44    public bool MatchParameterValues {
     45      get { return matchParameterValues; }
     46      set { matchParameterValues = value; }
    4747    }
    4848
     
    6666
    6767    public SymbolicExpressionTreeNodeEqualityComparer() {
    68       matchConstantValues = true;
     68      matchParameterValues = true;
    6969      matchVariableNames = true;
    7070      matchVariableWeights = true;
     
    8686        return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight));
    8787      }
    88       var ca = a as ConstantTreeNode;
    89       if (ca != null) {
    90         var cb = b as ConstantTreeNode;
     88
     89      if (a is INumericTreeNode ca) {
     90        var cb = b as INumericTreeNode;
    9191        if (cb == null) return false;
    92         return (!MatchConstantValues || ca.Value.Equals(cb.Value));
     92        return (!MatchParameterValues || ca.Value.Equals(cb.Value));
    9393      }
    9494      return false;
Note: See TracChangeset for help on using the changeset viewer.