Beispiel #1
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
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Updates the dissimilarity matrix after adding new cluster to matrix.
        /// </summary>
        /// <param name="newCluster">The new cluster.</param>
        private void _UpdateDissimilarityMatrix(Cluster newCluster)
        {
            for (int i = 0; i < _clusters.Count; i++)
            {
                // distance between newCluster and one of the _clusters one
                var distanceBetweenClusters = ClusterDistance.ComputeDistance(_clusters.GetCluster(i), newCluster, _dissimilarityMatrix, _strategy);
                _dissimilarityMatrix.AddClusterPairAndDistance(new ClusterPair(newCluster, _clusters.GetCluster(i)), distanceBetweenClusters); // adds distane to matrix

                // removes old cluster distance because they are useless
                _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(0), _clusters.GetCluster(i)));
                _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(1), _clusters.GetCluster(i)));
            }

            // remove the distance of the the initial cluster subclusters
            _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(0), newCluster.GetSubCluster(1)));
        }