Пример #1
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);
        }
Пример #2
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));
        }