private static double AverageInterDissimilar(double[] currInput, ClusterItem[] cluster, Distance distance) { double[] d = new double[cluster.Length]; for (int i = 0; i < d.Length; i++) { d[i] = distance.Similarity(currInput, cluster[i].InputVector); } return(d.Average()); }
private static double AverageDissimilar(double[] currInput, ClusterItem[] cluster, Distance distance) { double[] d = new double[cluster.Length]; for (int i = 0; i < d.Length; i++) { d[i] = distance.Similarity(currInput, cluster[i].InputVector); } return(d.Sum() / (d.Length - 1)); // remove one element => itself }
public static double WithinClusterVariance(ClusterItem[][] clusters, double[][] centroids, int numSamples, Distance distance) { double var = 0; for (int i = 0; i < clusters.Length; i++) { for (int j = 0; j < clusters[i].Length; j++) { var += distance.Similarity(clusters[i][j].InputVector, centroids[clusters[i][j].Label]); } } var = var / numSamples * 1.0; return(var); }