/** * Transform log space values into a probability distribution in place. On the * assumption that the values in the Counter are in log space, this method * calculates their sum, and then subtracts the log of their sum from each * element. That is, if a counter has keys c1, c2, c3 with values v1, v2, v3, * the value of c1 becomes v1 - log(e^v1 + e^v2 + e^v3). After this, e^v1 + * e^v2 + e^v3 = 1.0, so Counters.logSum(c) = 0.0 (approximately). * * @param c The Counter to log normalize in place */ @SuppressWarnings( { "UnnecessaryUnboxing" }) public static <E> void logNormalizeInPlace(Counter<E> c) { double logsum = logSum(c); // for (E key : c.keySet()) { // c.incrementCount(key, -logsum); // } // This should be faster for (Map.Entry<E, Double> e : c.entrySet()) { e.setValue(e.getValue().doubleValue() - logsum); } }
/** * Transform log space values into a probability distribution in place. On the * assumption that the values in the Counter are in log space, this method * calculates their sum, and then subtracts the log of their sum from each * element. That is, if a counter has keys c1, c2, c3 with values v1, v2, v3, * the value of c1 becomes v1 - log(e^v1 + e^v2 + e^v3). After this, e^v1 + * e^v2 + e^v3 = 1.0, so Counters.logSum(c) = 0.0 (approximately). * * @param c The Counter to log normalize in place */ @SuppressWarnings( { "UnnecessaryUnboxing" }) public static <E> void logNormalizeInPlace(Counter<E> c) { double logsum = logSum(c); // for (E key : c.keySet()) { // c.incrementCount(key, -logsum); // } // This should be faster for (Map.Entry<E, Double> e : c.entrySet()) { e.setValue(e.getValue().doubleValue() - logsum); } }
/** * Transform log space values into a probability distribution in place. On the * assumption that the values in the Counter are in log space, this method * calculates their sum, and then subtracts the log of their sum from each * element. That is, if a counter has keys c1, c2, c3 with values v1, v2, v3, * the value of c1 becomes v1 - log(e^v1 + e^v2 + e^v3). After this, e^v1 + * e^v2 + e^v3 = 1.0, so Counters.logSum(c) = 0.0 (approximately). * * @param c * The Counter to log normalize in place */ @SuppressWarnings( { "UnnecessaryUnboxing" }) public static <E> void logNormalizeInPlace(Counter<E> c) { double logsum = logSum(c); // for (E key : c.keySet()) { // c.incrementCount(key, -logsum); // } // This should be faster for (Map.Entry<E, Double> e : c.entrySet()) { e.setValue(e.getValue().doubleValue() - logsum); } }
/** * Transform log space values into a probability distribution in place. On the * assumption that the values in the Counter are in log space, this method * calculates their sum, and then subtracts the log of their sum from each * element. That is, if a counter has keys c1, c2, c3 with values v1, v2, v3, * the value of c1 becomes v1 - log(e^v1 + e^v2 + e^v3). After this, e^v1 + * e^v2 + e^v3 = 1.0, so Counters.logSum(c) = 0.0 (approximately). * * @param c The Counter to log normalize in place */ @SuppressWarnings( { "UnnecessaryUnboxing" }) public static <E> void logNormalizeInPlace(Counter<E> c) { double logsum = logSum(c); // for (E key : c.keySet()) { // c.incrementCount(key, -logsum); // } // This should be faster for (Map.Entry<E, Double> e : c.entrySet()) { e.setValue(e.getValue().doubleValue() - logsum); } }
/** Transform log space values into a probability distribution in place. * On the assumption that the values in the Counter are in log space, * this method calculates their sum, and then subtracts the log of * their sum from each element. That is, if a counter has keys * c1, c2, c3 with values v1, v2, v3, the value of c1 becomes * v1 - log(e^v1 + e^v2 + e^v3). After this, e^v1 + e^v2 + e^v3 = 1.0, * so Counters.logSum(c) = 0.0 (approximately). * * @param c The Counter to log normalize in place */ @SuppressWarnings({"UnnecessaryUnboxing"}) public static <E> void logNormalizeInPlace(Counter<E> c) { double logsum = logSum(c); // for (E key : c.keySet()) { // c.incrementCount(key, -logsum); // } // This should be faster for (Map.Entry<E,Double> e : c.entrySet()) { e.setValue(e.getValue().doubleValue() - logsum); } }