Exemplo n.º 1
0
        public void AddClusterToHyperCluster(Cluster cluster)
        {
            ClusterList.Add(cluster);
            AdaptiveIntersect.UpdateClusterIntersectionByLast(ClusterList, HyperClusterVector);
            AdaptiveIntersect.UpdateClusterSummaryByLast(ClusterList, HyperClusterVectorSummary);

            ValidHyperClusterItemList = false;
            //TODO: rendutant analyse to remove it
            //for (int i = 0; i < cluster.ClusterItemList.Count; i++)
            //{
            //    HyperClusterItemList.Add(cluster.ClusterItemList[i]);
            //}
        }
 public void SetInitialClusterCenters()
 {
     //for (int i = 0; i < NumberOfClusters; i++)
     //{
     //    Random rnd = new Random();
     //    int num = rnd.Next(0, ElementList.Count - 1);
     //    ClusterList.Add(new Cluster(ElementList[num]), i+1);
     //}
     ClusterList.Add(new Cluster(ElementList[0], 1));
     ClusterList.Add(new Cluster(ElementList[8], 2));
     ClusterList.Add(new Cluster(ElementList[15], 3));
     ClusterList.Add(new Cluster(ElementList[17], 4));
     ClusterList.Add(new Cluster(ElementList[23], 5));
 }
Exemplo n.º 3
0
        public void AddItemToClusters(Object item)
        {
            if (!GeospatialHelperStatic.IsValidGPS(ConvertObjToGPS(item)))
            {
                return;
            }

            for (int i = 1; i <= this.numZoomLevels; i++)
            {
                // List of Clusters for this zoom level
                ClusterList      clusters       = this.zoomLevelToClusters[i - 1];
                bool             addedToCluster = false;
                BasicGeoposition itemCoord      = ConvertObjToGPS(item);

                for (int j = 0; j < clusters.Count; j++)
                {
                    if (IsWithinBoundary(itemCoord, clusters[j].Location, i))
                    {
                        clusters[j].Count += 1;
                        clusters[j].Objects.Add(item);

                        string id = String.Format("ZL{0}_C{1}", i, j);
                        this.keyToItems[id].Add(item);

                        addedToCluster = true;
                        break;
                    }
                }
                if (addedToCluster == false)
                {
                    string        id         = String.Format("ZL{0}_C{1}", i, clusters.Count);
                    List <Object> singleItem = new List <Object>()
                    {
                        item
                    };
                    clusters.Add(new Cluster()
                    {
                        ClusterId = id,
                        Objects   = singleItem,
                        Count     = 1,
                        Location  = itemCoord
                    });
                    this.keyToItems.Add(id, singleItem);
                }
                this.zoomLevelToClusters[i - 1] = clusters;
            }
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        // Perf? Do it by pictures first and then by zoom level?
        // The assumption is that the d
        public void GenerateClusteringData(IEnumerable items)
        {
            this.cachedConvertedObjects.Clear();
            this.keyToItems.Clear();
            this.zoomLevelToClusters.Clear();

            this.LeastClustersZoomLevel = 1;
            this.MostClustersZoomLevel  = 1;


            CreateValidItemsAsClusters(items);

            // 1 is space view
            // 20 is ground view
            for (int i = 1; i <= this.numZoomLevels; i++)
            {
                // List of Clusters for this zoom level
                ClusterList clusters = new ClusterList();
                foreach (var item in items)
                {
                    BasicGeoposition itemCoord = ConvertObjToGPS(item);

                    if (!GeospatialHelperStatic.IsValidGPS(itemCoord))
                    {
                        continue;
                    }

                    bool addedToCluster = false;

                    for (int j = 0; j < clusters.Count; j++)
                    {
                        if (IsWithinBoundary(itemCoord, clusters[j].Location, i))
                        {
                            clusters[j].Count += 1;
                            clusters[j].Objects.Add(item);

                            string id = String.Format("ZL{0}_C{1}", i, j);
                            this.keyToItems[id].Add(item);

                            addedToCluster = true;
                            break;
                        }
                    }
                    if (addedToCluster == false)
                    {
                        string        id         = String.Format("ZL{0}_C{1}", i, clusters.Count);
                        List <Object> singleItem = new List <Object>()
                        {
                            item
                        };

                        clusters.Add(new Cluster()
                        {
                            ClusterId = id,
                            Objects   = singleItem,
                            Count     = 1,
                            Location  = itemCoord
                        });
                        List <Object> otherSingleItem = new List <Object>()
                        {
                            item
                        };
                        this.keyToItems.Add(id, otherSingleItem);
                    }
                }
                if (this.zoomLevelToClusters.Count > 1)
                {
                    int minClusters = this.zoomLevelToClusters[this.LeastClustersZoomLevel - 1].Count;
                    int maxClusters = this.zoomLevelToClusters[this.MostClustersZoomLevel - 1].Count;

                    // eg: 1 1 1 3 5 5 7 7 7, this will do the 1s. See definition for what these two are
                    if (clusters.Count <= minClusters)
                    {
                        this.LeastClustersZoomLevel = i;
                    }
                    if (clusters.Count > maxClusters)
                    {
                        this.MostClustersZoomLevel = i;
                    }
                }

                this.zoomLevelToClusters.Add(clusters);
            }
            RecalculateCenters();
        }