Changeset 16263
- Timestamp:
- 10/30/18 13:08:01 (6 years ago)
- Location:
- trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Analyzers/SymbolicDataAnalysisBuildingBlockAnalyzer.cs
r16259 r16263 41 41 private const string SimplifyTreesParameterName = "SimplifyTrees"; 42 42 43 private Dictionary< int, DataRow> hashToRow = new Dictionary<int, DataRow>();43 private Dictionary<ulong, DataRow> hashToRow = new Dictionary<ulong, DataRow>(); 44 44 45 45 #region parameters … … 66 66 base.InitializeState(); 67 67 68 hashToRow = new Dictionary< int, DataRow>();68 hashToRow = new Dictionary<ulong, DataRow>(); 69 69 } 70 70 … … 104 104 var simplify = SimplifyTrees.Value; 105 105 106 var expressions = new Dictionary< int, string>();107 var expressionCounts = new Dictionary< int, int>();106 var expressions = new Dictionary<ulong, string>(); 107 var expressionCounts = new Dictionary<ulong, int>(); 108 108 109 109 int totalCount = 0; // total number of examined subtrees -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashExtensions.cs
r16261 r16263 32 32 33 33 public bool Enabled; 34 public intHashValue; // the initial (fixed) hash value for this individual node/data35 public intCalculatedHashValue; // the calculated hash value (taking into account the children hash values)34 public ulong HashValue; // the initial (fixed) hash value for this individual node/data 35 public ulong CalculatedHashValue; // the calculated hash value (taking into account the children hash values) 36 36 37 37 public Action<HashNode<T>[], int> Simplify; … … 67 67 68 68 public override int GetHashCode() { 69 return CalculatedHashValue; 69 //return CalculatedHashValue; 70 return Data.GetHashCode(); 70 71 } 71 72 … … 79 80 } 80 81 81 public static intComputeHash<T>(this HashNode<T>[] nodes, int i) where T : class {82 public static ulong ComputeHash<T>(this HashNode<T>[] nodes, int i) where T : class { 82 83 var node = nodes[i]; 83 var hashes = new int[node.Arity + 1];84 var hashes = new ulong[node.Arity + 1]; 84 85 for (int j = i - 1, k = 0; k < node.Arity; j -= 1 + nodes[j].Size, k++) { 85 86 hashes[k] = nodes[j].CalculatedHashValue; -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/HashUtil.cs
r16261 r16263 20 20 #endregion 21 21 22 using System;23 using System.Security.Cryptography;24 22 25 23 namespace HeuristicLab.Problems.DataAnalysis.Symbolic { … … 28 26 29 27 // A simple hash function from Robert Sedgwicks Algorithms in C book.I've added some simple optimizations to the algorithm in order to speed up its hashing process. 30 public static int RSHash(int[] input) {28 public static ulong RSHash(ulong[] input) { 31 29 const int b = 378551; 32 inta = 63689;33 inthash = 0;30 ulong a = 63689; 31 ulong hash = 0; 34 32 35 33 foreach (var v in input) { … … 41 39 42 40 // A bitwise hash function written by Justin Sobel 43 public static int JSHash(int[] input) {44 inthash = 1315423911;41 public static ulong JSHash(ulong[] input) { 42 ulong hash = 1315423911; 45 43 for (int i = 0; i < input.Length; ++i) 46 44 hash ^= (hash << 5) + input[i] + (hash >> 2); … … 49 47 50 48 // This hash function comes from Brian Kernighan and Dennis Ritchie's book "The C Programming Language". It is a simple hash function using a strange set of possible seeds which all constitute a pattern of 31....31...31 etc, it seems to be very similar to the DJB hash function. 51 public static int BKDRHash(int[] input) {52 const intseed = 131;53 inthash = 0;49 public static ulong BKDRHash(ulong[] input) { 50 ulong seed = 131; 51 ulong hash = 0; 54 52 foreach (var v in input) { 55 53 hash = (hash * seed) + v; … … 59 57 60 58 // This is the algorithm of choice which is used in the open source SDBM project. The hash function seems to have a good over-all distribution for many different data sets. It seems to work well in situations where there is a high variance in the MSBs of the elements in a data set. 61 public static int SDBMHash(int[] input) {62 inthash = 0;59 public static ulong SDBMHash(ulong[] input) { 60 ulong hash = 0; 63 61 foreach (var v in input) { 64 62 hash = v + (hash << 6) + (hash << 16) - hash; … … 68 66 69 67 // An algorithm produced by Professor Daniel J. Bernstein and shown first to the world on the usenet newsgroup comp.lang.c. It is one of the most efficient hash functions ever published. 70 public static int DJBHash(int[] input) {71 inthash = 5381;68 public static ulong DJBHash(ulong[] input) { 69 ulong hash = 5381; 72 70 foreach (var v in input) { 73 71 hash = (hash << 5) + hash + v; … … 77 75 78 76 // An algorithm proposed by Donald E.Knuth in The Art Of Computer Programming Volume 3, under the topic of sorting and search chapter 6.4. 79 public static int DEKHash(int[] input) {80 int hash =input.Length;77 public static ulong DEKHash(ulong[] input) { 78 ulong hash = (ulong)input.Length; 81 79 foreach (var v in input) { 82 80 hash = (hash << 5) ^ (hash >> 27) ^ v; … … 85 83 } 86 84 87 public static int CryptoHash(HashAlgorithm ha, int[] input) {88 return BitConverter.ToInt32(ha.ComputeHash(input.ToByteArray()), 0);89 }85 //public static ulong CryptoHash(HashAlgorithm ha, ulong[] input) { 86 // return BitConverter.ToInt32(ha.ComputeHash(input.ToByteArray()), 0); 87 //} 90 88 91 public static byte[] ToByteArray(this int[] input) {92 var bytes = new byte[input.Length * sizeof(int)];93 int pos = 0;94 foreach (var v in input) {95 var b0 = (byte)((v >> 24) & 0xFF);96 var b1 = (byte)((v >> 16) & 0xFF);97 var b2 = (byte)((v >> 8) & 0xFF);98 var b3 = (byte)(v & 0xFF);99 bytes[pos++] = b0;100 bytes[pos++] = b1;101 bytes[pos++] = b2;102 bytes[pos++] = b3;103 }104 return bytes;105 }89 //public static byte[] ToByteArray(this ulong[] input) { 90 // var bytes = new byte[input.Length * sizeof(int)]; 91 // int pos = 0; 92 // foreach (var v in input) { 93 // var b0 = (byte)((v >> 24) & 0xFF); 94 // var b1 = (byte)((v >> 16) & 0xFF); 95 // var b2 = (byte)((v >> 8) & 0xFF); 96 // var b3 = (byte)(v & 0xFF); 97 // bytes[pos++] = b0; 98 // bytes[pos++] = b1; 99 // bytes[pos++] = b2; 100 // bytes[pos++] = b3; 101 // } 102 // return bytes; 103 //} 106 104 } 107 105 } -
trunk/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Hashing/SymbolicExpressionTreeHash.cs
r16255 r16263 39 39 private static readonly ISymbolicExpressionTreeNodeComparer comparer = new SymbolicExpressionTreeNodeComparer(); 40 40 41 public static intComputeHash(this ISymbolicExpressionTree tree) {41 public static ulong ComputeHash(this ISymbolicExpressionTree tree) { 42 42 return ComputeHash(tree.Root.GetSubtree(0).GetSubtree(0)); 43 43 } 44 44 45 45 // compute node hashes without sorting the arguments 46 public static Dictionary<ISymbolicExpressionTreeNode, int> ComputeNodeHashes(this ISymbolicExpressionTree tree) {46 public static Dictionary<ISymbolicExpressionTreeNode, ulong> ComputeNodeHashes(this ISymbolicExpressionTree tree) { 47 47 var root = tree.Root.GetSubtree(0).GetSubtree(0); 48 48 var nodes = root.MakeNodes(); … … 57 57 } 58 58 59 public static intComputeHash(this ISymbolicExpressionTreeNode treeNode) {59 public static ulong ComputeHash(this ISymbolicExpressionTreeNode treeNode) { 60 60 var hashNodes = treeNode.MakeNodes(); 61 61 var simplified = hashNodes.Simplify(); 62 return ComputeHash(simplified); 63 } 64 65 public static int ComputeHash(this HashNode<ISymbolicExpressionTreeNode>[] nodes) { 66 int hash = 1315423911; 67 foreach (var node in nodes) 68 hash ^= (hash << 5) + node.CalculatedHashValue + (hash >> 2); 69 return hash; 70 } 62 //return ComputeHash(simplified); 63 return simplified.Last().CalculatedHashValue; 64 } 65 66 //public static int ComputeHash(this HashNode<ISymbolicExpressionTreeNode>[] nodes) { 67 // int hash = 1315423911; 68 // foreach (var node in nodes) 69 // hash ^= (hash << 5) + node.CalculatedHashValue + (hash >> 2); 70 // return hash; 71 //} 71 72 72 73 public static HashNode<ISymbolicExpressionTreeNode> ToHashNode(this ISymbolicExpressionTreeNode node) { … … 77 78 name = variableTreeNode.VariableName; 78 79 } 79 var hash = name.GetHashCode();80 var hash = (ulong)name.GetHashCode(); 80 81 var hashNode = new HashNode<ISymbolicExpressionTreeNode>(comparer) { 81 82 Data = node,
Note: See TracChangeset
for help on using the changeset viewer.