public static double entropyConditionedOnRows(double[][] train,double[][] test,double numClasses){
  double returnValue=0, trainSumForRow, testSumForRow, testSum=0;
  for (int i=0; i < test.length; i++) {
    trainSumForRow=0;
    testSumForRow=0;
    for (int j=0; j < test[0].length; j++) {
      returnValue-=test[i][j] * Math.log(train[i][j] + 1);
      trainSumForRow+=train[i][j];
      testSumForRow+=test[i][j];
    }
    testSum=testSumForRow;
    returnValue+=testSumForRow * Math.log(trainSumForRow + numClasses);
  }
  return returnValue / (testSum * log2);
}

public static double entropyConditionedOnRows ( double [ ] [ ] train , double [ ] [ ] test , double numClasses ) { double returnValue = 0 , trainSumForRow , testSumForRow , testSum = 0 ; for ( int i = 0 ; i < test . length ; i ++ ) { trainSumForRow = 0 ; testSumForRow = 0 ; for ( int j = 0 ; j < test [ 0 ] . length ; j ++ ) { returnValue -= test [ i ] [ j ] * Math . log ( train [ i ] [ j ] + 1 ) ; trainSumForRow += train [ i ] [ j ] ; testSumForRow += test [ i ] [ j ] ; } testSum = testSumForRow ; returnValue += testSumForRow * Math . log ( trainSumForRow + numClasses ) ; } return returnValue / ( testSum * log2 ) ; }
computes conditional entropy of the columns given the rows of the test matrix with respect to the train matrix . uses a laplace prior . does not normalize the entropy .
