code: public static double dirichletPdf(double[] pi, double[] ai) {
          double probability=1.0;
          double sumAi=0.0;
          double productGammaAi=1.0;
          
          double tmp;
          int piLength=pi.length;
          for(int i=0;i<piLength;++i) {
              tmp=ai[i];
              sumAi+= tmp;
              productGammaAi*=gamma(tmp);
              probability*=Math.pow(pi[i], tmp-1);
          }
          
          probability*=gamma(sumAi)/productGammaAi;
          
          return probability;
      }
docs: Calculates probability pi, ai under dirichlet distribution
  
  @param pi    The vector with probabilities.
  @param ai    The vector with pseudocounts.
  @return      The probability