/// <summary> /// Finds the vectors most similar to the input vector. If the input is /// the zero vector, an empty list is returned. /// </summary> /// <param name="vector">The input vector</param> /// <param name="neighborhoodSize">The number of neighbors to retrieve</param> /// <returns>A list of neighboring vectors sorted by descending cosine similarity</returns> public List <Tuple <float, LabeledVector> > FindNearestNeighbors(float[] vector, int neighborhoodSize) { if (IsZero(vector)) { return(null); } var nBestList = new NBestList <LabeledVector>(neighborhoodSize); foreach (var wordVectorPair in _labeledVectorDictionary) { float cosine = LabeledVector.Cosine(wordVectorPair.Value, vector); if (nBestList.IsBetter(cosine)) { nBestList.Insert(cosine, new LabeledVector(wordVectorPair.Key, wordVectorPair.Value)); } } return(nBestList.GetSortedList()); }
public float Euclidean(LabeledVector otherVector) { return(Euclidean(otherVector.Vector)); }
public float Cosine(LabeledVector otherVector) { return(Cosine(otherVector.Vector)); }
public float InnerProduct(LabeledVector otherVector) { return(InnerProduct(otherVector.Vector)); }
/// <summary> /// Finds the vectors most similar to the input vector. If the input is /// the zero vector, an empty list is returned. /// </summary> /// <param name="vector">The input vector</param> /// <param name="neighborhoodSize">The number of neighbors to retrieve</param> /// <returns>A list of neighboring vectors sorted by descending cosine similarity</returns> public List <Tuple <float, LabeledVector> > FindNearestNeighbors(LabeledVector vector, int neighborhoodSize) { return(FindNearestNeighbors(vector.Vector, neighborhoodSize)); }
public float Euclidean(LabeledVector otherVector) { return Euclidean(otherVector.Vector); }
public float Cosine(LabeledVector otherVector) { return Cosine(otherVector.Vector); }
public float InnerProduct(LabeledVector otherVector) { return InnerProduct(otherVector.Vector); }
/// <summary> /// Finds the vectors most similar to the input vector. If the input is /// the zero vector, an empty list is returned. /// </summary> /// <param name="vector">The input vector</param> /// <param name="neighborhoodSize">The number of neighbors to retrieve</param> /// <returns>A list of neighboring vectors sorted by descending cosine similarity</returns> public List<Tuple<float, LabeledVector>> FindNearestNeighbors(LabeledVector vector, int neighborhoodSize) { return FindNearestNeighbors(vector.Vector, neighborhoodSize); }