public AssociativeArray2D getWordProbabilitiesPerTopic ( ) { AssociativeArray2D ptw = new AssociativeArray2D ( ) ; ModelParameters modelParameters = knowledgeBase . getModelParameters ( ) ; TrainingParameters trainingParameters = knowledgeBase . getTrainingParameters ( ) ; //initialize a probability list for every topic int k = trainingParameters . getK ( ) ; for ( int topicId = 0 ; topicId < k ; ++ topicId ) { ptw . put ( topicId , new AssociativeArray ( ) ) ; } int d = modelParameters . getD ( ) ; double beta = trainingParameters . getBeta ( ) ; Map < List < Object > , Integer > topicWordCounts = modelParameters . getTopicWordCounts ( ) ; Map < Integer , Integer > topicCounts = modelParameters . getTopicCounts ( ) ; for ( Map . Entry < List < Object > , Integer > entry : topicWordCounts . entrySet ( ) ) { List < Object > tpk = entry . getKey ( ) ; Integer topicId = ( Integer ) tpk . get ( 0 ) ; Object word = tpk . get ( 1 ) ; Integer njw = entry . getValue ( ) ; Integer nj = topicCounts . get ( topicId ) ; double probability = ( njw + beta ) / ( nj + beta * d ) ; ptw . get ( topicId ) . put ( word , probability ) ; } for ( int topicId = 0 ; topicId < k ; ++ topicId ) { ptw . put ( topicId , MapMethods . sortAssociativeArrayByValueDescending ( ptw . get ( topicId ) ) ) ; } return ptw ; }
Returns the distribution of the words in each topic .