- Timestamp:
- 12/15/21 11:50:57 (3 years ago)
- Location:
- trunk
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol (added) merged: 18091,18093,18100,18112-18121,18123-18131
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic
- Property svn:mergeinfo changed
/branches/3140_NumberSymbol/HeuristicLab.Problems.DataAnalysis.Symbolic (added) merged: 18093,18100,18112-18116,18118,18121,18123-18124,18129-18130
- Property svn:mergeinfo changed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeBottomUpSimilarityCalculator.cs
r17180 r18132 41 41 protected override bool IsCommutative { get { return true; } } 42 42 43 public bool Match ConstantValues { get; set; }43 public bool MatchParameterValues { get; set; } 44 44 public bool MatchVariableWeights { get; set; } 45 45 … … 66 66 67 67 public static double CalculateSimilarity(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) { 68 var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchConstantValues = strict, MatchVariableWeights = strict };69 68 return CalculateSimilarity(n1, n2, strict); 70 69 } 71 70 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) { 73 72 return ComputeBottomUpMapping(ActualRoot(t1), ActualRoot(t2), strict); 74 73 } 75 74 76 public static Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) {77 var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { Match ConstantValues = strict, MatchVariableWeights = strict };75 public static NodeMap ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2, bool strict = false) { 76 var calculator = new SymbolicExpressionTreeBottomUpSimilarityCalculator { MatchParameterValues = strict, MatchVariableWeights = strict }; 78 77 return calculator.ComputeBottomUpMapping(n1, n2); 79 78 } … … 81 80 82 81 public double CalculateSimilarity(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 83 return CalculateSimilarity(t1, t2, out Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> map);82 return CalculateSimilarity(t1, t2, out _); 84 83 } 85 84 … … 110 109 } 111 110 112 public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) {111 public NodeMap ComputeBottomUpMapping(ISymbolicExpressionTree t1, ISymbolicExpressionTree t2) { 113 112 return ComputeBottomUpMapping(ActualRoot(t1), ActualRoot(t2)); 114 113 } 115 114 116 public Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) {115 public NodeMap ComputeBottomUpMapping(ISymbolicExpressionTreeNode n1, ISymbolicExpressionTreeNode n2) { 117 116 var compactedGraph = Compact(n1, n2); 118 117 … … 211 210 return node.Symbol.Name; 212 211 213 if (node is ConstantTreeNode constant)214 return Match ConstantValues ? constant.Value.ToString(CultureInfo.InvariantCulture) : constant.Symbol.Name;212 if (node is INumericTreeNode numNode) 213 return MatchParameterValues ? numNode.Value.ToString(CultureInfo.InvariantCulture) : "Numeric"; 215 214 216 215 if (node is VariableTreeNode variable) -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator.cs
r17180 r18132 38 38 } 39 39 40 public bool Match ConstantValues {41 get { return comparer.Match ConstantValues; }42 set { comparer.Match ConstantValues = value; }40 public bool MatchParameterValues { 41 get { return comparer.MatchParameterValues; } 42 set { comparer.MatchParameterValues = value; } 43 43 } 44 44 … … 59 59 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator() { 60 60 comparer = new SymbolicExpressionTreeNodeEqualityComparer { 61 Match ConstantValues = true,61 MatchParameterValues = true, 62 62 MatchVariableNames = true, 63 63 MatchVariableWeights = true … … 65 65 } 66 66 67 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool match ConstantValues) {67 public SymbolicExpressionTreeMaxCommonSubtreeSimilarityCalculator(bool matchVariableWeights, bool matchParameterValues) { 68 68 comparer = new SymbolicExpressionTreeNodeEqualityComparer { 69 Match ConstantValues = matchConstantValues,69 MatchParameterValues = matchParameterValues, 70 70 MatchVariableNames = true, 71 71 MatchVariableWeights = matchVariableWeights -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeComparer.cs
r17180 r18132 28 28 // this comparer considers that a < b if the type of a is "greater" than the type of b, for example: 29 29 // - A function node is "greater" than a terminal node 30 // - A variable terminal is "greater" than a constantterminal30 // - A variable terminal is "greater" than a numeric terminal 31 31 // - used for bringing subtrees to a "canonical" form when the operation allows reordering of arguments 32 32 public class SymbolicExpressionTreeNodeComparer : ISymbolicExpressionTreeNodeComparer { … … 52 52 53 53 // 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; 56 56 57 57 if (ca != null && cb != null) -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/TreeMatching/SymbolicExpressionTreeNodeEqualityComparer.cs
r17180 r18132 33 33 protected SymbolicExpressionTreeNodeEqualityComparer(SymbolicExpressionTreeNodeEqualityComparer original, Cloner cloner) 34 34 : base(original, cloner) { 35 match ConstantValues = original.matchConstantValues;35 matchParameterValues = original.matchParameterValues; 36 36 matchVariableNames = original.matchVariableNames; 37 37 matchVariableWeights = original.matchVariableWeights; … … 41 41 // more flexible matching criteria 42 42 [Storable] 43 private bool match ConstantValues;44 public bool Match ConstantValues {45 get { return match ConstantValues; }46 set { match ConstantValues = value; }43 private bool matchParameterValues; 44 public bool MatchParameterValues { 45 get { return matchParameterValues; } 46 set { matchParameterValues = value; } 47 47 } 48 48 … … 66 66 67 67 public SymbolicExpressionTreeNodeEqualityComparer() { 68 match ConstantValues = true;68 matchParameterValues = true; 69 69 matchVariableNames = true; 70 70 matchVariableWeights = true; … … 86 86 return (!MatchVariableNames || va.VariableName.Equals(vb.VariableName)) && (!MatchVariableWeights || va.Weight.Equals(vb.Weight)); 87 87 } 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; 91 91 if (cb == null) return false; 92 return (!Match ConstantValues || ca.Value.Equals(cb.Value));92 return (!MatchParameterValues || ca.Value.Equals(cb.Value)); 93 93 } 94 94 return false;
Note: See TracChangeset
for help on using the changeset viewer.