private HashMap < DensityGrid , CharacteristicVector > adjustForTransitionalGrid ( DensityGrid dg , CharacteristicVector cv , int dgClass ) { //System.out.print("Density grid "+dg.toString()+" is adjusted as a transitional grid at time "+this.getCurrTime()+". "); // Among all neighbours of dg, find the grid h whose cluster ch has the largest size // and satisfies that dg would be an outside grid if added to it GridCluster ch ; // The cluster, ch, of h double hChosenSize = 0.0 ; // The size of ch, the largest cluster DensityGrid dgH ; // The neighbour of dg being considered int hClass = NO_CLASS ; // The class label of h int hChosenClass = NO_CLASS ; // The class label of ch Iterator < DensityGrid > dgNeighbourhood = dg . getNeighbours ( ) . iterator ( ) ; HashMap < DensityGrid , CharacteristicVector > glNew = new HashMap < DensityGrid , CharacteristicVector > ( ) ; while ( dgNeighbourhood . hasNext ( ) ) { dgH = dgNeighbourhood . next ( ) ; if ( this . grid_list . containsKey ( dgH ) ) { hClass = this . grid_list . get ( dgH ) . getLabel ( ) ; if ( hClass != NO_CLASS ) { ch = this . cluster_list . get ( hClass ) ; if ( ( ch . getWeight ( ) > hChosenSize ) && ! ch . isInside ( dg , dg ) ) { hChosenSize = ch . getWeight ( ) ; hChosenClass = hClass ; } } } } //System.out.println(" Chosen neighbour is from cluster "+hChosenClass+", dgClass is "+dgClass+"."); if ( hChosenClass != NO_CLASS && hChosenClass != dgClass ) { ch = this . cluster_list . get ( hChosenClass ) ; ch . addGrid ( dg ) ; this . cluster_list . set ( hChosenClass , ch ) ; if ( dgClass != NO_CLASS ) { GridCluster c = this . cluster_list . get ( dgClass ) ; c . removeGrid ( dg ) ; this . cluster_list . set ( dgClass , c ) ; } cv . setLabel ( hChosenClass ) ; glNew . put ( dg , cv ) ; } return glNew ; }
Adjusts the clustering of a transitional density grid . Implements lines 20 and 21 from Figure 4 of Chen and Tu 2007 .