question: @ Override public double [ ] distributionForInstance ( Instance instance ) throws Exception { double [ ] probOfClassGivenDoc = new double [ m_numClasses ] ; double [ ] logDocGivenClass = new double [ m_numClasses ] ; for ( int c = 0 ; c < m_numClasses ; c ++ ) { logDocGivenClass [ c ] += Math . log ( m_probOfClass [ c ] ) ; int allWords = 0 ; for ( int i = 0 ; i < instance . numValues ( ) ; i ++ ) { if ( instance . index ( i ) == instance . classIndex ( ) ) { continue ; } double frequencies = instance . valueSparse ( i ) ; allWords += frequencies ; logDocGivenClass [ c ] += frequencies * Math . log ( m_probOfWordGivenClass [ c ] [ instance . index ( i ) ] ) ; } logDocGivenClass [ c ] -= allWords * Math . log ( m_wordsPerClass [ c ] ) ; } double max = logDocGivenClass [ Utils . maxIndex ( logDocGivenClass ) ] ; for ( int i = 0 ; i < m_numClasses ; i ++ ) { probOfClassGivenDoc [ i ] = Math . exp ( logDocGivenClass [ i ] - max ) ; } Utils . normalize ( probOfClassGivenDoc ) ; return probOfClassGivenDoc ; }
target:  Calculates the class membership probabilities for the given test instance.