Similarity Methods (Cosine Similarty, L1 Distance, KullbackLeibler, Simetric KullbackLeibler, JensenShannon) in C#
public static double CosineSimilarty(double[] q, double[] d) { if (d == null || q == null) return 0; if (q.Length != d.Length) throw new Exception("both vectors must be of similar length"); // Calculate cosine similarity: double numer = 0; double denom = 1; double d1 = 0, d2 = 0; for (int m = 0; m < q.Length; m++) { numer += (q[m] * d[m]); d1 += (q[m] * q[m]); d2 += (d[m] * d[m]); ...