示例#1
0
        public bool RemoveClusterFromHyperCluster(Cluster cluster)
        {
            if (ClusterList.Remove(cluster) == true)
            {
                if (ClusterList.Count > 0)
                {
                    AdaptiveIntersect.CalculateClusterIntersection(ClusterList, HyperClusterVector);
                    AdaptiveIntersect.CalculateClusterSummary(ClusterList, HyperClusterVectorSummary);

                    //TODO: redundant analyse to remove it
                    // nie ma senzu sa kazdym razem tworzyc listy, tylko wtedy gdy bedzie do niej potrzebny dostep
                    //HyperClusterItemList.Clear();
                    //for(int i=0; i< ClusterList.Count; i++)
                    //{
                    //    for(int j = 0; j < ClusterList[i].ClusterItemList.Count; j++)
                    //    {
                    //        HyperClusterItemList.Add(ClusterList[i].ClusterItemList[j]);
                    //    }
                    //}
                }
                ValidHyperClusterItemList = false;
            }
            return(ClusterList.Count > 0);
        }
示例#2
0
        public void AssignCluster(FeatureItem item)
        {
            int    iterationCounter     = IterationLimit; //assign IterationLimit
            bool   isAssignementChanged = true;
            double itemVectorMagnitude  = CalculateVectorMagnitude(item.FeatureVector);

            while (isAssignementChanged && iterationCounter > 0)
            {
                isAssignementChanged = false;

                List <KeyValuePair <Cluster, double> > clusterToProximityList = new List <KeyValuePair <Cluster, double> >();
                double proximityThreshold = itemVectorMagnitude / (bValue + rangeLimit * FeatureItemSize);  // ||E_i||/(b+1)

                //Calculate proximity values for item and clusters
                for (int i = 0; i < ClusterList.Count; i++)
                {
                    double clusterVectorMagnitude = CalculateVectorMagnitude(ClusterList[i].ClusterVector);
                    double proximity = CaulculateVectorIntersectionMagnitude(item.FeatureVector, ClusterList[i].ClusterVector) / (bValue + clusterVectorMagnitude); //prox = ||C_j and E_i ||/ (b + ||E_i||) > proxThres
                    if (proximity > proximityThreshold)
                    {
                        clusterToProximityList.Add(new KeyValuePair <Cluster, double>(ClusterList[i], proximity));
                    }
                }

                if (clusterToProximityList.Count > 0)                                        //???? tutaj zobaczyc, czy nie trzeba sprawdzic dodania lub ominiecia dodania
                {
                    clusterToProximityList.Sort((x, y) => - 1 * x.Value.CompareTo(y.Value)); //sorting in place in descending order

                    //search from the maximum proximity to smallest
                    for (int i = 0; i < clusterToProximityList.Count; i++)
                    {
                        Cluster newCluster = clusterToProximityList[i].Key;
                        double  vigilance  = CaulculateVectorIntersectionMagnitude(newCluster.ClusterVector, item.FeatureVector) / itemVectorMagnitude;
                        if (vigilance >= pValue)                       //passed all tests and has max proximity
                        {
                            if (ItemToClusterMap.ContainsKey(item.Id)) //find cluster with this item
                            {
                                Cluster previousCluster = ItemToClusterMap[item.Id];
                                if (ReferenceEquals(newCluster, previousCluster))
                                {
                                    break;                                                  //if the best is the same, then it will break (not considered others)
                                }
                                if (previousCluster.RemoveItemFromCluster(item) == false)   //the cluster is empty
                                {
                                    ClusterList.Remove(previousCluster);
                                }
                            }
                            //Add item to the current cluster
                            newCluster.AddItemToCluster(item);
                            ItemToClusterMap[item.Id] = newCluster;
                            isAssignementChanged      = true;
                            break;
                        }
                    }
                }

                if (ItemToClusterMap.ContainsKey(item.Id) == false)
                {
                    Cluster newCluster = new Cluster(item);
                    ClusterList.Add(newCluster);
                    ItemToClusterMap.Add(item.Id, newCluster);
                    isAssignementChanged = true;
                }

                iterationCounter--;
            }

            AssignHyperCluster();
        }