private double getMCEntropy ( int [ ] [ ] mat , ArrayList < int [ ] > partsx , ArrayList < int [ ] > partsy , int size , int gridsize , double loggrid ) { // Margin entropies: double [ ] mx = new double [ gridsize ] ; double [ ] my = new double [ gridsize ] ; for ( int i = 0 ; i < gridsize ; i ++ ) { // Note: indexes are a bit tricky here, because we compute both margin // entropies at the same time! final double sumx = ( double ) partsx . get ( i ) . length ; final double sumy = ( double ) partsy . get ( i ) . length ; for ( int j = 0 ; j < gridsize ; j ++ ) { double px = mat [ i ] [ j ] / sumx ; double py = mat [ j ] [ i ] / sumy ; if ( px > 0. ) { mx [ i ] -= px * FastMath . log ( px ) ; } if ( py > 0. ) { my [ i ] -= py * FastMath . log ( py ) ; } } } // Weighted sums of margin entropies. double sumx = 0. , sumy = 0. ; for ( int i = 0 ; i < gridsize ; i ++ ) { sumx += mx [ i ] * partsx . get ( i ) . length ; sumy += my [ i ] * partsy . get ( i ) . length ; } double max = ( ( sumx > sumy ) ? sumx : sumy ) ; return max / ( size * loggrid ) ; }
Compute the MCE entropy value .