/// <summary>Get Distance</summary> /// <seealso cref="">comirva.audio.feature.AudioFeature#GetDistance(comirva.audio.feature.AudioFeature)</seealso> public override double GetDistance(AudioFeature f, AudioFeature.DistanceType t) { if(!(f is MandelEllis)) { new Exception("Can only handle AudioFeatures of type Mandel Ellis, not of: "+f); return -1; } MandelEllis other = (MandelEllis)f; DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean; switch (t) { case AudioFeature.DistanceType.Dtw_Euclidean: distanceMeasure = DistanceMeasure.Euclidean; break; case AudioFeature.DistanceType.Dtw_SquaredEuclidean: distanceMeasure = DistanceMeasure.SquaredEuclidean; break; case AudioFeature.DistanceType.Dtw_Manhattan: distanceMeasure = DistanceMeasure.Manhattan; break; case AudioFeature.DistanceType.Dtw_Maximum: distanceMeasure = DistanceMeasure.Maximum; break; case AudioFeature.DistanceType.KullbackLeiblerDivergence: default: return KullbackLeibler(this.gmmMe, other.gmmMe) + KullbackLeibler(other.gmmMe, this.gmmMe); } Dtw dtw = new Dtw(this.GetArray(), other.GetArray(), distanceMeasure, true, true, null, null, null); return dtw.GetCost(); }
private static void FindSimilar(string path, Db db, Analyzer.AnalysisMethod analysisMethod, int numToTake=25, double percentage=0.2, AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence) { var similarTracks = SimilarTracks(path, db, analysisMethod, numToTake, percentage, distanceType); foreach (var entry in similarTracks) { Console.WriteLine("{0}, {1}", entry.Key, entry.Value); } }
/// <summary>Get Distance</summary> /// <seealso cref="">comirva.audio.feature.AudioFeature#GetDistance(comirva.audio.feature.AudioFeature)</seealso> public override double GetDistance(AudioFeature f) { if(!(f is MandelEllis)) { new Exception("Can only handle AudioFeatures of type Mandel Ellis, not of: "+f); return -1; } MandelEllis other = (MandelEllis)f; return KullbackLeibler(this.gmmMe, other.gmmMe) + KullbackLeibler(other.gmmMe, this.gmmMe); }
/// <summary>Get Distance</summary> /// <seealso cref="">comirva.audio.feature.AudioFeature#GetDistance(comirva.audio.feature.AudioFeature)</seealso> public override double GetDistance(AudioFeature f) { if (!(f is MandelEllis)) { new Exception("Can only handle AudioFeatures of type Mandel Ellis, not of: " + f); return(-1); } MandelEllis other = (MandelEllis)f; return(KullbackLeibler(this.gmmMe, other.gmmMe) + KullbackLeibler(other.gmmMe, this.gmmMe)); }
/// <summary>Get Distance</summary> /// <seealso cref="">comirva.audio.feature.AudioFeature#GetDistance(comirva.audio.feature.AudioFeature)</seealso> public override double GetDistance(AudioFeature f, AudioFeature.DistanceType t) { if (!(f is MandelEllis)) { new Exception("Can only handle AudioFeatures of type Mandel Ellis, not of: " + f); return(-1); } MandelEllis other = (MandelEllis)f; DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean; switch (t) { case AudioFeature.DistanceType.Dtw_Euclidean: distanceMeasure = DistanceMeasure.Euclidean; break; case AudioFeature.DistanceType.Dtw_SquaredEuclidean: distanceMeasure = DistanceMeasure.SquaredEuclidean; break; case AudioFeature.DistanceType.Dtw_Manhattan: distanceMeasure = DistanceMeasure.Manhattan; break; case AudioFeature.DistanceType.Dtw_Maximum: distanceMeasure = DistanceMeasure.Maximum; break; case AudioFeature.DistanceType.KullbackLeiblerDivergence: default: return(KullbackLeibler(this.gmmMe, other.gmmMe) + KullbackLeibler(other.gmmMe, this.gmmMe)); } Dtw dtw = new Dtw(this.GetArray(), other.GetArray(), distanceMeasure, true, true, null, null, null); return(dtw.GetCost()); }
public override double GetDistance(AudioFeature f) { if(!(f is Scms)) { new Exception("Can only handle AudioFeatures of type Scms, not of: "+f); return -1; } Scms other = (Scms)f; return Distance(this, other, new ScmsConfiguration(Analyzer.MFCC_COEFFICIENTS)); }
/// <summary> /// Add a track to the database /// </summary> /// <param name="audioFeature">the audiofeature object</param> /// <returns>-1 if failed otherwise the track-id passed</returns> public int AddTrack(AudioFeature audioFeature) { IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary); IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String); IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64); IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String); IDbCommand dbcmd; lock (dbcon) { dbcmd = dbcon.CreateCommand(); } dbcmd.CommandText = "INSERT INTO mirage (audioFeature, name, duration, bitstring) " + "VALUES (@audioFeature, @name, @duration, @bitstring); SELECT last_insert_rowid();"; dbcmd.Parameters.Add(dbAudioFeatureParam); dbcmd.Parameters.Add(dbNameParam); dbcmd.Parameters.Add(dbDurationParam); dbcmd.Parameters.Add(dbBitStringParam); dbAudioFeatureParam.Value = audioFeature.ToBytes(); dbNameParam.Value = audioFeature.Name; dbDurationParam.Value = audioFeature.Duration; dbBitStringParam.Value = audioFeature.BitString; int trackid = -1; try { dbcmd.Prepare(); //dbcmd.ExecuteNonQuery(); trackid = Convert.ToInt32(dbcmd.ExecuteScalar()); dbcmd.Dispose(); } catch (Exception) { return -1; } return trackid; }
/// <summary> /// Find Similar Tracks to one or many audio files using their unique database id(s) /// </summary> /// <param name="id">an array of unique database ids for the audio files to search for similar matches</param> /// <param name="exclude">an array of unique database ids to ignore (normally the same as the id array)</param> /// <param name="db">database</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <param name="numToTake">max number of entries to return</param> /// <param name="percentage">percentage below and above the duration in ms when querying (used if between 0.1 - 0.9)</param> /// <param name="distanceType">distance method to use (KullbackLeiblerDivergence is default)</param> /// <returns>a list of query results</returns> public static List<FindSimilar.QueryResult> SimilarTracksList(int[] id, int[] exclude, Db db, Analyzer.AnalysisMethod analysisMethod, int numToTake=25, double percentage=0.2, AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence) { AudioFeature[] seedAudioFeatures = null; AudioFeature[] audioFeatures = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: seedAudioFeatures = new MandelEllis[id.Length]; audioFeatures = new MandelEllis[100]; break; case Analyzer.AnalysisMethod.SCMS: seedAudioFeatures = new Scms[id.Length]; audioFeatures = new Scms[100]; break; } for (int i = 0; i < seedAudioFeatures.Length; i++) { seedAudioFeatures[i] = db.GetTrack(id[i], analysisMethod); } // Get all tracks from the DB except the seedSongs IDataReader r = db.GetTracks(exclude, seedAudioFeatures[0].Duration, percentage); // store results in a query results list List<FindSimilar.QueryResult> queryResultList = new List<FindSimilar.QueryResult>(); int[] mapping = new int[100]; int read = 1; double d; double dcur; float count; while (read > 0) { read = db.GetNextTracks(ref r, ref audioFeatures, ref mapping, 100, analysisMethod); for (int i = 0; i < read; i++) { d = 0; count = 0; for (int j = 0; j < seedAudioFeatures.Length; j++) { dcur = seedAudioFeatures[j].GetDistance(audioFeatures[i], distanceType); // convert to positive values dcur = Math.Abs(dcur); d += dcur; count++; } if (d > 0) { QueryResult queryResult = new QueryResult(); queryResult.Id = mapping[i]; queryResult.Path = audioFeatures[i].Name; queryResult.Duration = audioFeatures[i].Duration; queryResult.Similarity = d/count; queryResultList.Add(queryResult); } } } var sortedList = (from row in queryResultList orderby row.Similarity ascending select new QueryResult { Id = row.Id, Path = row.Path, Duration = row.Duration, Similarity = row.Similarity }).Take(numToTake).ToList(); return sortedList; }
/// <summary> /// Find Similar Tracks to one or many audio files using their unique database id(s) /// </summary> /// <param name="id">an array of unique database ids for the audio files to search for similar matches</param> /// <param name="exclude">an array of unique database ids to ignore (normally the same as the id array)</param> /// <param name="db">database</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <param name="numToTake">max number of entries to return</param> /// <param name="percentage">percentage below and above the duration in ms when querying (used if between 0.1 - 0.9)</param> /// <param name="distanceType">distance method to use (KullbackLeiblerDivergence is default)</param> /// <returns>a dictinary list of key value pairs (filepath and distance)</returns> public static Dictionary<KeyValuePair<int, string>, double> SimilarTracks(int[] id, int[] exclude, Db db, Analyzer.AnalysisMethod analysisMethod, int numToTake=25, double percentage=0.2, AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence) { DbgTimer t = new DbgTimer(); t.Start(); AudioFeature[] seedAudioFeatures = null; AudioFeature[] audioFeatures = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: seedAudioFeatures = new MandelEllis[id.Length]; audioFeatures = new MandelEllis[100]; break; case Analyzer.AnalysisMethod.SCMS: seedAudioFeatures = new Scms[id.Length]; audioFeatures = new Scms[100]; break; } for (int i = 0; i < seedAudioFeatures.Length; i++) { seedAudioFeatures[i] = db.GetTrack(id[i], analysisMethod); } // Get all tracks from the DB except the seedSongs IDataReader r = db.GetTracks(exclude, seedAudioFeatures[0].Duration, percentage); // store results in a dictionary var NameDictionary = new Dictionary<KeyValuePair<int, string>, double>(); int[] mapping = new int[100]; int read = 1; double d; double dcur; float count; while (read > 0) { read = db.GetNextTracks(ref r, ref audioFeatures, ref mapping, 100, analysisMethod); for (int i = 0; i < read; i++) { d = 0; count = 0; for (int j = 0; j < seedAudioFeatures.Length; j++) { dcur = seedAudioFeatures[j].GetDistance(audioFeatures[i], distanceType); // convert to positive values dcur = Math.Abs(dcur); d += dcur; count++; } if (d > 0) { NameDictionary.Add(new KeyValuePair<int,string>(mapping[i], audioFeatures[i].Name), d/count); //NameDictionary.Add(new KeyValuePair<int,string>(mapping[i], String.Format("{0} ({1} ms)", audioFeatures[i].Name, audioFeatures[i].Duration)), d/count); } } } // sort by non unique values var sortedDict = (from entry in NameDictionary orderby entry.Value ascending select entry) .Take(numToTake) .ToDictionary(pair => pair.Key, pair => pair.Value); Console.Out.WriteLine(String.Format("Found Similar to ({0}) in {1} ms", String.Join(",", seedAudioFeatures.Select(p=>p.Name)), t.Stop().TotalMilliseconds)); return sortedDict; }
/// <summary> /// Add a track N number of times to the database starting with the given track-id /// </summary> /// <param name="trackid">track-id to start with</param> /// <param name="audioFeature">the audiofeature object</param> /// <returns>the track-ids inserted</returns> public int[] AddTracks(ref int trackid, AudioFeature audioFeature) { IDbDataParameter dbTrackIdParam = new SQLiteParameter("@trackid", DbType.Int64); IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary); IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String); IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64); IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String); IDbDataParameter dbSignatureParam = new SQLiteParameter("@signature", DbType.Binary); dbAudioFeatureParam.Value = audioFeature.ToBytes(); dbNameParam.Value = audioFeature.Name; dbDurationParam.Value = audioFeature.Duration; dbBitStringParam.Value = audioFeature.BitString; List<int> trackids = new List<int>(); foreach(bool[] signature in audioFeature.Signatures) { trackids.Add(trackid); dbTrackIdParam.Value = trackid; dbSignatureParam.Value = BoolToByte(signature); IDbCommand dbcmd; lock (dbcon) { dbcmd = dbcon.CreateCommand(); } dbcmd.CommandText = "INSERT INTO mirage (trackid, audioFeature, name, duration, bitstring, signature) " + "VALUES (@trackid, @audioFeature, @name, @duration, @bitstring, @signature)"; dbcmd.Parameters.Add(dbTrackIdParam); dbcmd.Parameters.Add(dbAudioFeatureParam); dbcmd.Parameters.Add(dbNameParam); dbcmd.Parameters.Add(dbDurationParam); dbcmd.Parameters.Add(dbBitStringParam); dbcmd.Parameters.Add(dbSignatureParam); try { dbcmd.ExecuteNonQuery(); } catch (SQLiteException) { continue; } trackid++; } return trackids.ToArray(); }
/// <summary> /// Measures the similarity/dissimilarity of two audio streams characterized /// by two audio features. /// </summary> /// <param name="f">AudioFeature another audio feature of the same type</param> /// <returns>double the distance between the two audio streams</returns> public abstract double GetDistance(AudioFeature f, DistanceType t);
/// <summary> /// Measures the similarity/dissimilarity of two audio streams characterized /// by two audio features. /// </summary> /// <param name="f">AudioFeature another audio feature of the same type</param> /// <returns>double the distance between the two audio streams</returns> public abstract double GetDistance(AudioFeature f);
public override double GetDistance(AudioFeature f) { throw new NotImplementedException(); }
/// <summary> /// Measures the similarity/dissimilarity of two audio streams characterized /// by two audio features. /// </summary> /// <param name="f">AudioFeature another audio feature of the same type</param> /// <returns>double the distance between the two audio streams</returns> abstract public double GetDistance(AudioFeature f, DistanceType t);
/// <summary> /// Measures the similarity/dissimilarity of two audio streams characterized /// by two audio features. /// </summary> /// <param name="f">AudioFeature another audio feature of the same type</param> /// <returns>double the distance between the two audio streams</returns> abstract public double GetDistance(AudioFeature f);
public override double GetDistance(AudioFeature f, AudioFeature.DistanceType t) { if(!(f is Scms)) { new Exception("Can only handle AudioFeatures of type Scms, not of: "+f); return -1; } Scms other = (Scms)f; DistanceMeasure distanceMeasure = DistanceMeasure.Euclidean; switch (t) { case AudioFeature.DistanceType.Dtw_Euclidean: distanceMeasure = DistanceMeasure.Euclidean; break; case AudioFeature.DistanceType.Dtw_SquaredEuclidean: distanceMeasure = DistanceMeasure.SquaredEuclidean; break; case AudioFeature.DistanceType.Dtw_Manhattan: distanceMeasure = DistanceMeasure.Manhattan; break; case AudioFeature.DistanceType.Dtw_Maximum: distanceMeasure = DistanceMeasure.Maximum; break; case AudioFeature.DistanceType.UCR_Dtw: return UCRCSharp.UCR.DTW(this.GetArray(), other.GetArray()); case AudioFeature.DistanceType.CosineSimilarity: return CosineSimilarity(this, other); case AudioFeature.DistanceType.BitStringHamming: return Imghash.ImagePHash.HammingDistance(this.BitString, other.BitString); case AudioFeature.DistanceType.JaqSimilarity: //return Soundfingerprinting.Hashing.MinHash.CalculateJaqSimilarity(this.Signature, other.Signature); break; case AudioFeature.DistanceType.KullbackLeiblerDivergence: default: return Distance(this, other, new ScmsConfiguration(Analyzer.MFCC_COEFFICIENTS)); } Dtw dtw = new Dtw(this.GetArray(), other.GetArray(), distanceMeasure, true, true, null, null, null); return dtw.GetCost(); }
/// <summary> /// Add a track to the database using the given track-id /// </summary> /// <param name="trackid">track-id to use</param> /// <param name="audioFeature">the audiofeature object</param> /// <returns>-1 if failed otherwise the track-id passed</returns> public int AddTrack(ref int trackid, AudioFeature audioFeature) { IDbDataParameter dbTrackIdParam = new SQLiteParameter("@trackid", DbType.Int64); IDbDataParameter dbAudioFeatureParam = new SQLiteParameter("@audioFeature", DbType.Binary); IDbDataParameter dbNameParam = new SQLiteParameter("@name", DbType.String); IDbDataParameter dbDurationParam = new SQLiteParameter("@duration", DbType.Int64); IDbDataParameter dbBitStringParam = new SQLiteParameter("@bitstring", DbType.String); dbTrackIdParam.Value = trackid; dbAudioFeatureParam.Value = audioFeature.ToBytes(); dbNameParam.Value = audioFeature.Name; dbDurationParam.Value = audioFeature.Duration; dbBitStringParam.Value = audioFeature.BitString; IDbCommand dbcmd; lock (dbcon) { dbcmd = dbcon.CreateCommand(); } dbcmd.CommandText = "INSERT INTO mirage (trackid, audioFeature, name, duration, bitstring) " + "VALUES (@trackid, @audioFeature, @name, @duration, @bitstring)"; dbcmd.Parameters.Add(dbTrackIdParam); dbcmd.Parameters.Add(dbAudioFeatureParam); dbcmd.Parameters.Add(dbNameParam); dbcmd.Parameters.Add(dbDurationParam); dbcmd.Parameters.Add(dbBitStringParam); try { dbcmd.ExecuteNonQuery(); } catch (SQLiteException) { return -1; } //trackid++; return trackid; }
/// <summary> /// Find Similar Tracks to an audio file using its file path /// </summary> /// <param name="searchForPath">audio file path</param> /// <param name="db">database</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <param name="numToTake">max number of entries to return</param> /// <param name="percentage">percentage below and above the duration in ms when querying (used if between 0.1 - 0.9)</param> /// <param name="distanceType">distance method to use (KullbackLeiblerDivergence is default)</param> /// <returns>a dictinary list of key value pairs (filepath and distance)</returns> public static Dictionary<KeyValuePair<int, string>, double> SimilarTracks(string searchForPath, Db db, Analyzer.AnalysisMethod analysisMethod, int numToTake=25, double percentage=0.2, AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence) { DbgTimer t = new DbgTimer(); t.Start(); FileInfo fi = new FileInfo(searchForPath); AudioFeature seedAudioFeature = null; AudioFeature[] audioFeatures = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: seedAudioFeature = Analyzer.AnalyzeMandelEllis(fi); audioFeatures = new MandelEllis[100]; break; case Analyzer.AnalysisMethod.SCMS: seedAudioFeature = Analyzer.AnalyzeScms(fi); audioFeatures = new Scms[100]; break; } // Get all tracks from the DB except the seedSongs IDataReader r = db.GetTracks(null, seedAudioFeature.Duration, percentage); // store results in a dictionary var NameDictionary = new Dictionary<KeyValuePair<int, string>, double>(); int[] mapping = new int[100]; int read = 1; double dcur; while (read > 0) { read = db.GetNextTracks(ref r, ref audioFeatures, ref mapping, 100, analysisMethod); for (int i = 0; i < read; i++) { dcur = seedAudioFeature.GetDistance(audioFeatures[i], distanceType); // convert to positive values dcur = Math.Abs(dcur); NameDictionary.Add(new KeyValuePair<int,string>(mapping[i], audioFeatures[i].Name), dcur); } } // sort by non unique values var sortedDict = (from entry in NameDictionary orderby entry.Value ascending select entry) .Take(numToTake) .ToDictionary(pair => pair.Key, pair => pair.Value); Console.Out.WriteLine(String.Format("Found Similar to ({0}) in {1} ms", seedAudioFeature.Name, t.Stop().TotalMilliseconds)); return sortedDict; }
/// <summary> /// Using the passed datareader pointer, fill the audio feature tracks array with content /// </summary> /// <param name="tracksIterator">datareader pointer</param> /// <param name="tracks">AudioFeature array</param> /// <param name="mapping">array of trackids</param> /// <param name="len">number of tracks to return</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <returns>number of tracks returned</returns> public int GetNextTracks(ref IDataReader tracksIterator, ref AudioFeature[] tracks, ref int[] mapping, int len, Analyzer.AnalysisMethod analysisMethod) { int i = 0; while ((i < len) && tracksIterator.Read()) { AudioFeature audioFeature = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: audioFeature = MandelEllis.FromBytes((byte[]) tracksIterator.GetValue(0)); break; case Analyzer.AnalysisMethod.SCMS: audioFeature = Scms.FromBytes((byte[]) tracksIterator.GetValue(0)); break; } mapping[i] = tracksIterator.GetInt32(1); audioFeature.Name = tracksIterator.GetString(2); audioFeature.Duration = tracksIterator.GetInt64(3); audioFeature.BitString = tracksIterator.GetString(4); audioFeature.Signatures.Add(ByteToBool((byte[]) tracksIterator.GetValue(5))); tracks[i] = audioFeature; i++; } if (i == 0) { tracksIterator.Close(); tracksIterator = null; } return i; }
/// <summary> /// Find Similar Tracks to an audio file using its file path /// </summary> /// <param name="searchForPath">audio file path</param> /// <param name="db">database</param> /// <param name="analysisMethod">analysis method (SCMS or MandelEllis)</param> /// <param name="numToTake">max number of entries to return</param> /// <param name="percentage">percentage below and above the duration in ms when querying (used if between 0.1 - 0.9)</param> /// <param name="distanceType">distance method to use (KullbackLeiblerDivergence is default)</param> /// <returns>a list of query results</returns> public static List<FindSimilar.QueryResult> SimilarTracksList(string searchForPath, Db db, Analyzer.AnalysisMethod analysisMethod, int numToTake=25, double percentage=0.2, AudioFeature.DistanceType distanceType = AudioFeature.DistanceType.KullbackLeiblerDivergence) { FileInfo fi = new FileInfo(searchForPath); AudioFeature seedAudioFeature = null; AudioFeature[] audioFeatures = null; switch (analysisMethod) { case Analyzer.AnalysisMethod.MandelEllis: seedAudioFeature = Analyzer.AnalyzeMandelEllis(fi); audioFeatures = new MandelEllis[100]; break; case Analyzer.AnalysisMethod.SCMS: seedAudioFeature = Analyzer.AnalyzeScms(fi); audioFeatures = new Scms[100]; break; } // Get all tracks from the DB except the seedSongs IDataReader r = db.GetTracks(null, seedAudioFeature.Duration, percentage); // store results in a query results list List<FindSimilar.QueryResult> queryResultList = new List<FindSimilar.QueryResult>(); int[] mapping = new int[100]; int read = 1; double dcur; while (read > 0) { read = db.GetNextTracks(ref r, ref audioFeatures, ref mapping, 100, analysisMethod); for (int i = 0; i < read; i++) { dcur = seedAudioFeature.GetDistance(audioFeatures[i], distanceType); // convert to positive values dcur = Math.Abs(dcur); QueryResult queryResult = new QueryResult(); queryResult.Id = mapping[i]; queryResult.Path = audioFeatures[i].Name; queryResult.Duration = audioFeatures[i].Duration; queryResult.Similarity = dcur; queryResultList.Add(queryResult); } } var sortedList = (from row in queryResultList orderby row.Similarity ascending select new QueryResult { Id = row.Id, Path = row.Path, Duration = row.Duration, Similarity = row.Similarity }).Take(numToTake).ToList(); return sortedList; }