public override double ComputeSimilarity(WeightDictionary vectorA, WeightDictionary vectorB) { WeightDictionaryEntryPairs termPairs = new WeightDictionaryEntryPairs(vectorA, vectorB); if (termPairs.Count == 0) { return(0); } return(Compute(termPairs)); }
private Double Compute(WeightDictionaryEntryPairs termPairs) { Double above = 0; Double belowA = 0; Double belowB = 0; foreach (WeightDictionaryEntryPair pair in termPairs) { above += pair.weight_A * pair.weight_B; belowA += pair.weight_A_sq; belowB += pair.weight_B_sq; } belowA = Math.Sqrt(belowA); belowB = Math.Sqrt(belowB); return(above / (belowA * belowB)); }