-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
37 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
31 changes: 31 additions & 0 deletions
31
benchmarks/galton_bean_machine/python_numpy/galton_bean_machine.py
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
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() |
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
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 | ||
|