Skip to content

Instantly share code, notes, and snippets.

View harrymvr's full-sized avatar

Harry Mavroforakis harrymvr

View GitHub Profile
@harrymvr
harrymvr / log_add.py
Created November 1, 2012 05:08
Python code to sample from a probability distribution described by the logarithms of the probabilities (log probabilities). Includes code for log sum (log_add)
def log_add(x, y):
maximum = max(x,y)
minimum = min(x,y)
if(abs(maximum - minimum) > 30):
# the difference is too small, return the just the maximum
return maximum
return maximum + log(1 + pow(2, minimum - maximum) ,2)