Ejemplo n.º 1
0
        private void BuildHierarchicalClustering(int indexNewCluster, ClusterDistance.Strategy strategy, int k)
        {
            ClusterPair closestClusterPair = this._GetClosestClusterPairInDissimilarityMatrix();

            // create a new cluster by merge the closest cluster pair
            Cluster newCluster = new Cluster();

            newCluster.AddSubCluster(closestClusterPair.Cluster1);
            newCluster.AddSubCluster(closestClusterPair.Cluster2);
            newCluster.Id = indexNewCluster;
            newCluster.UpdateTotalQuantityOfPatterns(); //update the total quantity of patterns of the new cluster (this quantity is used by UPGMA clustering strategy)

            //remove the closest cluster pair from the clustering data structure (clusters)
            _clusters.RemoveClusterPair(closestClusterPair);
            _UpdateDissimilarityMatrix(newCluster, strategy);
            //add the new cluster to clustering
            _clusters.AddCluster(newCluster);
            closestClusterPair = null;

            // recursive call of this method while there is more than 1 cluster (k>2) in the clustering
            if (_clusters.Count() > k)
            {
                this.BuildHierarchicalClustering(indexNewCluster + 1, strategy, k);
            }
        }
Ejemplo n.º 2
0
        public Clusters ExecuteClustering(ClusterDistance.Strategy strategy, int k)
        {
            // Step 1
            // build a clustering only with singleton clusters
            this._BuildSingletonCluster();
            //build the dissimilarity matrix
            this._BuildDissimilarityMatrixParallel();

            // Step 3
            // build the hierarchical clustering
            this.BuildHierarchicalClustering(_clusters.Count(), strategy, k);

            return(_clusters); //represents the clustering data structure
        }
Ejemplo n.º 3
0
        public ClusterNodeCollection ExecuteClustering(ClusterDistance.Strategy strategy, int k)
        {
            nodeCollection.BuildSingletonCluster(leafCollection);

            dissimilarityMatrix = new DissimilarityMatrix();
            foreach (ClusterNodePair clusterPair in GetClusterPairCollection())
            {
                double distanceBetweenTwoClusters = ClusterDistance.ComputeLeafDistance(clusterPair.Cluster1, clusterPair.Cluster2);
                dissimilarityMatrix.AddClusterPairAndDistance(clusterPair, distanceBetweenTwoClusters);
            }

            BuildHierarchicalClustering(nodeCollection.Count, strategy, k);

            return(nodeCollection);
        }
Ejemplo n.º 4
0
        // update dissimilarity matrix with the distance of the new formed cluster
        private void _UpdateDissimilarityMatrix(Cluster newCluster, ClusterDistance.Strategy strategie)
        {
            double distanceBetweenClusters;

            for (int i = 0; i < _clusters.Count(); i++)
            {
                // compute the distance between old clusters to the new cluster
                distanceBetweenClusters = ClusterDistance.ComputeDistance(_clusters.GetCluster(i), newCluster, _dissimilarityMatrix, strategie);
                // insert the new cluster's distance
                _dissimilarityMatrix.AddClusterPairAndDistance(new ClusterPair(newCluster, _clusters.GetCluster(i)), distanceBetweenClusters);
                //remove all old distance values of the old clusters (subclusters of the newcluster)
                _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(0), _clusters.GetCluster(i)));
                _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(1), _clusters.GetCluster(i)));
            }

            // finally, remove the distance of the old cluster pair
            _dissimilarityMatrix.RemoveClusterPair(new ClusterPair(newCluster.GetSubCluster(0), newCluster.GetSubCluster(1)));
        }
Ejemplo n.º 5
0
        private void UpdateDissimilarityMatrix(ClusterNode newNode, ClusterDistance.Strategy strategie)
        {
            ClusterNode node1 = newNode.NodeAt(0);
            ClusterNode node2 = newNode.NodeAt(1);

            for (int i = 0; i < nodeCollection.Count; i++)
            {
                ClusterNode node = nodeCollection.ElementAt(i);

                double distanceBetweenClusters = ClusterDistance.ComputeNodeDistance(node, newNode, dissimilarityMatrix, strategie);

                dissimilarityMatrix.AddClusterPairAndDistance(new ClusterNodePair(newNode, node), distanceBetweenClusters);
                dissimilarityMatrix.RemoveClusterPair(new ClusterNodePair(node1, node));
                dissimilarityMatrix.RemoveClusterPair(new ClusterNodePair(node2, node));
            }

            dissimilarityMatrix.RemoveClusterPair(new ClusterNodePair(node1, node2));
        }
Ejemplo n.º 6
0
        private void BuildHierarchicalClustering(int indexNewNode, ClusterDistance.Strategy strategy, int k)
        {
            ClusterNodePair closestClusterPair = dissimilarityMatrix.GetClosestClusterPair();

            ClusterNode newNode = new ClusterNode();

            newNode.Add(closestClusterPair.Cluster1);
            newNode.Add(closestClusterPair.Cluster2);
            newNode.Id       = indexNewNode;
            newNode.Distance = dissimilarityMatrix.ReturnClusterPairDistance(closestClusterPair);
            newNode.UpdateTotalLeafs();

            nodeCollection.Remove(closestClusterPair.Cluster1);
            nodeCollection.Remove(closestClusterPair.Cluster2);
            UpdateDissimilarityMatrix(newNode, strategy);

            nodeCollection.Add(newNode);

            if (nodeCollection.Count > k)
            {
                BuildHierarchicalClustering(indexNewNode + 1, strategy, k);
            }
        }