예제 #1
0
 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);
        }
예제 #3
0
        //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;
 }
예제 #6
0
 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;
 }