/// <summary> /// Perform an ANN search on the class' world, given a vector, returning the (approximate) k-best results. /// </summary> /// <param name="queryVector">The query vector.</param> /// <param name="kBest">How many results should be returned (K-Value).</param> /// <returns>A <see cref="QueryResult"/> object containing the K best results.</returns> public QueryResult RunANNQuery(NamedFeatureVector queryVector, int kBest) { QueryResult queryresult = new QueryResult(queryVector.Name); IList <SmallWorld <NamedFeatureVector, double> .KNNSearchResult> kBestResults = world.KNNSearch(queryVector, kBest); foreach (SmallWorld <NamedFeatureVector, double> .KNNSearchResult queryitem in kBestResults) { queryresult.AddItem(new QueryItem(queryitem.Item.Name, queryitem.Distance)); } return(queryresult); }
/// <summary> /// Distance function used for calculating the distances between vectors. /// </summary> /// <param name="vector1">The first vector.</param> /// <param name="vector2">The second vector.</param> /// <returns></returns> private static double ANNDistance(NamedFeatureVector vector1, NamedFeatureVector vector2) { return(vector1.FeatureVector.Compare(vector2.FeatureVector)); }