I remember a Mythbusters episode where they were building a buttered-toast-dropper. To test the null hypothesis, they first did 10 runs without buttered toast, just marking one side with an X. They got 7/10 landing the same way up... and declared "It should be 5/10! This is not random enough!"...
It's something I'd expected someone to know in anything related to data science / machine learning / big data. But if it wasn't a position specific to those fields, then yeah that's that a pretty silly riddle of a question.
edit: even within those fields, it's definitely more of a very-specific-domain-knowledge type of question and not something that I think is worth the time to ask it in a job interview.
This is a common thing to learn during your first week or so in an introductory computer science course. They were probably picking something that a second-year student could use to easily demonstrate basic coding ability. Unfortunately, this didn't happen to be part of your intro course.
BTW there is a nice related course on coursera: "Statistical Mechanics: Algorithms and Computations"[1]. Also notice there is a rosettacode entry for this[2].
LOL we all have those moments, I thought I was a genius for thinking I could calculate PI by doing a double integral over x,y from 0 to 1 using the Heaviside step function with (x^2+y^2) or something I can't remember... Basically it was that in the integral the step function is on if x^2+y^2 is less than 1 and off if >1, so you would end up with PI/4. Anyways it didn't work out :)
Today I tried to write this on shell, I couldn't do it in a compact way. Are there some nice PLs for these kind of plays? Cleanest I could do was doing below in a single line via "python -c". I couldn't get it done via bc or awk.
from random import random
l = lambda (a, b), c: (a + c, b + 1)
g = (1 if random()**2 + random()**2 <= 1 else 0 for i in range(10**6))
r, t = reduce(l, g, (0.0, 0))
print r / t * 4
BTW, your scatter plots aren't colourblind-friendly - they just look like boxes of indistinguishable dots to me, I had to ask a friend if I was missing something. You seem to have accidentally made an Ishihara test[0], thanks to the particular shades of red and green you've used - red & blue would be better for accessibility.
Is there a service that makes it trivially easy to simulate colour blindness on an image or document? Heck, why's it not built into data publishing applications?
It is also the example I give on a (true) parallel library for front-end javascript with math-intensive code such as calculating PI with Monte Carlo: https://github.com/franciscop/uwork
1. You can do one quadrant rather than four, then multiply that approximation by 4.
2. Montecarlo is good to develop an intuition about Monte carlo approximations but converges really slowly.
Ramanujan-Sato series for pi or Chudnovsky algorithm can be a scalable alternative, gives you a lot of digits.
Now... how many digits you usually need? Very few. Practical applications requiring more than 15 digits are hard to find. e.g: NASA uses 15 digits for interplanetary navigation, even for the most distant spacecraft such as the Voyager 1 which is now 20 billion kilometers from Earth.
Can just use a constant, or in the worst case, if missing, define it as:
Accuracy from one quadrant and four quadrants would be the same, though, and full circle is easier to code (no extra conditions).
To get better accuracy you would need to cut out some parts that are clearly inside or outside the circle, and only throw the points in the areas where the circle can actually be.
You can try the same with quasi-random rather than pseudo-random numbers (Sobol, Halton, or even just additive). Should probably get better accuracy with the same number of iterations.
42 comments
[ 3.2 ms ] story [ 99.5 ms ] threadhttp://sohcahtoa.org.uk/pages/maths_montecarlo.html
Someone here suggested the Steinmetz solid as a follow up which I will try next time I teach that group.
That project led directly to the 'rand' call in this function [1] 13 years later and fundamentally altered the way I think about data analysis.
[1] https://github.com/4kbt/PlateWash/blob/master/mlib/bootstrap...
Golden!
http://www.radiolab.org/story/91684-stochasticity/
I didn't get it at the time and I deeply resented the problem. What does this have to do with being a software engineer?
But interesting to see how it's actually done.
edit: even within those fields, it's definitely more of a very-specific-domain-knowledge type of question and not something that I think is worth the time to ask it in a job interview.
1. https://www.coursera.org/learn/statistical-mechanics
2. http://rosettacode.org/wiki/Monte_Carlo_methods
[0] https://en.m.wikipedia.org/wiki/Ishihara_test
There's a Python library that's usable at the command line, too: https://github.com/joergdietrich/daltonize.
It is also the example I give on a (true) parallel library for front-end javascript with math-intensive code such as calculating PI with Monte Carlo: https://github.com/franciscop/uwork
1. You can do one quadrant rather than four, then multiply that approximation by 4.
2. Montecarlo is good to develop an intuition about Monte carlo approximations but converges really slowly.
Ramanujan-Sato series for pi or Chudnovsky algorithm can be a scalable alternative, gives you a lot of digits.
Now... how many digits you usually need? Very few. Practical applications requiring more than 15 digits are hard to find. e.g: NASA uses 15 digits for interplanetary navigation, even for the most distant spacecraft such as the Voyager 1 which is now 20 billion kilometers from Earth.
Can just use a constant, or in the worst case, if missing, define it as:
To get better accuracy you would need to cut out some parts that are clearly inside or outside the circle, and only throw the points in the areas where the circle can actually be.
https://notebooks.azure.com/smortaz/libraries/MonteCarloPi
You can click on it, sign in to run, edit, etc.
Sign in: any outlook, xbox, hotmail, or msft ID.