Example #1
0
        private static double[] CalcPairwise(List <Cluster> clusters, Similarity similarity, int startIdx, int endIdx, float[][] cache, int offset)
        {
            double[] lowestPair  = new double[] { 0.0d, 1.0d, Double.MaxValue, 0.0d };
            double   closest     = similarity.GetDistance(clusters[0], clusters[1]);
            Int64    cacheMisses = 0;

            // loop through every pair looking for the smallest distance
            for (int i = startIdx; i < endIdx; i++)
            {
                for (int j = (i + 1); j < clusters.Count; j++)
                {
                    int row = clusters[i].Id + offset;
                    int col = clusters[j].Id + offset;

                    //if (cache[row][col] == -10.0d)
                    //{
                    cache[row][col] = (float)similarity.GetDistance(clusters[i], clusters[j]);
                    cacheMisses++;
                    //}

                    double d = cache[row][col];

                    if (d < closest)
                    {
                        closest    = d;
                        lowestPair = new double[] { i, j, closest, 0.0d };
                    }
                }
            }

            lowestPair[3] = cacheMisses;

            return(lowestPair);
        }