Created
September 2, 2009 10:55
-
-
Save apatil/179657 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Illustrates why log-sums are better than direct sums for probability integrals | |
# when probabilities are initially computed on the log scale | |
import pymc | |
import numpy | |
lp_big = numpy.random.normal(loc=0,scale=2,size=1000) | |
print numpy.log(numpy.mean(numpy.exp(lp_big))) | |
print pymc.flib.logsum(lp_big)-numpy.log(len(lp_big)) | |
lp_small = numpy.random.normal(loc=-3000,scale=2,size=1000) | |
print numpy.log(numpy.mean(numpy.exp(lp_small))) | |
print pymc.flib.logsum(lp_small)-numpy.log(len(lp_small)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment