OnlineLogLikelihood extends ComputeFunction { public static double logSumExp(DenseMatrix dm) { double max = dm.get(0, 0); for (int i = 0; i < dm.numRows(); i++) { for (int j = 0; j < dm.numCols(); j++) { if (dm.get(i, j) > max) { max = dm.get(i, j); } } } double sum = 0; for (int i = 0; i < dm.numRows(); i++) { for (int j = 0; j < dm.numCols(); j++) { sum += Math.exp(dm.get(i, j) - max); } } return max + Math.log(sum); } OnlineLogLikelihood(double beta, int numTopic, int numIter); static double logLikelihood(List <Vector> data, DenseMatrix lambda, DenseMatrix alpha, DenseMatrix gammad,
									   int numTopic, int vocabularySize, double beta, int taskNum); static double logSumExp(DenseMatrix dm); @Override void calc(ComContext context);  }
@Test public void testSum() { DenseMatrix gammad = new DenseMatrix(5, 1, new double[] {-0.7, 0.8, 0.9, 1.0, 1.1}); double sum = OnlineLogLikelihood.logSumExp(gammad); System.out.println(sum); }