Пример #1
0
 public Centroid(Centroid c)
 {
     // perform deep copy
     this.name           = new StringBuilder(c.getName());
     this.vectorCnt      = c.getVectorCnt();
     this.centroidVector = new Dictionary <string, double>(c.getCentroidVector());
     this.length         = c.getLength();
 }
Пример #2
0
        static public double similarity(Centroid a, Centroid b)
        {
            Dictionary <string, double> vectorA = a.getCentroidVector();
            Dictionary <string, double> vectorB = b.getCentroidVector();

            double lengthA = a.getLength();
            double lengthB = b.getLength();

            double dotproduct = 0.0;

            // compute dot product of vectors A & B
            foreach (KeyValuePair <string, double> kvp in vectorA)
            {
                // if both vectors have the key
                if (vectorB.ContainsKey(kvp.Key))
                {
                    dotproduct += (kvp.Value * vectorB[kvp.Key]);
                }
            }

            return(dotproduct / (lengthA * lengthB));
        }