Пример #1
0
        public void TestClusterAlgorithmOnExample()
        {
            ClusterData             data    = new ClusterData(GetTestData(), new string[] { "X", "Y" });
            ClusterAlgorithmOptions options = new ClusterAlgorithmOptions(5);

            var result = KmeansClusterAlgorithm.Analyze(data, options);

            Assert.IsTrue(result.ClusterAssignment.Length > 0);
            Trace.WriteLine($"Iterations: {result.Iterations}");
            Trace.WriteLine(result.PrintCsvResult());
        }
Пример #2
0
        public void TestBigSet()
        {
            int cols = 5;
            int rows = 5000;

            string[] attributes = new string[cols];
            for (int i = 0; i < cols; i++)
            {
                attributes[i] = "Col_" + i.ToString();
            }

            ClusterAlgorithmOptions options = new ClusterAlgorithmOptions(3, true);
            ClusterData             data    = new ClusterData(GetRandomDataSet(rows, cols, 2000), attributes);

            ClusterResult result = KmeansClusterAlgorithm.Analyze(data, options);

            Assert.IsTrue(result.Iterations > 0);
            Trace.WriteLine($"Iterations: {result.Iterations}");
            Trace.WriteLine(result.PrintCsvResult());
        }
Пример #3
0
        private async void ExportButton_Click(object sender, RoutedEventArgs e)
        {
            ClusterButton.IsEnabled = false;
            ClusterButton.IsEnabled = false;
            LoadCsvButton.IsEnabled = false;
            BusyIndication.IsActive = true;

            int clusters = (int)(ClusterCountRange.UpperValue);

            if (MessageBox.Show($"Run with {clusters} Clusters?", "Get Results", MessageBoxButton.YesNo, MessageBoxImage.Question)
                == MessageBoxResult.Yes)
            {
                int  runs      = (int)(RandomRuns.Value.Value);
                bool normalize = NormalizeSwitch.IsChecked.Value;

                var analysis = await Task.Run(() => ClusterSolver.Cluster(clusterData, clusters, clusters, runs, normalize));

                var seed    = analysis[0].BestSeed;
                var options = new ClusterAlgorithmOptions(clusters, seed, normalize);
                var result  = await Task.Run(() => KmeansClusterAlgorithm.Analyze(clusterData, options));


                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "Csv files (*.csv)|*.csv|Text files (*.txt)|*.txt";

                if (saveFileDialog.ShowDialog() == true)
                {
                    using (var writer = new StreamWriter(File.Create(saveFileDialog.FileName)))
                    {
                        string csv = result.PrintCsvResult();
                        writer.Write(csv);
                    }
                }
            }
            ClusterButton.IsEnabled = true;
            ClusterButton.IsEnabled = true;
            LoadCsvButton.IsEnabled = true;
            BusyIndication.IsActive = false;
        }