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 ; }
Calculates probability pi ai under dirichlet distribution