Vectors with string labels and basic vector operations
Exemplo n.º 1
0
        /// <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());
        }
Exemplo n.º 2
0
 public float Euclidean(LabeledVector otherVector)
 {
     return(Euclidean(otherVector.Vector));
 }
Exemplo n.º 3
0
 public float Cosine(LabeledVector otherVector)
 {
     return(Cosine(otherVector.Vector));
 }
Exemplo n.º 4
0
 public float InnerProduct(LabeledVector otherVector)
 {
     return(InnerProduct(otherVector.Vector));
 }
Exemplo n.º 5
0
 /// <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));
 }
Exemplo n.º 6
0
 public float Euclidean(LabeledVector otherVector)
 {
     return Euclidean(otherVector.Vector);
 }
Exemplo n.º 7
0
 public float Cosine(LabeledVector otherVector)
 {
     return Cosine(otherVector.Vector);
 }
Exemplo n.º 8
0
 public float InnerProduct(LabeledVector otherVector)
 {
     return InnerProduct(otherVector.Vector);
 }
Exemplo n.º 9
0
 /// <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);
 }