public static double CalculateSingle(DistanceMeasurementTypes distanceMeasurement, List <double[]> firstClusterDatapoints, List <double[]> secondClusterDatapoints)
        {
            double min = double.MaxValue;

            for (int i = 0; i < firstClusterDatapoints.Count(); i++)
            {
                for (int j = 0; j < secondClusterDatapoints.Count(); j++)
                {
                    var firstDatapoint  = firstClusterDatapoints[i];
                    var secondDatapoint = secondClusterDatapoints[j];
                    var distance        = DistanceCalculationHelper.Calculate(distanceMeasurement, firstDatapoint, secondDatapoint);
                    if (distance < min)
                    {
                        min = distance;
                    }
                }
            }

            return(min);
        }
        public static double CalculateComplete(DistanceMeasurementTypes distanceMeasurement, List <double[]> firstClusterDatapoints, List <double[]> secondClusterDatapoints)
        {
            double max = 0;

            for (int i = 0; i < firstClusterDatapoints.Count(); i++)
            {
                for (int j = 0; j < secondClusterDatapoints.Count(); j++)
                {
                    var firstDatapoint  = firstClusterDatapoints[i];
                    var secondDatapoint = secondClusterDatapoints[j];
                    var distance        = DistanceCalculationHelper.Calculate(distanceMeasurement, firstDatapoint, secondDatapoint);
                    if (distance > max)
                    {
                        max = distance;
                    }
                }
            }

            return(max);
        }
Example #3
0
        public double[,] CalculateSimilarity(List <double[]> data)
        {
            // Documentation :
            // https://r-snippets.readthedocs.io/en/latest/real_analysis/metrics.html
            var nbRow = data.Count();

            double[,] c = new double[nbRow, nbRow];
            for (int i = 0; i < nbRow; i++)
            {
                var firstVector = data.ElementAt(i);
                for (int j = 0; j < nbRow; j++)
                {
                    var    secondVector = data.ElementAt(j);
                    double distance     = DistanceCalculationHelper.Calculate(_options.DistanceMeasurement, firstVector, secondVector);
                    c[i, j] = distance;
                }
            }

            return(c);
        }