final public double score ( StringWrapper s , StringWrapper t ) { BagOfTokens sBag = ( BagOfTokens ) s ; BagOfTokens tBag = ( BagOfTokens ) t ; double sum = 0 ; for ( Iterator i = sBag . tokenIterator ( ) ; i . hasNext ( ) ; ) { Token tok = ( Token ) i . next ( ) ; if ( tBag . contains ( tok ) ) { double ps = sBag . getWeight ( tok ) ; double pt = tBag . getWeight ( tok ) ; sum -= h ( ps + pt ) - h ( ps ) - h ( pt ) ; } } return 0.5 * sum / Math . log ( 2 ) ; }
Jensen - Shannon distance between distributions .