/// <summary>
        /// Setups this instance.
        /// </summary>
        public void Setup()
        {
            // creates data tables
            _dataTable = new DataTable();
            // add columns to datatable
            _dataTable.Columns.Add("Название кластера");
            for (int i = 0; i < Tools.NumericDataHeadings.Length; i++)
            {
                _dataTable.Columns.Add(Tools.NumericDataHeadings[i]);
            }
            _dataTable.Columns.Add("Число обьектов");
            _contents = new StatisticPoint[contentsHeadings.Length][];

            // fill data table
            for (int i = 0; i < Clusters.Count; i++)
            {
                var list = Clusters.GetCluster(i).Centroid.Points.Select(x => $"{x}").ToList();
                list.Insert(0, $"Cluster{Clusters.GetCluster(i).Id}");
                list.Add($"{Clusters.GetCluster(i).QuantityOfDataPoints}");
                _dataTable.Rows.Add(list.ToArray());
            }

            // init contents
            for (int j = 0; j < contentsHeadings.Length; j++)
            {
                _contents[j] = new StatisticPoint[Clusters.Count];
            }

            // gets contents
            for (int i = 0; i < Clusters.Count; i++)
            {
                for (int j = 0; j < contentsHeadings.Length; j++)
                {
                    _contents[j][i]         = new StatisticPoint();
                    _contents[j][i].value   = Clusters.GetCluster(i).Centroid[j];
                    _contents[j][i].GroupId = 0;
                    _contents[j][i].index   = i;
                }
            }

            // group contents
            for (int j = 0; j < contentsHeadings.Length; j++)
            {
                _contents[j] = _contents[j].OrderBy((x) => x.value).ToArray();
                var points       = _contents[j].Select(x => x.value).ToArray();
                var indentifiers = Tools.GroupBy(points);
                for (int i = 0; i < _contents[j].Length; i++)
                {
                    _contents[j][i].GroupId = indentifiers[i];
                }
                _contents[j] = _contents[j].OrderBy((x) => x.index).ToArray();
            }

            // fill data gridview
            clustersOverviewGridView.ColumnHeadersVisible = true;
            clustersOverviewGridView.AutoSizeColumnsMode  = DataGridViewAutoSizeColumnsMode.AllCells;
            clustersOverviewGridView.DataSource           = _dataTable;
        }
Beispiel #2
0
        /// <summary>
        /// Builds the dissimilarity matrix.
        /// </summary>
        private void BuildDissimilarityMatrix()
        {
            _dissimilarityMatrix = new DissimilarityMatrix();

            for (int i = 0; i < _clusters.Count - 1; i++)
            {
                for (int j = i + 1; j < _clusters.Count; j++)
                {
                    var clusterPair = new ClusterPair(_clusters.GetCluster(i), _clusters.GetCluster(j));

                    var distanceBetweenTwoClusters = ClusterDistance.ComputeDistance(clusterPair.Cluster1, clusterPair.Cluster2, _distanceMetric);
                    _dissimilarityMatrix.AddClusterPairAndDistance(clusterPair, distanceBetweenTwoClusters); // adds distance to matrix
                }
            }
        }