示例#1
0
        /// <summary>
        /// Handles the Click event of the calculateClusterCountButton control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        /// <exception cref="Clusterizer.CustomException">Не было выбрано ни одного показателя. - Ощибка при выборе показателей</exception>
        private void calculateClusterCountButton_Click(object sender, EventArgs e)
        {
            // gets selected parameters of clustering
            distanceMetric  = (DistanceMetric)distanceSelectComboBox.SelectedIndex;
            strategy        = (MergeStrategy)strategySelectComboBox.SelectedIndex;
            normalizeMethod = (NormalizeMethod)normalizeMethodSelectComboBox.SelectedIndex;

            // gets selected datapoints
            var  isChosen   = new bool[Tools.NumericDataHeadings.Length];
            bool isAllFalse = true;
            int  ind        = 0;

            for (int i = 0; i < pointsSelectTreeView.Nodes.Count; i++)
            {
                for (int j = 0; j < pointsSelectTreeView.Nodes[i].Nodes.Count; j++)
                {
                    isChosen[ind] = pointsSelectTreeView.Nodes[i].Nodes[j].Checked;
                    if (isAllFalse)
                    {
                        isAllFalse = !isChosen[ind];
                    }
                    ind++;
                }
            }

            // check if no datapoint is selected
            if (isAllFalse)
            {
                throw new CustomException("Не было выбрано ни одного показателя.", "Ощибка при выборе показателей");
            }


            // gets cluster set from data
            var clusters = Tools.Data.GetClusterSet(Tools.isChosen);

            clusters.Normalize(normalizeMethod);

            // executes clustering for determining recomended count of clusters
            Agnes agnes = new Agnes(clusters,
                                    distanceMetric, strategy);

            agnes.ExecuteClustering(2, true);

            // gets recomended count of clusters
            countOfClusters          = agnes.GetRecommendedCountOfClusters();
            clusterCountTextBox.Text = $"{countOfClusters}";
        }
示例#2
0
        /// <summary>
        /// Handles the Click event of the clusterizeToolStripMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        private void clusterizeToolStripMenuItem_Click(object sender, EventArgs e)
        {
            // shows form
            var clusterizeForm = new ClusterizeForm();

            clusterizeForm.ShowDialog();

            if (Tools.Data != null && clusterizeForm.isParametersSelected)
            {
                // updates data
                Tools.Data.UpdateRows();

                // get clusterset
                var clusters = Tools.Data.GetClusterSet(Tools.isChosen);
                Tools.Clusters = clusters;

                // backups clusters before normalization
                _dataPointsBeforeNormalization = new List <DataPoint>();
                for (var i = 0; i < clusters.ClustersList.Count; i++)
                {
                    _dataPointsBeforeNormalization.Add(
                        new DataPoint(new List <double>(clusters[i].DataPoints[0].Points)));
                    _dataPointsBeforeNormalization[i].Id = i;
                }

                // normalize clusters
                clusters.Normalize(clusterizeForm.normalizeMethod);
                var agnes = new Agnes(clusters,
                                      clusterizeForm.distanceMetric, clusterizeForm.strategy);

                // execute clustering
                Tools.Clusters = agnes.ExecuteClustering(clusterizeForm.countOfClusters);

                // builds components
                BuildTreeView();
                BuildResultTable();
                tabControl.SelectTab(1);

                // enables functions
                buildDendrogramToolStripMenuItem.Enabled     = true;
                showClusterOverviewToolStripMenuItem.Enabled = true;
                exportToolStripMenuItem.Enabled = true;

                Task.Factory.StartNew(() =>
                {
                    // shows form
                    statisticsForm = new StatisticsForm
                    {
                        contentsHeadings = Tools.Data.GetChosenDataPointNames(Tools.isChosen),
                        Clusters         = new ClusterSet
                        {
                            ClustersList = Tools.Clusters.ClustersList.GetRange(0, Tools.Clusters.Count)
                        }
                    };

                    // setup form
                    statisticsForm.Clusters.ClustersList.ForEach(RestoreClusterSet);
                    statisticsForm.Setup();
                });
            }
        }