public static double entropy(int p, int n) {
    if ((p == 0) &&
        (n == 0)) {
      return (0.0);
    }
    { int sum = p + n;
      double posImpurity = 0.0;
      double posPerc = ((double)(p)) / sum;
      double negImpurity = 0.0;
      double negPerc = ((double)(n)) / sum;

      if (p == 0) {
        posImpurity = 0.0;
      }
      else {
        posImpurity = 0 - (posPerc * (Math.log(posPerc) / Math.log((2.0))));
      }
      if (n == 0) {
        negImpurity = 0.0;
      }
      else {
        negImpurity = 0 - (negPerc * (Math.log(negPerc) / Math.log((2.0))));
      }
      return (posImpurity + negImpurity);
    }
  }