Пример #1
0
        private static void RunClusteringAlgorithm(ArffParser.ArffRelation relation, int k, bool randomInitials)
        {
            var    clusterer    = new Clusterer.KClusterer(k, relation, randomInitials);
            double squaredError = clusterer.TotalSquaredError();

            PrintMessage(clusterer, 1);

            clusterer.ReCluster();
            double nextSquaredError = clusterer.TotalSquaredError();
            int    iteration        = 2;

            PrintMessage(clusterer, iteration);
            while (nextSquaredError != squaredError)
            {
                iteration++;
                clusterer.ReCluster();
                squaredError     = nextSquaredError;
                nextSquaredError = clusterer.TotalSquaredError();
                PrintMessage(clusterer, iteration);
            }
        }
Пример #2
0
        private static void PrintMessage(Clusterer.KClusterer clusterer, int iteration)
        {
            var builder = new System.Text.StringBuilder();

            builder.Append(SEPARATOR + "\n" + SEPARATOR + "\n");
            builder.Append(string.Format(ITERATION_MESSAGE, iteration) + "\n");
            builder.Append(SEPARATOR + "\n");
            builder.Append(clusterer.ClusterData() + "\n");
            builder.Append(string.Format(SSE_MESSAGE, clusterer.TotalSquaredError()) + "\n");
            builder.Append(SEPARATOR + "\n" + SEPARATOR + "\n");

            Console.WriteLine(builder.ToString());
        }