protected static void computePi(int i,double[] dist_i,double[] pij_i,double perplexity,double logPerp){
  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;
  }
}

protected static void computePi ( int i , double [ ] dist_i , double [ ] pij_i , double perplexity , double logPerp ) { 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 ; } }
compute row pij [ i ] , using binary search on the kernel bandwidth sigma to obtain the desired perplexity .
