3 ms·
Hi HN! This is a small hack that I created over the weekend. I learnt about the Monte Carlo method while doing Princeton's Functional Programming course[0] in
by krat0sprakhar 12y ago
Hi HN!
This is a small hack that I created over the weekend. I learnt about the Monte Carlo method while doing Princeton's Functional Programming course[0] in OCaml[1] as one of the assignment problems. To get the first four digits consistently, I ran around 200,000 - 400,000 simulations - not quite possible in the browser!
[0] - http://www.cs.princeton.edu/~dpw/courses/cos326-12/ http://www.cs.princeton.edu/~dpw/courses/cos326-12/
[1] - https://github.com/prakhar1989/ocaml-experiments/blob/master/cos326/a1/a1.ml#L204-L216 https://github.com/prakhar1989/ocaml-experiments/blob/master...
- Goopplesoft 12y agoThanks for the share. Tried this in python using some higher iterations and started getting good numbers around 1E6 Link: http://nbviewer.ipython.org/gist/pnegahdar/eb62475b28d5b394d824 http://nbviewer.ipython.org/gist/pnegahdar/eb62475b28d5b394d...
- fphilipe 12y agoNice work. I did a very similar simulation a year ago when I learned about MC in the context of particle filtering in a course about recursive estimation at ETH. http://bl.ocks.org/fphilipe/6094255 http://bl.ocks.org/fphilipe/6094255
- krat0sprakhar 12y agoWow! Nicely done. The idea of showing relative error is pretty cool :D
- nemetroid 12y ago> not quite possible in the browser! It's not the browser (or JS) that's slow, it's all the animations and stuff. If you write Javascript to do only what the OCaml code does, it runs fast enough: http://jsfiddle.net/qmw4d9p9/1/ http://jsfiddle.net/qmw4d9p9/1/