Exemplo n.º 1
0
        /// <summary>
        ///     Let data be a set of n elements, then co-membership
        ///     is an n by n matrix with (i,j)th element equal to 1
        ///     if i and j fall into the same cluster from the clusters set, 0 otherwise.
        ///     The clusters and data can come from different samples (of the same population)
        /// </summary>
        /// <param name="learningCluster"></param>
        /// <param name="testingClusterPoints"></param>
        /// <returns></returns>
        private int[][] co_membership(KMeans learningCluster, List <Point> testingClusterPoints)
        {
            int len = testingClusterPoints.Count;

            int[][] m = new int[len][];
            for (int i = 0; i < len; i++)
            {
                m[i] = new int[len];
            }

            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len; j++)
                {
                    if (i != j)
                    {
                        for (int k = 0; k < learningCluster.K; k++)
                        {
                            int i_centroid = learningCluster.GetClosestCentroid(testingClusterPoints[i]);

                            int j_centroid = learningCluster.GetClosestCentroid(testingClusterPoints[j]);

                            if (i_centroid == j_centroid)
                            {
                                m[i][j] = 1;
                                break;
                            }
                            else
                            {
                                m[i][j] = 0;
                            }
                        }
                    }
                }
            }

            return(m);
        }
        /// <summary>
        ///     Let data be a set of n elements, then co-membership 
        ///     is an n by n matrix with (i,j)th element equal to 1
        ///     if i and j fall into the same cluster from the clusters set, 0 otherwise.
        ///     The clusters and data can come from different samples (of the same population) 
        /// </summary>
        /// <param name="learningCluster"></param>
        /// <param name="testingClusterPoints"></param>
        /// <returns></returns>
        private int[][] co_membership(KMeans learningCluster, List<Point> testingClusterPoints)
        {
            int len = testingClusterPoints.Count;
            int[][] m = new int[len][];
            for (int i = 0; i < len; i++)
            {
                m[i] = new int[len];
            }

            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len; j++)
                {
                    if (i != j)
                    {
                        for (int k = 0; k < learningCluster.K; k++)
                        {
                            int i_centroid = learningCluster.GetClosestCentroid(testingClusterPoints[i]);

                            int j_centroid = learningCluster.GetClosestCentroid(testingClusterPoints[j]);

                            if (i_centroid == j_centroid){
                                m[i][j] = 1;
                                break;
                            }
                            else
                                m[i][j] = 0;
                        }
                    }
                }
            }

            return m;
        }