Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/05/19 10:26:41 (5 years ago)
Author:
gkronber
Message:

#2950: made some small changes while reviewing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs

    r16983 r17076  
    4848      ulong hashFunction(byte[] input) => HashUtil.DJBHash(input);
    4949
    50       var hashNodes = simplify ? node.MakeNodes(strict).Simplify(hashFunction) : node.MakeNodes(strict).Sort(hashFunction);
     50      var hashNodes = simplify ? node.MakeNodes(strict).Simplify(hashFunction) : node.MakeNodes(strict).Sort(hashFunction); // simplify sorts implicitly
    5151      var hashes = new ulong[hashNodes.Length];
    5252      for (int i = 0; i < hashes.Length; ++i) {
     
    210210      var treeNodes = nodes.Select(x => x.Data.Symbol.CreateTreeNode()).ToArray();
    211211
     212      // construct tree top down (assumes postfix order for nodes)
    212213      for (int i = nodes.Length - 1; i >= 0; --i) {
    213214        var node = nodes[i];
     
    244245    // (in other words simplification should be applied in a bottom-up fashion)
    245246    public static ISymbolicExpressionTree Simplify(ISymbolicExpressionTree tree) {
    246       ulong hashFunction(byte[] bytes) => HashUtil.JSHash(bytes);
    247       var root = tree.Root.GetSubtree(0).GetSubtree(0);
     247      ulong hashFunction(byte[] bytes) => HashUtil.DJBHash(bytes);
     248      var root = tree.ActualRoot();
    248249      var nodes = root.MakeNodes();
    249250      var simplified = nodes.Simplify(hashFunction);
     
    369370        nodes[i].Enabled = false;
    370371      } else if ((parentSymbol is Exponential && childSymbol is Logarithm) || (parentSymbol is Logarithm && childSymbol is Exponential)) {
     372        // exp(log(x)) == x only for positive x. We consider this as equivalent for hashing anyway.
    371373        child.Enabled = parent.Enabled = false;
    372374      }
Note: See TracChangeset for help on using the changeset viewer.