Exemplo n.º 1
0
        /// <summary>
        /// Normalizes cluster's datapoints using the specified normalize method.
        /// </summary>
        /// <param name="normalizeMethod">The normalize method.</param>
        public void Normalize(NormalizeMethod normalizeMethod)
        {
            // if there is no normalization
            if (normalizeMethod == NormalizeMethod.None)
            {
                return;
            }


            int pointCount    = ClustersList[0].DataPoints[0].Count; // datapoints count
            int clustersCount = ClustersList.Count;                  // clusters count

            // gets all data subgrouped by their datapoints
            double[][] dataArray = new double[pointCount][];

            for (int i = 0; i < pointCount; i++)
            {
                dataArray[i] = new double[clustersCount];
                for (int j = 0; j < clustersCount; j++)
                {
                    dataArray[i][j] = ClustersList[j].DataPoints[0][i];
                }
            }

            // normalizes data
            if (normalizeMethod == NormalizeMethod.MinMax)
            {
                for (int i = 0; i < pointCount; i++)
                {
                    Tools.MinMaxNormalize(ref dataArray[i]);
                }
            }
            else if (normalizeMethod == NormalizeMethod.ZScore)
            {
                for (int i = 0; i < pointCount; i++)
                {
                    Tools.ZScoreNormalize(ref dataArray[i]);
                }
            }

            // updates data with normalized one
            for (int i = 0; i < pointCount; i++)
            {
                for (int j = 0; j < ClustersList.Count; j++)
                {
                    ClustersList[j].DataPoints[0][i] = dataArray[i][j];
                }
            }
        }
Exemplo n.º 2
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}";
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the Click event of the doClusteringButton 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">
        /// Введите правилное количество кластеров. - Ошибка при вводе числа кластеров
        /// or
        /// Не было выбрано не одного показателя. - Ощибка при выборе показателей
        /// </exception>
        private void doClusteringButton_Click(object sender, EventArgs e)
        {
            // Gets selected parameters of clustering
            distanceMetric  = (DistanceMetric)distanceSelectComboBox.SelectedIndex;
            strategy        = (MergeStrategy)strategySelectComboBox.SelectedIndex;
            normalizeMethod = (NormalizeMethod)normalizeMethodSelectComboBox.SelectedIndex;

            // checks for correct cluster number
            if (int.TryParse(clusterCountTextBox.Text, out var tmp) && tmp > 0 && tmp < Tools.Data.Rows.Count)
            {
                countOfClusters = tmp;
            }
            else
            {
                throw new CustomException("Введите правилное количество кластеров.", "Ошибка при вводе числа кластеров");
            }

            // 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("Не было выбрано не одного показателя.", "Ощибка при выборе показателей");
            }

            Tools.isChosen       = isChosen;
            isParametersSelected = true;
            Close();
        }
 /// <inheritdoc cref ="INormalizeAggregation.Method"/>
 public NormalizeAggregationDescriptor Method(NormalizeMethod method) =>
 Assign(method, (a, v) => a.Method = v);