List of usage examples for org.apache.commons.math.special Gamma digamma
public static double digamma(double x)
Computes the digamma function of x.
This is an independently written implementation of the algorithm described in Jose Bernardo, Algorithm AS 103: Psi (Digamma) Function, Applied Statistics, 1976.
Some of the constants have been changed to increase accuracy at the moderate expense of run-time.
From source file:org.broadinstitute.gatk.tools.walkers.variantrecalibration.MultivariateGaussian.java
public void precomputeDenominatorForVariationalBayes(final double sumHyperParameterLambda) { // Variational Bayes calculations from Bishop precomputeInverse();/* ww w . j av a2 s . c o m*/ cachedSigmaInverse.timesEquals(hyperParameter_a); double sum = 0.0; for (int jjj = 1; jjj <= mu.length; jjj++) { sum += Gamma.digamma((hyperParameter_a + 1.0 - jjj) / 2.0); } sum -= Math.log(sigma.det()); sum += Math.log(2.0) * mu.length; final double lambda = 0.5 * sum; final double pi = Gamma.digamma(hyperParameter_lambda) - Gamma.digamma(sumHyperParameterLambda); final double beta = (-1.0 * mu.length) / (2.0 * hyperParameter_b); cachedDenomLog10 = (pi / Math.log(10.0)) + (lambda / Math.log(10.0)) + (beta / Math.log(10.0)); }
From source file:vagueobjects.ir.lda.online.matrix.MatrixUtil.java
static double[] dirichletExpectation(double[] array) { double sum = 0; for (double d : array) { sum += d;//from w w w . j a v a 2 s . com } double d = Gamma.digamma(sum); double[] result = new double[array.length]; for (int i = 0; i < array.length; ++i) { result[i] = Gamma.digamma(array[i]) - d; } return result; }
From source file:vagueobjects.ir.lda.online.matrix.MatrixUtil.java
/** * Digamma function (the first derivative of the logarithm of the gamma function). * @param array - variational parameter * @return//from w w w. j a v a 2s.c o m */ static double[][] dirichletExpectation(double[][] array) { int numRows = array.length; int numCols = array[0].length; double[] vector = new double[numRows]; Arrays.fill(vector, 0.0); for (int k = 0; k < numRows; ++k) { for (int w = 0; w < numCols; ++w) { try { vector[k] += array[k][w]; } catch (Exception e) { throw new RuntimeException(e); } } } for (int k = 0; k < numRows; ++k) { vector[k] = Gamma.digamma(vector[k]); } double[][] approx = new double[numRows][]; for (int k = 0; k < numRows; ++k) { approx[k] = new double[numCols]; for (int w = 0; w < numCols; ++w) { double z = Gamma.digamma(array[k][w]); approx[k][w] = z - vector[k]; } } return approx; }