public static double KullbackLeiblerDivergence ( double [ ] p , double [ ] q ) { boolean intersection = false ; double k = 0 ; for ( int i = 0 ; i < p . length ; i ++ ) { if ( p [ i ] != 0 && q [ i ] != 0 ) { intersection = true ; k += p [ i ] * Math . log ( p [ i ] / q [ i ] ) ; } } if ( intersection ) return k ; else return Double . POSITIVE_INFINITY ; }
Gets the Kullback Leibler divergence .