public static Dictionary<int, int> SquaredEuclideanDistances(CPoint centroid, List<CPoint> points)
 {
     Dictionary<int, int> dists = new Dictionary<int, int>();
     for (int i = 0; i < points.Count; i++)
     {
         if ( !ReferenceEquals(centroid, points[i]))
             dists.Add(i, SquaredEuclideanDistance(centroid, points[i]));
         else 
             dists.Add(i, 0);
     }
     return dists;
 }
示例#2
0
        public static KeyValuePair<int, int> MaxAndArgMaxComboFromSquaredEuclideanDistances(CPoint centroid, Cluster cluster, List<CPoint> allPoints)
        {
            int argmax = -1;
            int max = -1;
            var clusterPoints = cluster.GetPointAsList();
            for (int i = 0; i < cluster.GetPointsCount(); i++)
            {
                var distance = SquaredEuclideanDistance(centroid, clusterPoints[i]);
                if (distance > max)
                {
                    max = distance;
                    argmax = allPoints.IndexOf(clusterPoints[i]);
                }
            }

            return new KeyValuePair<int, int>(argmax, max);
        }
        //public static Dictionary<int, int> SquaredEuclideanDistances(CPoint centroid, List<CPoint> cluster, List<CPoint> allPoints)
        //{
        //    Dictionary<int, int> dists = new Dictionary<int, int>();
        //    for (int i = 0; i < cluster.Count; i++)
        //    {
        //        no need to check references cuz thera ain't any centroids in cluster. only points
        //         dists.Add(i, SquaredEuclideanDistance(centroid, allPoints[i]));
        //    }

        //    return dists;
        //}

        public static KeyValuePair<int, int> MaxAndArgMaxComboFromSquaredEuclideanDistances(CPoint centroid, List<CPoint> clusterPoints, List<CPoint> allPoints)
        {
            Dictionary<int, int> dists = new Dictionary<int, int>();
            int argmax = -1;
            int max = -1;

            for (int i = 0; i < clusterPoints.Count; i++)
            {
                var distance = SquaredEuclideanDistance(centroid, clusterPoints[i]);
                if (distance > max)
                {
                    max = distance;
                    argmax = allPoints.IndexOf(clusterPoints[i]);
                }
            }

            return new KeyValuePair<int, int>(argmax, max);
        }
示例#4
0
        public static int ArgMaxFromSquaredEuclideanDistances(CPoint centroid, List<CPoint> points)
        {
            int argmax = -1;
            int max = -1;
            int distance;

            for (int i = 0; i < points.Count; i++)
            {
                if (!Object.ReferenceEquals(centroid, points[i]))
                {
                    distance = SquaredEuclideanDistance(centroid, points[i]);
                    if (distance > max)
                    {
                        max = distance;
                        argmax = i;
                    }
                }
            }
            return argmax;
        }
示例#5
0
 public static int ArgMinFromSquaredEuclideanDistances(CPoint point, List<CPoint> centroids)
 {
     int argmin = -1;
     int min = Int32.MaxValue;
    
     for (int i = 0; i < centroids.Count; i++)
     {
         if (!Object.ReferenceEquals(centroids[i], point))
         {
             var distance = SquaredEuclideanDistance(point, centroids[i]);
             if (distance < min)
             {
                 min = distance;
                 argmin = i;
             }
         }
           
     }
     return argmin;
 }
 public static int SquaredEuclideanDistance(CPoint pointA, CPoint pointB)
 {
     //(A.x - B.x)^2 + (A.y - B.y)^2
     return (pointB.X - pointA.X) * (pointB.X - pointA.X) +
            (pointB.Y - pointA.Y) * (pointB.Y - pointA.Y);
 }
示例#7
0
 public CPoint(CPoint point, Color color)
 {
     this.X = point.X;
     this.Y = point.Y;
     this.Color = color;
 }