private long [ ] determinePreferenceVectorByApriori ( Relation < V > relation , ModifiableDBIDs [ ] neighborIDs , StringBuilder msg ) { int dimensionality = neighborIDs . length ; // database for apriori UpdatableDatabase apriori_db = new HashmapDatabase ( ) ; SimpleTypeInformation < ? > bitmeta = VectorFieldTypeInformation . typeRequest ( BitVector . class , dimensionality , dimensionality ) ; for ( DBIDIter it = relation . iterDBIDs ( ) ; it . valid ( ) ; it . advance ( ) ) { long [ ] bits = BitsUtil . zero ( dimensionality ) ; boolean allFalse = true ; for ( int d = 0 ; d < dimensionality ; d ++ ) { if ( neighborIDs [ d ] . contains ( it ) ) { BitsUtil . setI ( bits , d ) ; allFalse = false ; } } if ( ! allFalse ) { SingleObjectBundle oaa = new SingleObjectBundle ( ) ; oaa . append ( bitmeta , new BitVector ( bits , dimensionality ) ) ; apriori_db . insert ( oaa ) ; } } APRIORI apriori = new APRIORI ( minpts ) ; FrequentItemsetsResult aprioriResult = apriori . run ( apriori_db ) ; // result of apriori List < Itemset > frequentItemsets = aprioriResult . getItemsets ( ) ; if ( msg != null ) { msg . append ( "\n Frequent itemsets: " ) . append ( frequentItemsets ) ; } int maxSupport = 0 , maxCardinality = 0 ; long [ ] preferenceVector = BitsUtil . zero ( dimensionality ) ; for ( Itemset itemset : frequentItemsets ) { if ( ( maxCardinality < itemset . length ( ) ) || ( maxCardinality == itemset . length ( ) && maxSupport == itemset . getSupport ( ) ) ) { preferenceVector = Itemset . toBitset ( itemset , BitsUtil . zero ( dimensionality ) ) ; maxCardinality = itemset . length ( ) ; maxSupport = itemset . getSupport ( ) ; } } if ( msg != null ) { msg . append ( "\n preference " ) // . append ( BitsUtil . toStringLow ( preferenceVector , dimensionality ) ) // . append ( ' ' ) ; LOG . debugFine ( msg . toString ( ) ) ; } return preferenceVector ; }
Determines the preference vector with the apriori strategy .