Beispiel #1
0
 public double ReturnClusterPairDistance(ClusterPair clusterPair)
 {
     if (_distanceMatrix.ContainsKey(clusterPair))
     {
         return(_distanceMatrix[clusterPair]);
     }
     else
     {
         return(_distanceMatrix[new ClusterPair(clusterPair.Cluster2, clusterPair.Cluster1)]);
     }
 }
Beispiel #2
0
 public void RemoveClusterPair(ClusterPair clusterPair)
 {
     if (_distanceMatrix.ContainsKey(clusterPair))
     {
         _distanceMatrix.TryRemove(clusterPair, out _);
     }
     else
     {
         _distanceMatrix.TryRemove(new ClusterPair(clusterPair.Cluster2, clusterPair.Cluster1), out _);
     }
 }
        private IEnumerable <ClusterPair> _ClusterPairCollection()
        {
            ClusterPair clusterPair;

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

                    yield return(clusterPair);
                }
            }
        }
Beispiel #4
0
        public ClusterPair GetClosestClusterPair()
        {
            double      minDistance        = double.MaxValue;
            ClusterPair closestClusterPair = new ClusterPair();

            foreach (var item in _distanceMatrix)
            {
                if (item.Value < minDistance)
                {
                    minDistance        = item.Value;
                    closestClusterPair = item.Key;
                }
            }

            return(closestClusterPair);
        }
        private void BuildHierarchicalClustering(int indexNewCluster, ClusterDistanceStrategy 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)
            _clusters.RemoveCluster(closestClusterPair.Cluster1);
            _clusters.RemoveCluster(closestClusterPair.Cluster2);
            _UpdateDissimilarityMatrix(newCluster, strategy);
            //add the new cluster to clustering
            _clusters.AddCluster(newCluster);

            // 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);
            }
        }
Beispiel #6
0
 public void AddClusterPairAndDistance(ClusterPair clusterPair, double distance)
 {
     _distanceMatrix.TryAdd(clusterPair, distance);
 }