code: protected static double computePi(int i, double[] dist_i, double[] pij_i, double perplexity, double logPerp) {
      // Relation to paper: beta == 1. / (2*sigma*sigma)
      double beta = estimateInitialBeta(dist_i, perplexity);
      double diff = computeH(i, dist_i, pij_i, -beta) - logPerp;
      double betaMin = 0.;
      double betaMax = Double.POSITIVE_INFINITY;
      for(int tries = 0; tries < PERPLEXITY_MAXITER && Math.abs(diff) > PERPLEXITY_ERROR; ++tries) {
        if(diff > 0) {
          betaMin = beta;
          beta += (betaMax == Double.POSITIVE_INFINITY) ? beta : ((betaMax - beta) * .5);
        }
        else {
          betaMax = beta;
          beta -= (beta - betaMin) * .5;
        }
        diff = computeH(i, dist_i, pij_i, -beta) - logPerp;
      }
      return beta;
    }
docs: Compute row pij[i], using binary search on the kernel bandwidth sigma to
  obtain the desired perplexity.
  
  @param i Current point
  @param dist_i Distance matrix row pij[i]
  @param pij_i Output row
  @param perplexity Desired perplexity
  @param logPerp Log of desired perplexity
  @return Beta