Here you can find the source of normalizeToLogProbs(double[] x)
public static void normalizeToLogProbs(double[] x)
//package com.java2s; //License from project: BSD License public class Main { public static void normalizeToLogProbs(double[] x) { double max = max(x, x.length); double sumExp = 0; for (int i = 0; i < x.length; i++) { if (!Double.isNaN(x[i])) sumExp += Math.exp(x[i] - max); }/*from w ww . j ava 2 s . c om*/ double logSumExp = max + Math.log(sumExp); for (int i = 0; i < x.length; i++) if (!Double.isNaN(x[i])) x[i] -= logSumExp; } public static int max(int[] x, int length) { int m = Integer.MIN_VALUE; for (int i = 0; i < length; i++) if (x[i] > m) m = x[i]; return m; } public static int max(int[] x) { return max(x, x.length); } public static double max(double[] x, int length) { double m = Double.NEGATIVE_INFINITY; for (int i = 0; i < length; i++) if (x[i] > m) m = x[i]; return m; } }