

Random walk illustrated with D3 - mixedbit
http://mixedbit.org/blog/2013/02/10/random_walk_illustrated_with_d3.html

======
paulgb
The code for this is neat and impressively short, anyone looking to see the
power of D3 should check it out: <https://gist.github.com/wrr/4750218>

My only suggestion is that .data([color_idx]) would be more idiomatic (I
think) if it were .datum(color_idx)

~~~
mixedbit
Thanks! It is now changed to datum().

------
nevinera
"A moral of this is that any lucky series will always eventually be reversed
and an expected outcome of a random walk is always 0. Or in other words -
don’t play roulette ;)"

The _apriori_ expected outcome of a random walk is zero. The expected outcome
of a random walk from a given position is the position itself. So no, 'any
lucky series' will not 'always eventually be reversed'. I'm afraid that's not
how probability works.

But you still shouldn't play roulette.

~~~
mixedbit
The way I understand this, is that for a random walk of infinite length, your
expected outcome is always 0. It doesn't matter that you started very lucky by
winning 10 games in a row, because if you play an infinite number of times,
you will balance this by loosing 10 games in a row (you'll do it an infinite
number of times).

In real life people usually don't play an infinite number of times, but the
more you play, the better the theory approximates your final outcome. After
very large number of games, you will very likely encounter a bad luck series.

This is a bit counter intuitive, because according to the theory, there is a
difference between a person that enters a fair game with 10$ and a person that
enters with 1$ and wins 9$ in the first 9 games. The first person is expected
to finish with 10$, the second with 1$, even though both have the same amount
of money at some point. But laws that involve infinity are often counter
intuitive.

~~~
nevinera
>The way I understand this, is that for a random walk of infinite length, your
expected outcome is always 0. It doesn't matter that you started very lucky by
winning 10 games in a row, because if you play an infinite number of times,
you will balance this by loosing 10 games in a row (you'll do it an infinite
number of times).

You understand it incorrectly.

>This is a bit counter intuitive, because according to the theory, there is a
difference between a person that enters a fair game with 10$ and a person that
enters with 1$ and wins 9$ in the first 9 games. The first person is expected
to finish with 10$, the second with 1$, even though both have the same amount
of money at some point. But laws that involve infinity are often counter
intuitive.

That is exactly the example I would give of why your understanding is flawed.
This is not 'counter-intuitive', it is a clear contradiction of basic logic.
You are making a fairly common error in confusing a priori probability with
conditional probability: <http://en.wikipedia.org/wiki/Gamblers_fallacy>. A
standard phrase used by gamblers to refer to this truth is that "the dice have
no memory."

If you start a random walk from Chicago, you are expected to end up in
Chicago. If you start a random walk from New York, you are expected _then_ to
end up in New York. If you, later on that same walk, notice that you are
currently in Chicago, you can start expecting yourself to end up in Chicago,
despite that your random walk started in New York: you have observed the
actual events (collapsed the waveform), and now you have just taken _a walk_.

This is the core of the misconception: "The first person is expected to finish
with 10$, the second with 1$, even though both have the same amount of money
at some point." The first person _was_ expected to finish with 10$, and the
second _was_ expected to finish with 1$, but after the second player has won 9
games, he is _then_ expected to finish with 10$, and anyone standing around
watching who still has faith in their earlier expectation is uninformed.

~~~
mixedbit
Thanks for this explanation, my understanding was indeed flawed.

------
halter73
Too bad this doesn't work in IE since it loads JS from github:

[http://stackoverflow.com/questions/7180099/including-js-
from...](http://stackoverflow.com/questions/7180099/including-js-from-raw-
github-com)

At least in IE 10, it would work if it wasn't for this.

~~~
mixedbit
Thanks for pointing this out, it is now fixed.

------
mikeash
Interesting fact about the interesting facts at the bottom: each point is
reached an infinite number of times only when a random walk is performed in
one or two-dimensional space. For dimensions >=3, an infinite walk visits each
point a finite number of times, which means that, while the random walker may
return to the starting point one or more times after starting, it will
eventually wander off forever. This has been described as, "A drunk man will
find his way home, but a drunk bird may get lost forever."

~~~
jeffwass
Or, in human terms, you can eventually find your car in a 2D parking lot, but
not a 3D parking garage (as per Seinfeld
<http://en.wikipedia.org/wiki/The_Parking_Garage>)

------
taliesinb
and with Mathematica: ... <http://taliesinb.net/visualizing-random-walks>

------
misleading_name
Doesn't work on my Windows Firefox... got it working on Chrome though.

