コード例 #1
0
        private SilverlightEdge GetCentralEdge(List <SilverlightEdge> edges)
        {
            SilverlightEdge bestEdge = null;

            double distance = double.MaxValue;

            foreach (SilverlightEdge edge in edges)
            {
                double newDistance = edge.Position.CalculateDistance(CenterPoint);
                if (newDistance < distance)
                {
                    bestEdge = edge;
                    distance = newDistance;
                }
            }


            return(bestEdge);
        }
コード例 #2
0
        //∙Place K points into the space represented by the objects that are being clustered. These points represent
        //initial group centroids.
        //∙Assign each object to the group that has the closest centroid.
        //∙When all objects have been assigned, recalculate the positions of the K centroids.
        //∙Repeat Steps 2 and 3 until the centroids no longer move. This produces a separation of the objects into
        //groups from which the metric to be minimized can be calculated.
        //Table 1 and Fig. 2 show the results, after applying �-means clustering

        public List <Cluster> CreateClusters(List <SilverlightEdge> edges, int nrOfClusters)
        {
            List <Cluster> returnCluster = new List <Cluster>();

            CalculateBoundaries(edges);
            CalculateRadius();
            returnCluster = InitialClusters(edges, nrOfClusters);
            while (RecalculateClusters(edges, ref returnCluster) == false)
            {
            }


            SilverlightEdge centralEdge = GetCentralEdge(edges);

            foreach (Cluster c in returnCluster)
            {
                if (!c.Edges.Contains(centralEdge))
                {
                    c.Edges.Add(centralEdge);
                }
            }
            return(returnCluster);
        }