/// <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; }
public static Dictionary<Int32, QueryStats> QueryOneSongMinHashFast( string pathToSong, IStride queryStride, IAudioService proxy, DaoGateway dalManager, int seconds, int lshHashTables, int lshGroupsPerKey, int thresholdTables, int topWavelets, ref long queryTime) { ///*Fingerprint service*/ //fingerprintService service = new fingerprintService {TopWavelets = topWavelets}; //Stopwatch stopWatch = new Stopwatch(); //stopWatch.Start(); //int startIndex = -1; //Dictionary<Int32, QueryStats> stats = new Dictionary<Int32, QueryStats>(); //int lenOfQuery = service.SampleRate*seconds; //double[] samples = service.GetSamplesFromSong(proxy, pathToSong); //int startOfQuery = Random.Next(0, samples.Length - lenOfQuery); //double[] querySamples = new double[lenOfQuery]; //Array.Copy(samples, startOfQuery, querySamples, 0, lenOfQuery); //startIndex = startOfQuery/service.SampleRate; //MinHash minHash = new MinHash(dalManager); //IStride stride = queryStride; //int index = stride.FirstStrideSize(); //while (index + service.SamplesPerFingerprint < querySamples.Length) //{ // Fingerprint f = service.CreateFingerprintFromSamplesArray(querySamples, index); // if (f == null) continue; // index += service.SamplesPerFingerprint + stride.StrideSize(); // int[] bin = minHash.ComputeMinHashSignature(f); /*Compute Min Hash on randomly selected fingerprints*/ // Dictionary<int, long> hashes = minHash.GroupMinHashToLSHBuckets(bin, lshHashTables, lshGroupsPerKey); /*Find all candidates by querying the database*/ // long[] hashbuckets = hashes.Values.ToArray(); // var candidates = dalManager.ReadFingerprintsByHashBucketLSH(hashbuckets, thresholdTables); // if (candidates != null && candidates.Count > 0) // { // var query = (from candidate in candidates // select candidate.Value.Item1).Distinct(); // foreach (var item in query) // { // stats.Add(item, new QueryStats(0, 0, 0, startIndex, startIndex + seconds, 0)); // } // break; // } //} //stopWatch.Stop(); //queryTime = stopWatch.ElapsedMilliseconds; /*Set the query Time parameter*/ return null; }
public void ReadFingerprintsByTrackIdTest() { DaoGateway target = new DaoGateway(connectionstring); const int TrackId = 0; const int NumberOfFingerprintsToRead = 10; List<Fingerprint> actual = target.ReadFingerprintsByTrackId(TrackId, NumberOfFingerprintsToRead); Assert.IsNull(actual); }
public void ReadFingerprintsByMultipleTrackIdTest() { DaoGateway target = new DaoGateway(connectionstring); List<Track> tracks = new List<Track> { new Track(), new Track(), new Track(), new Track() }; const int NumberOfFingerprintsToRead = 10; Dictionary<int, List<Fingerprint>> actual = target.ReadFingerprintsByMultipleTrackId( tracks, NumberOfFingerprintsToRead); Assert.IsNull(actual); }
/// <summary> /// Common init method for both constructors /// </summary> /// <param name = "net">Network which will be trained</param> /// <param name = "dalManager">Database Fingerprint accessor</param> protected void Init(Network net, DaoGateway dalManager) { _dalManager = dalManager; _pauseSem = new Semaphore(0, 1, "PauseSemaphore"); }
public NetTrainerTest() { _dalManager = new DaoGateway(ConnectionString); }
public void ReadTrackIdCandidatesByHashBinAndHashTableNeuralHasherTest() { DaoGateway target = new DaoGateway(connectionstring); long[] hashBins = new long[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; int[] hashTables = new[] { 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110 }; Dictionary<int, int> actual = target.ReadTrackIdCandidatesByHashBinAndHashTableNeuralHasher( hashBins, hashTables); Assert.IsNull(actual); }
public void ReadTrackByIdTest() { DaoGateway target = new DaoGateway(connectionstring); const int Id = 0; Track actual = target.ReadTrackById(Id); Assert.IsNull(actual); }
public void ReadTrackByFingerprintFalseTest() { DaoGateway target = new DaoGateway(connectionstring); const int Id = 0; List<Track> actual = target.ReadTrackByFingerprint(Id); Assert.IsNull(actual); }
public DaoGatewayTest() { connectionstring = ConnectionString; dalManager = new DaoGateway(connectionstring); }
public void InsertReadAlbumTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway manager = new DaoGateway(connectionstring); const int FakeId = int.MinValue; Album album = new Album { Id = FakeId, Name = name, ReleaseYear = 1986 }; manager.InsertAlbum(album); Assert.AreNotEqual(FakeId, album.Id); List<Album> albums = manager.ReadAlbums(); // read all albums bool found = false; int id = 0; if (albums.Any(a => a.Id == album.Id)) { found = true; id = album.Id; } Assert.IsTrue(found); // check if it was inserted Album b = manager.ReadAlbumById(id); Assert.AreEqual(id, b.Id); Assert.AreEqual(album.Name, b.Name); Assert.AreEqual(album.ReleaseYear, b.ReleaseYear); List<Album> listAlbums = new List<Album>(); List<int> lId = new List<int>(); for (int i = 0; i < 10; i++) { Album a = new Album(FakeId, name + ":" + i, i + 1986); listAlbums.Add(a); } manager.InsertAlbum(listAlbums); /*Insert a list of albums*/ foreach (Album item in listAlbums) { Assert.AreNotEqual(FakeId, item.Id); lId.Add(item.Id); } List<Album> readAlbums = manager.ReadAlbums(); /*read all albums*/ List<int> lReadIds = readAlbums.Select(a => a.Id).ToList(); foreach (int i in lId) { Assert.AreEqual(true, lReadIds.Contains(i)); } }
public void DeleteTrackFalseTest3() { DaoGateway target = new DaoGateway(connectionstring); const int TrackId = 0; const int Expected = 0; int actual = target.DeleteTrack(TrackId); Assert.AreEqual(Expected, actual); }
public void DeleteTrackFalseTest1() { DaoGateway target = new DaoGateway(connectionstring); Track track = new Track(); const int Expected = 0; int actual = target.DeleteTrack(track); Assert.AreEqual(Expected, actual); }
/// <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; }
public void SetUp() { connectionstring = ConnectionString; dalManager = new DaoGateway(connectionstring); fingerprintingServiceWithBass = new FingerprintService( new BassAudioService(), new FingerprintDescriptor(), new HaarWavelet()); fingerprintingServiceWithDirectSound = new FingerprintService( new DirectSoundAudioService(), new FingerprintDescriptor(), new HaarWavelet()); fingerprintingConfiguration = new DefaultFingerprintingConfiguration(); workUnitBuilder = new WorkUnitBuilder(); }
public void ReadFingerprintsTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway target = new DaoGateway(connectionstring); Album album = target.ReadUnknownAlbum(); Track t = new Track(0, name, name, album.Id); target.InsertTrack(t); Fingerprint f = new Fingerprint(0, GenericFingerprint, t.Id, 10); target.InsertFingerprint(f); List<Fingerprint> actual = target.ReadFingerprints(); Assert.IsTrue(actual.Count >= 1); }
public void ReadTrackByArtistAndTitleNameTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway target = new DaoGateway(connectionstring); string artist = name; string title = name; Track actual = target.ReadTrackByArtistAndTitleName(artist, title); Assert.IsNull(actual); }
public void ReadAlbumByNameFalseTest() { string name = MethodBase.GetCurrentMethod().Name; DaoGateway target = new DaoGateway(connectionstring); Album actual = target.ReadAlbumByName(name); Assert.IsNull(actual); }
public void DeleteTrackFalseTest() { DaoGateway target = new DaoGateway(connectionstring); IEnumerable<int> collection = new List<int> { 0 }; const int Expected = 0; int actual = target.DeleteTrack(collection); Assert.AreEqual(Expected, actual); }
public void DaoGatewayConstructorTest() { DaoGateway target = new DaoGateway(connectionstring); Assert.IsNotNull(target); }
public void ReadTrackIdByHashBinAndHashTableNeuralHasherTest() { DaoGateway target = new DaoGateway(connectionstring); const long HashBin = 0; const int HashTable = 100; List<int> actual = target.ReadTrackIdByHashBinAndHashTableNeuralHasher(HashBin, HashTable); Assert.IsNull(actual); }
public void ReadFingerprintByIdFalseTest() { DaoGateway target = new DaoGateway(connectionstring); const int Id = 0; Fingerprint actual = target.ReadFingerprintById(Id); Assert.IsNull(actual); }
public void ReadFingerprintByIdFalseTest1() { DaoGateway target = new DaoGateway(connectionstring); IEnumerable<int> ids = new List<int> { 0 }; List<Fingerprint> actual = target.ReadFingerprintById(ids); Assert.IsNull(actual); }
public void ReadFingerprintIdByHashBinAndHashTableMinHashFalseTest() { DaoGateway target = new DaoGateway(connectionstring); long[] hashBins = new long[] { 1, 2, 3, 4, 5, 6 }; int[] hashTables = new[] { 100, 101, 102, 103, 104, 105 }; Dictionary<int, List<HashBinMinHash>> actual = target.ReadFingerprintsByHashBucketAndHashTableLSH( hashBins, hashTables); Assert.IsNull(actual); }
/// <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; }
/// <summary> /// Standard constructor of NetTrainer, should be used in most cases. /// </summary> /// <param name = "dalManager">Database gateway</param> public NetTrainer(DaoGateway dalManager) { Network net = new Network(); net.AddLayer(new BasicLayer(new ActivationTANH(), true, DEFAULT_FINGERPRINT_SIZE)); net.AddLayer(new BasicLayer(new ActivationTANH(), true, DEFAULT_HIDDEN_NEURONS_COUNT)); net.AddLayer(new BasicLayer(new ActivationTANH(), false, OUT_PUT_NEURONS)); net.Structure.FinalizeStructure(); net.Reset(); Init(net, dalManager); }