/// <summary>
 ///   Query one specific song using MinHash algorithm. ConnectionString is set by the caller.
 /// </summary>
 /// <param name = "signatures">Fingerprint signatures from a song</param>
 /// <param name = "dalManager">DAL Manager used to query the underlying database</param>
 /// <param name = "permStorage">Permutation storage</param>
 /// <param name = "seconds">Fingerprints to consider as query points [1.4 sec * N]</param>
 /// <param name = "lHashTables">Number of hash tables from the database</param>
 /// <param name = "lGroupsPerKey">Number of groups per hash table</param>
 /// <param name = "thresholdTables">Threshold percentage [0.07 for 20 LHash Tables, 0.17 for 25 LHashTables]</param>
 /// <param name = "queryTime">Set but the method, representing the query length</param>
 /// <returns>Dictionary with Tracks ID's and the Query Statistics</returns>
 public static Dictionary<Int32, QueryStats> QueryOneSongMinHash(
     IEnumerable<bool[]> signatures,
     DaoGateway dalManager,
     IPermutations permStorage,
     int seconds,
     int lHashTables,
     int lGroupsPerKey,
     int thresholdTables,
     ref long queryTime)
 {
     Stopwatch stopWatch = new Stopwatch();
     stopWatch.Start();
     Dictionary<Int32, QueryStats> stats = new Dictionary<Int32, QueryStats>();
     MinHash minHash = new MinHash(permStorage);
     foreach (bool[] f in signatures)
     {
         if (f == null) continue;
         int[] bin = minHash.ComputeMinHashSignature(f); /*Compute Min Hash on randomly selected fingerprints*/
         Dictionary<int, long> hashes = minHash.GroupMinHashToLSHBuckets(bin, lHashTables, lGroupsPerKey); /*Find all candidates by querying the database*/
         long[] hashbuckets = hashes.Values.ToArray();
         Dictionary<int, List<HashBinMinHash>> candidates = dalManager.ReadFingerprintsByHashBucketLSH(hashbuckets);
         Dictionary<int, List<HashBinMinHash>> potentialCandidates = SelectPotentialMatchesOutOfEntireDataset(candidates, thresholdTables);
         if (potentialCandidates.Count > 0)
         {
             List<Fingerprint> fingerprints = dalManager.ReadFingerprintById(potentialCandidates.Keys);
             Dictionary<Fingerprint, int> fCandidates = new Dictionary<Fingerprint, int>();
             foreach (Fingerprint finger in fingerprints)
                 fCandidates.Add(finger, potentialCandidates[finger.Id].Count);
             ArrangeCandidatesAccordingToFingerprints(f, fCandidates, lHashTables, lGroupsPerKey, stats);
         }
     }
     stopWatch.Stop();
     queryTime = stopWatch.ElapsedMilliseconds; /*Set the query Time parameter*/
     return stats;
 }
Exemplo n.º 2
0
 /// <summary>
 ///   Each repository should have storage for permutations and for tracks/fingerprints
 /// </summary>
 /// <param name = "storage">Track/Signatures storage</param>
 /// <param name = "permutations">Permutations storage</param>
 public Repository(IStorage storage, IPermutations permutations)
 {
     _permutations = permutations;
     _storage = storage;
     _manager = new FingerprintManager();
     _hasher = new MinHash(_permutations);
 }
Exemplo n.º 3
0
 public Repository(IPermutations permutations, DatabaseService dbService, FingerprintService fingerprintService)
 {
     this.permutations = permutations;
     this.minHash = new MinHash(this.permutations);
     this.dbService = dbService;
     this.fingerprintService = fingerprintService;
 }
Exemplo n.º 4
0
        private static int MAX_SIGNATURE_COUNT = 5;         // the number of signatures to reduce to

        public Repository(IPermutations permutations, DatabaseService dbService, FingerprintService fingerprintService)
        {
            this.permutations       = permutations;
            this.minHash            = new MinHash(this.permutations);
            this.dbService          = dbService;
            this.fingerprintService = fingerprintService;
        }
 public WinEnsembleHash(IFingerprintService fingerprintService)
 {
     this.fingerprintService = fingerprintService;
     InitializeComponent();
     Icon = Resources.Sound;
     permutations = new DbPermutations(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);
 }
 /// <summary>
 ///   Each repository should have storage for permutations and for tracks/fingerprints
 /// </summary>
 /// <param name = "storage">Track/Signatures storage</param>
 /// <param name = "permutations">Permutations storage</param>
 public Repository(IStorage storage, IPermutations permutations)
 {
     _permutations = permutations;
     _storage      = storage;
     _manager      = new FingerprintManager();
     _hasher       = new MinHash(_permutations);
 }
Exemplo n.º 7
0
 public Repository(IFingerprintService fingerprintService, IWorkUnitBuilder workUnitBuilder, IStorage storage, IPermutations permutations)
 {
     this.permutations = permutations;
     this.storage = storage;
     service = fingerprintService;
     this.workUnitBuilder = workUnitBuilder;
     hasher = new MinHash(this.permutations);
 }
Exemplo n.º 8
0
        /// <summary>
        ///   Public constructor
        /// </summary>
        /// <param name = "storage">
        ///   Permutations storage
        /// </param>
        public MinHash(IPermutations storage)
        {
            _permutations = storage.GetPermutations();

            if (_permutations == null || _permutations.GetLength(0) == 0)
                throw new Exception("Permutations are null or not enough to create the Min Hash signature");

            _permutationsCount = _permutations.GetLength(0);
        }
Exemplo n.º 9
0
        /// <summary>
        ///   Public constructor
        /// </summary>
        /// <param name = "permutations">Storage from which to read the permutations</param>
        public MinHash(IPermutations permutations)
        {
            _permutations = permutations.GetPermutations(); /*Read the permutation from the database*/

            if (_permutations == null || _permutations.Length == 0)
                throw new Exception("Permutations are null or not enough to create the Min Hash signature");

            _permutationsCount = _permutations.Length;
        }
 public RepositoryGateway()
 {
     _storage      = new RamStorage(NUMBER_OF_HASH_TABLES);                  /*Number of LSH Tables, used for storage purposes*/
     _permutations = new LocalPermutations(PATH_TO_PERMUTATIONS, SEPARATOR); /*Permutations*/
     _repository   = new Repository(_storage, _permutations);
     _proxy        = new BassProxy();                                        /*audio proxy used in reading the file*/
     _createStride = new IncrementalStaticStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT);
     _queryStride  = new IncrementalRandomStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT, SAMPLES_IN_FINGERPRINT);
 }
Exemplo n.º 11
0
        public MinHash(IPermutations permutations)
        {
            this.permutations = permutations.GetPermutations();             /*Read the permutation from the database*/

            if (this.permutations == null || this.permutations.Length == 0)
            {
                throw new Exception("Permutations are null or not enough to create the Min Hash signature");
            }

            permutationsCount = this.permutations.Length;
        }
        /// <summary>
        ///   Public constructor
        /// </summary>
        /// <param name = "storage">
        ///   Permutations storage
        /// </param>
        public MinHash(IPermutations storage)
        {
            _permutations = storage.GetPermutations();

            if (_permutations == null || _permutations.GetLength(0) == 0)
            {
                throw new Exception("Permutations are null or not enough to create the Min Hash signature");
            }

            _permutationsCount = _permutations.GetLength(0);
        }
Exemplo n.º 13
0
        static async Task Main()
        {

            var services = new ServiceCollection()
                .AddSingleton<IPermutations, Permutations>();

            ServiceProvider serviceProvider = services.BuildServiceProvider();

            IPermutations permutations = serviceProvider.GetService<IPermutations>();

            await permutations.Run();
        }
Exemplo n.º 14
0
 /// <summary>
 ///   Public parameter less constructor
 /// </summary>
 public WinEnsembleHash()
 {
     InitializeComponent();
     Icon = Resources.Sound;
     _permutations = new DbPermutations(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);
 }
Exemplo n.º 15
0
 public MinHashService(IPermutations permutations)
 {
     this.permutations = permutations;
 }
        public RepositoryGateway()
        {
            storage =
                ServiceContainer.Kernel.Get<IStorage>(
                    new ConstructorArgument("numberOfHashTables", NumberOfHashTables));
                /*Number of LSH Tables, used for storage purposes*/

            permutations =
                ServiceContainer.Kernel.Get<IPermutations>(
                    new ConstructorArgument("pathToPermutations", PathToPermutations),
                    new ConstructorArgument("separator", Separator)); /*Permutations*/

            cts = new CancellationTokenSource();
            repository = new Repository(ServiceContainer.Kernel.Get<IFingerprintService>(), ServiceContainer.Kernel.Get<IWorkUnitBuilder>(), storage, permutations);
            createStride = new IncrementalStaticStride(StrideSizeIncremental, SamplesInFingerprint);
        }
 public CachedPermutations(IPermutations permutations)
 {
     this.permutations = permutations;
 }
 internal MinHashService(IPermutations permutations)
 {
     this.permutations = permutations;
 }
Exemplo n.º 19
0
 internal MinHashService(IPermutations permutations)
 {
     this.permutations = permutations;
 }
Exemplo n.º 20
0
 private MinHashService(IPermutations permutations)
 {
     this.permutations = permutations;
 }
Exemplo n.º 21
0
 public RepositoryGateway()
 {
     _storage = new RamStorage(NUMBER_OF_HASH_TABLES); /*Number of LSH Tables, used for storage purposes*/
     _permutations = new LocalPermutations(PATH_TO_PERMUTATIONS, SEPARATOR); /*Permutations*/
     _repository = new Repository(_storage, _permutations);
     _proxy = new BassProxy(); /*audio proxy used in reading the file*/
     _createStride = new IncrementalStaticStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT);
     _queryStride = new IncrementalRandomStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT, SAMPLES_IN_FINGERPRINT);
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="WinQueryResults"/> class. 
        ///   Protected constructor of WinQueryResults class
        /// </summary>
        /// <param name="connectionString">
        /// Connection string used for the underlying data source
        /// </param>
        /// <param name="secondsToAnalyze">
        /// Number of consequent fingerprints to analyze
        /// </param>
        /// <param name="startSecond">
        /// Starting seconds
        /// </param>
        /// <param name="stride">
        /// Stride used in the query
        /// </param>
        /// <param name="topWavelets">
        /// Number of top wavelets to analyze
        /// </param>
        /// <param name="fileList">
        /// List of all files to be recognized
        /// </param>
        protected WinQueryResults(
            string connectionString,
            int secondsToAnalyze,
            int startSecond,
            IStride stride,
            int topWavelets,
            List<string> fileList)
        {
            InitializeComponent(); /*Initialize Designer Components*/
            Icon = Resources.Sound;
            this.connectionString = connectionString;
            dalManager = new DaoGateway(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);
            permStorage = new DbPermutations(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);

            dalManager.SetConnectionString(this.connectionString); /*Set connection string for DAL service*/
            this.secondsToAnalyze = secondsToAnalyze; /*Number of fingerprints to analyze from each song*/
            this.startSecond = startSecond;
            this.fileList = fileList; /*List of files to analyze*/
            _dgvResults.Columns.Add(ColSongName, "Initial Song");
            _dgvResults.Columns[ColSongName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            _dgvResults.Columns.Add(ColResultName, "Result Song");
            _dgvResults.Columns[ColResultName].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            _dgvResults.Columns.Add(ColPosition, "Position");
            _dgvResults.Columns[ColPosition].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            _dgvResults.Columns.Add(ColResult, "Result");
            _dgvResults.Columns[ColResult].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            _dgvResults.Columns.Add(ColHammingAvg, "Hamming Avg.");
            _dgvResults.Columns[ColHammingAvg].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
            queryStride = stride;
        }
Exemplo n.º 23
0
 public ExtendedMinHashService(IPermutations permutations)
 {
     this.permutations = permutations;
 }
Exemplo n.º 24
0
 /// <summary>
 ///   Protected constructor of WinQueryResults class
 /// </summary>
 /// <param name = "connectionString">Connection string used for the underlying data source</param>
 /// <param name = "secondsToAnalyze">Number of consequent fingerprints to analyze</param>
 /// <param name = "startSecond">Starting seconds</param>
 /// <param name = "stride">Stride used in the query</param>
 /// <param name = "topWavelets">Number of top wavelets to analyze</param>
 /// <param name = "fileList">List of all files to be recognized</param>
 protected WinQueryResults(string connectionString, int secondsToAnalyze, int startSecond,
                           IStride stride, int topWavelets, List<string> fileList)
 {
     InitializeComponent(); /*Initialize Designer Components*/
     Icon = Resources.Sound;
     _connectionString = connectionString;
     _topWavelets = topWavelets;
     _dalManager = new DaoGateway(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);
     _permStorage = new DbPermutations(ConfigurationManager.ConnectionStrings["FingerprintConnectionString"].ConnectionString);
     _manager = new FingerprintManager {TopWavelets = topWavelets};
     _dalManager.SetConnectionString(_connectionString); /*Set connection string for DAL manager*/
     _secondsToAnalyze = secondsToAnalyze; /*Number of fingerprints to analyze from each song*/
     _startSecond = startSecond;
     _fileList = fileList; /*List of files to analyze*/
     _dgvResults.Columns.Add(COL_SONG_NAME, "Initial Song");
     _dgvResults.Columns[COL_SONG_NAME].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     _dgvResults.Columns.Add(COL_RESULT_NAME, "Result Song");
     _dgvResults.Columns[COL_RESULT_NAME].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     _dgvResults.Columns.Add(COL_POSITION, "Position");
     _dgvResults.Columns[COL_POSITION].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     _dgvResults.Columns.Add(COL_RESULT, "Result");
     _dgvResults.Columns[COL_RESULT].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     _dgvResults.Columns.Add(COL_HAMMING_AVG, "Hamming Avg.");
     _dgvResults.Columns[COL_HAMMING_AVG].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
     _queryStride = stride;
 }
Exemplo n.º 25
0
        /// <summary>
        ///   Repository gateway parameter less constructor
        /// </summary>
        public RepositoryGateway()
        {
            _storage = ServiceContainer.Kernel.Get<IStorage>(new ConstructorArgument("numberOfHashTables", NUMBER_OF_HASH_TABLES)); /*Number of LSH Tables, used for storage purposes*/

            _permutations = ServiceContainer.Kernel.Get<IPermutations>(new ConstructorArgument("pathToPermutations", PATH_TO_PERMUTATIONS),
                new ConstructorArgument("separator", SEPARATOR)); /*Permutations*/

            _cts = new CancellationTokenSource();
            _repository = new Repository(_storage, _permutations);
            _createStride = new IncrementalStaticStride(STRIDE_SIZE_INCREMENTAL, SAMPLES_IN_FINGERPRINT);
        }
 public CachedPermutations(IPermutations permutations)
 {
     this.permutations = permutations;
 }
 public void SetUp()
 {
     modelService = new ModelService(new MsSqlDatabaseProviderFactory(new DefaultConnectionStringFactory()), new ModelBinderFactory());
     fingerprintService = new FingerprintService(new FingerprintDescriptor(), new SpectrumService(new CachedFFTWService(new FFTWService86())), new WaveletService(new StandardHaarWaveletDecomposition()));
     defaultConfiguration = new DefaultFingerprintingConfiguration();
     var mockedPermutations = new Mock<IPermutations>();
     mockedPermutations.Setup(perms => perms.GetPermutations()).Returns(new int[1][]);
     permutations = mockedPermutations.Object;
     fingerprintUnitBuilderWithBass = new FingerprintUnitBuilder(fingerprintService, new BassAudioService(), new MinHashService(permutations));
     #pragma warning disable 612,618
     fingerprintUnitBuilderWithDirectSound = new FingerprintUnitBuilder(fingerprintService, new DirectSoundAudioService(), new MinHashService(permutations));
     #pragma warning restore 612,618
 }