Exemple #1
0
        public void ComputeHashTest()
        {
            int[][] perms = new[] { new[] { 1, 4, 8 }, new[] { 2, 3, 8 }, new[] { 7, 9, 0 } };
            permutations.Setup(perm => perm.GetPermutations()).Returns(perms);

            byte[] hashed = minHashService.Hash(new TinyFingerprintSchema(10).SetTrueAt(2, 4, 6), perms.Length);

            Assert.AreEqual(1, hashed[0]);
            Assert.AreEqual(0, hashed[1]);
            Assert.AreEqual(255, hashed[2]);
        }
Exemple #2
0
        public void ComputeHashTest()
        {
            var perms          = new TestPermutations();
            var minHashService = new MinHashService(perms);

            byte[] hashed = minHashService.Hash(new TinyFingerprintSchema(10).SetTrueAt(2, 4, 6), perms.GetPermutations().Length);

            Assert.AreEqual(1, hashed[0]);
            Assert.AreEqual(0, hashed[1]);
            Assert.AreEqual(255, hashed[2]);
        }
Exemple #3
0
        public void ComputeHashTest()
        {
            int[][] perms = new[] { new[] { 1, 4, 8 }, new[] { 2, 3, 8 }, new[] { 7, 9, 0 } };
            permutations.Setup(perm => perm.GetPermutations()).Returns(perms);

            bool[] fingerprint = new[] { false, false, true, false, true, false, true, false, false, false };

            byte[] hashed = minHashService.Hash(fingerprint);

            Assert.AreEqual(1, hashed[0]);
            Assert.AreEqual(0, hashed[1]);
            Assert.AreEqual(255, hashed[2]);
        }
Exemple #4
0
        public void ShouldNotIdentifyTooManyHashesOnLastPosition()
        {
            var random       = new Random(1);
            var permutations = new MaxEntropyPermutations();
            var minHash      = new MinHashService(permutations);
            var counts       = new List <int>();
            int maxIndex     = permutations.GetPermutations().First().Length;

            Assert.AreEqual(255, maxIndex);
            for (int i = 0; i < 50000; ++i)
            {
                var    schema = TestUtilities.GenerateRandomFingerprint(random, 200, 128, 32);
                byte[] hashes = minHash.Hash(schema, 25 * 4);
                int    count  = hashes.Count(last => last == maxIndex);
                counts.Add(count);
            }

            Console.WriteLine($"Avg. Permutations {counts.Average():0.000}");
            Console.WriteLine($"Max. {counts.Max()}");
            Console.WriteLine($"Min. {counts.Min()}");
            Assert.IsTrue(counts.Average() <= 0.25, "On average we expect no more than 0.25 elements in the schema to contain hashes at last position");
        }