Created
February 12, 2016 19:59
-
-
Save lagondo/5d89e290bdc12348e0fd to your computer and use it in GitHub Desktop.
Random walk gaussian
This file contains hidden or 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
| const R = require('ramda') | |
| const plot = require('plotter').plot | |
| const randomBoolean = () => Math.random() > 0.5 | |
| const randomOneOrMinusOne = () => randomBoolean() ? 1 : -1 | |
| const randomWalk = (length) => R.times(randomOneOrMinusOne, 100) | |
| const randomWalkEnd = (length) => R.sum(randomWalk(length)) | |
| const manyRandomWalks = R.times(() => randomWalkEnd(100), 1000000) | |
| const distribution = R.countBy(R.identity, manyRandomWalks) | |
| const values = R.map((x) => distribution[x], R.range(-100, 100)) | |
| plot({ | |
| data: values, | |
| filename: 'output.png' | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment