private HashSet [ ] getTopCombinations ( int n ) { final HashMap < HashSet , Integer > count = new HashMap < HashSet , Integer > ( ) ; HashMap < HashSet , Integer > isets = new HashMap < HashSet , Integer > ( ) ; int N = 100000 ; double lc = 0.0 ; for ( int i = 0 ; i < N ; i ++ ) { HashSet Y = generateSet ( ) ; lc += Y . size ( ) ; count . put ( Y , count . get ( Y ) != null ? count . get ( Y ) + 1 : 1 ) ; } lc = lc / N ; // @TODO could generate closed frequent itemsets from 'count' List < HashSet > top_set = new ArrayList < HashSet > ( count . keySet ( ) ) ; // Sort the sets by their count Collections . sort ( top_set , new Comparator < HashSet > ( ) { @ Override public int compare ( HashSet Y1 , HashSet Y2 ) { return count . get ( Y2 ) . compareTo ( count . get ( Y1 ) ) ; } } ) ; System . err . println ( "The most common labelsets (from which we will build the map) will likely be: " ) ; HashSet map_set [ ] = new HashSet [ n ] ; double weights [ ] = new double [ n ] ; int idx = 0 ; for ( HashSet Y : top_set ) { System . err . println ( " " + Y + " : " + ( count . get ( Y ) * 100.0 / N ) + "%" ) ; weights [ idx ++ ] = count . get ( Y ) ; if ( idx == weights . length ) { break ; } } double sum = Utils . sum ( weights ) ; System . err . println ( "Estimated Label Cardinality: " + lc + "\n\n" ) ; System . err . println ( "Estimated % Unique Labelsets: " + ( count . size ( ) * 100.0 / N ) + "%\n\n" ) ; // normalize weights[] Utils . normalize ( weights ) ; // add sets to the map set, according to their weights for ( int i = 0 , k = 0 ; i < top_set . size ( ) && k < map_set . length ; i ++ ) { // i'th combination (pre) int num = ( int ) Math . round ( Math . max ( weights [ i ] * map_set . length , 1.0 ) ) ; // i'th weight for ( int j = 0 ; j < num && k < map_set . length ; j ++ ) { map_set [ k ++ ] = top_set . get ( i ) ; } } // shuffle Collections . shuffle ( Arrays . asList ( map_set ) ) ; // return return map_set ; }
GetTopCombinations . Calculating the full joint probability distribution is too complex . - sample from the approximate joint many times - record the the n most commonly ocurring Y and their frequencies - create a map based on these frequencies