Java Number Sum sumLogProb(double a, double b)

Here you can find the source of sumLogProb(double a, double b)

Description

Returns Math.log(Math.exp(a) + Math.exp(b)).

License

Common Public License

Declaration

public static double sumLogProb(double a, double b) 

Method Source Code

//package com.java2s;
//License from project: Common Public License 

public class Main {
    /**//from w  ww  .ja  v a2 s .  com
     * Returns <tt>Math.log(Math.exp(a) + Math.exp(b))</tt>.
     * <p>
     * <tt>a, b</tt> represent weights.
     */
    public static double sumLogProb(double a, double b) {
        if (a == Double.NEGATIVE_INFINITY) {
            if (b == Double.NEGATIVE_INFINITY)
                return Double.NEGATIVE_INFINITY;
            return b;
        } else if (b == Double.NEGATIVE_INFINITY)
            return a;
        else if (a > b)
            return a + Math.log(1 + Math.exp(b - a));
        else
            return b + Math.log(1 + Math.exp(a - b));
    }
}

Related

  1. sumHash(int hash, String element)
  2. sumHash(int leftHash, int rightHash)
  3. sumIf(final Integer number, final Integer sum, final Boolean condition)
  4. sumIsMod10(int sum)
  5. sumLange(int _a, int _b)
  6. summarize(String longString, int limit)
  7. summarizeCigarString(String cigarString)
  8. summary(String text)
  9. summatory(int value)