public double jointEntropy(int[] x,int[] y){
  double h=0.0;
  int[][] ns=new int[2][2];
  int n=x.length;
  double ln2=Math.log(2.0);
  ns[0][0]=0;
  ns[0][1]=0;
  ns[1][0]=0;
  ns[1][1]=0;
  for (int i=0; i < n; i++) {
    ns[x[i]][y[i]]++;
  }
  int ntot=n;
  double[][] p=new double[2][2];
  double lp00, lp01, lp10, lp11;
  p[0][0]=(double)ns[0][0] / (double)ntot;
  p[0][1]=(double)ns[0][1] / (double)ntot;
  p[1][0]=(double)ns[1][0] / (double)ntot;
  p[1][1]=(double)ns[1][1] / (double)ntot;
  if (p[0][0] == 0.0) {
    lp00=0.0;
  }
 else {
    lp00=-p[0][0] * Math.log(p[0][0]);
  }
  if (p[0][1] == 0.0) {
    lp01=0.0;
  }
 else {
    lp01=-p[0][1] * Math.log(p[0][1]);
  }
  if (p[1][0] == 0.0) {
    lp10=0.0;
  }
 else {
    lp10=-p[1][0] * Math.log(p[1][0]);
  }
  if (p[1][1] == 0.0) {
    lp11=0.0;
  }
 else {
    lp11=-p[1][1] * Math.log(p[1][1]);
  }
  h=lp00 + lp01 + lp10+ lp11;
  h/=ln2;
  return h;
}

public double jointEntropy ( int [ ] x , int [ ] y ) { double h = 0.0 ; int [ ] [ ] ns = new int [ 2 ] [ 2 ] ; int n = x . length ; double ln2 = Math . log ( 2.0 ) ; ns [ 0 ] [ 0 ] = 0 ; ns [ 0 ] [ 1 ] = 0 ; ns [ 1 ] [ 0 ] = 0 ; ns [ 1 ] [ 1 ] = 0 ; for ( int i = 0 ; i < n ; i ++ ) { ns [ x [ i ] ] [ y [ i ] ] ++ ; } int ntot = n ; double [ ] [ ] p = new double [ 2 ] [ 2 ] ; double lp00 , lp01 , lp10 , lp11 ; p [ 0 ] [ 0 ] = ( double ) ns [ 0 ] [ 0 ] / ( double ) ntot ; p [ 0 ] [ 1 ] = ( double ) ns [ 0 ] [ 1 ] / ( double ) ntot ; p [ 1 ] [ 0 ] = ( double ) ns [ 1 ] [ 0 ] / ( double ) ntot ; p [ 1 ] [ 1 ] = ( double ) ns [ 1 ] [ 1 ] / ( double ) ntot ; if ( p [ 0 ] [ 0 ] == 0.0 ) { lp00 = 0.0 ; } else { lp00 = - p [ 0 ] [ 0 ] * Math . log ( p [ 0 ] [ 0 ] ) ; } if ( p [ 0 ] [ 1 ] == 0.0 ) { lp01 = 0.0 ; } else { lp01 = - p [ 0 ] [ 1 ] * Math . log ( p [ 0 ] [ 1 ] ) ; } if ( p [ 1 ] [ 0 ] == 0.0 ) { lp10 = 0.0 ; } else { lp10 = - p [ 1 ] [ 0 ] * Math . log ( p [ 1 ] [ 0 ] ) ; } if ( p [ 1 ] [ 1 ] == 0.0 ) { lp11 = 0.0 ; } else { lp11 = - p [ 1 ] [ 1 ] * Math . log ( p [ 1 ] [ 1 ] ) ; } h = lp00 + lp01 + lp10 + lp11 ; h /= ln2 ; return h ; }
this method computes the joint entropy of two arrays . the values stored in those arrays are assumed to be restricted to { 0 , 1 } .
