pyodide/benchmark/benchmarks/log_likelihood.py

14 lines
461 B
Python
Raw Normal View History

2018-10-03 18:59:01 +00:00
# setup: import numpy as np ; N = 100000 ; a = np.random.random(N); b = 0.1; c =1.1 # noqa
# run: log_likelihood(a, b, c)
# from: http://arogozhnikov.github.io/2015/09/08/SpeedBenchmarks.html
2018-04-05 22:07:33 +00:00
import numpy
2018-10-03 18:59:01 +00:00
# pythran export log_likelihood(float64[], float64, float64)
2018-10-03 12:38:48 +00:00
2018-04-05 22:07:33 +00:00
def log_likelihood(data, mean, sigma):
s = (data - mean) ** 2 / (2 * (sigma ** 2))
pdfs = numpy.exp(- s)
pdfs /= numpy.sqrt(2 * numpy.pi) * sigma
return numpy.log(pdfs).sum()