Skip to content

Commit

Permalink
New benchmark: Galton Bean Machine
Browse files Browse the repository at this point in the history
  • Loading branch information
madsbk committed Dec 14, 2016
1 parent 011e4ba commit b316187
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
Empty file.
31 changes: 31 additions & 0 deletions benchmarks/galton_bean_machine/python_numpy/galton_bean_machine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from __future__ import print_function
from benchpress import util
import numpy as np

def bean(num_beans, height):
return np.sum(np.sign(np.random.random((num_beans,height))-0.5), axis=1)

def main():
B = util.Benchmark()
num_beans, height = B.size

B.start()
R = bean(num_beans, height)
B.stop()

B.pprint()
if B.verbose:
print(R)
if B.visualize:
from matplotlib import pyplot
bins = 100
pyplot.hist(R, bins)
pyplot.title("Galton Normal distribution")
pyplot.xlabel("Value")
pyplot.ylabel("Frequency")
pyplot.show()
if B.outputfn:
B.tofile(B.outputfn, {'res': R})

if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions benchmarks/galton_bean_machine/readme.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Simulation of the Galton Bean Machine, which was an old physical machine that demonstrated the normal distribution. https://en.wikipedia.org/wiki/Bean_machine

It takes two arguments, the number of beans and the height of the machine::

--size=10000*100

0 comments on commit b316187

Please sign in to comment.