예제 #1
0
        public void RemoveClusterPair(ClusterNodePair clusterPair)
        {
            double outvalue;

            if (distanceMatrix.ContainsKey(clusterPair))
            {
                distanceMatrix.TryRemove(clusterPair, out outvalue);
            }
            else
            {
                distanceMatrix.TryRemove(new ClusterNodePair(clusterPair.Cluster2, clusterPair.Cluster1), out outvalue);
            }
        }
예제 #2
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);
            }
        }
예제 #3
0
 // get the distance value from a cluster pair. THIS METHOD DEPENDS ON THE EqualityComparer IMPLEMENTATION IN ClusterPair CLASS
 public double ReturnClusterPairDistance(ClusterNodePair clusterPair)
 {
     return(distanceMatrix.ContainsKey(clusterPair)
         ? distanceMatrix[clusterPair]
         : distanceMatrix[new ClusterNodePair(clusterPair.Cluster2, clusterPair.Cluster1)]); // Reverse
 }
예제 #4
0
 public void AddClusterPairAndDistance(ClusterNodePair clusterPair, double distance)
 {
     distanceMatrix.TryAdd(clusterPair, distance);
 }