
Markov Chains Explained Visually (2014) - sonabinu
http://setosa.io/ev/markov-chains/
======
kastnerkyle
For anyone interested in Markov chains (aimed at language) in Python, and
their relationship to the larger world of language modeling (including
"modern" RNNLMs and so on) this post by Yoav Goldberg is an excellent
introduction, with clear and simple code [1]. Extending the Markov chain even
a few steps can give really impressive generated results. Clone/download [2]
if you want to run the code yourself.

[1]
[http://nbviewer.jupyter.org/urls/gist.githubusercontent.com/...](http://nbviewer.jupyter.org/urls/gist.githubusercontent.com/yoavg/d76121dfde2618422139/raw/564dfb8ad396e987c1f1c45ce3c6b942757cdb9e/lm_example)

[2]
[https://gist.github.com/yoavg/d76121dfde2618422139](https://gist.github.com/yoavg/d76121dfde2618422139)

------
xnzakg
Woah, spent way too much time making this:
[http://setosa.io/markov/index.html#%7B%22tm%22%3A%5B%5B0%2C0...](http://setosa.io/markov/index.html#%7B%22tm%22%3A%5B%5B0%2C0.9%2C0%2C0%2C0%2C0%2C0%2C0.1%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0.9%2C0%2C0%2C0%2C0.1%2C0%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0.9%2C0%2C0.1%2C0%2C0%2C0%2C0%2C0%2C0%5D%2C%5B0.9%2C0%2C0%2C0%2C0.1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0.1%2C0%2C0%2C0%2C0%2C0%2C0%2C0.9%2C0%5D%2C%5B0%2C0%2C0.1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0.9%5D%2C%5B0%2C0.1%2C0%2C0%2C0%2C0%2C0%2C0%2C0.9%2C0%2C0%2C0%5D%2C%5B0.1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0.9%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0%2C0%2C1%2C0%2C0%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0%2C0%2C0%2C1%2C0%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0%2C0%2C0%2C0%2C1%2C0%2C0%2C0%2C0%5D%2C%5B0%2C0%2C0%2C0%2C1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%5D%5D%7D)

~~~
agumonkey
Very nice lattice.

------
nmaggioni
Last year I made a pseudo-random text generator based on Markov Chains as a
summer project to learn C++:
[https://github.com/nmaggioni/MarkovText](https://github.com/nmaggioni/MarkovText)

It's in Italian since it just was an hobby project and I didn't spend too much
time adapting it for the public domain, but it may be interesting for someone.

~~~
herval
I have a Twitter bot that makes up book passages combining books from the
Gutenberg project:
[https://twitter.com/markovian_lit](https://twitter.com/markovian_lit) Code is
also on GitHub if it interests anyone - not the prettiest, but it was fun to
build :-)

------
theoh
For the case of Markov chains with memory, Dasher is a good learning tool
(even though the word Markov is never used).

[http://www.inference.phy.cam.ac.uk/dasher/](http://www.inference.phy.cam.ac.uk/dasher/)

(Actually it seems I mentioned Dasher when this same link was posted in 2014,
but it bears repeating.)

~~~
erikpukinskis
Interesting you mention Dasher. A month or so it occurred to me that some
variation on Dasher might be the text input method of choice in VR.

~~~
theoh
Along those lines, maybe also something like Fleksy or Swype, which are
reportedly usable by blind people -- fleksy in particular is very smart about
determining the size and orientation of the invisible "keyboard" the user is
typing on.

------
rhodysurf
I like this. Markov chains can be hard to explain without examples.

~~~
ams6110
It's a nice demo but when I moved one of the probability sliders from 0.5 to
0.9 my browser essentially locked up for nearly two minutes. (FF 45.0.1).

Seems we're still a ways from achieving native browser animation performance
that Flash (for all its other problems) had a decade or more ago.

~~~
abiox
i didn't have any lockups in chrome.

------
vicapow
Find the source code for this and other explanations at:
[https://github.com/vicapow/explained-
visually/tree/master/cl...](https://github.com/vicapow/explained-
visually/tree/master/client/explanations/markov-chains)

------
jokoon
I don't see how a markov chain has something to do with pagerank. I understand
that pagerank use graphs, and a markov chain is some kind of graph, but I
don't see anything else.

~~~
pedrosorio
PageRank assumes your browsing activity is a Markov chain in the graph defined
by hyperlinks in the web (assuming 1/n probability for each outgoing link in a
page). The rank of a page is the limit #visits to the page/#total visits
(which is the eigenvector of the transition matrix for eigenvalue 1)

------
max_
This site is excellent for maths!!!! I recommend it to everyone!!!

Thanx sonabinu!!!

~~~
sonabinu
Thanks Max! I think it's a great resource too !!!

------
Link-djst
Nice way to learn new things!

------
wodenokoto
I think it would be much more interesting with a guide to hidden markov
models.

I'm surprised how much focus there is on regular markov chains without any
hidden units on places like hacker news.

------
escobar
This has previously appeared on HN in July 2014 :)

[https://news.ycombinator.com/item?id=8103240](https://news.ycombinator.com/item?id=8103240)

~~~
xchaotic
But there wasn't enough hype around ML back then. A few Go wins later and it's
getting a top spot.

~~~
dang
Cheap shots like this degrade the community, so please don't post them here.

The story spent hours at #1 back then, and had three times as many votes as
this resubmission (so far).

------
creed0r
Am I right in taking from this that markov chains don't necessarily adjust to
history?

So in the example, if a "sunny day" state has a chance of 0.9 to stay in that
state and a 0.1 chance of transitioning to rainy day and I already had 5 sunny
days, the 6th day would still have a 0.1 chance to be a rainy day?

~~~
detaro
Yes, the classical Markov chain has no memory. A Markov chain with memory for
the last m steps is sometimes called a "Markov chain of order m"

------
justifier
when this first hit hn it had an enormous rank of 1070, and the comments are
all about the breakthrough importance of markov chains

for those who follow.. is this still the case?

i feel like i hear less and less about markov chains

are they still in research and use?

is page rank still the most prominent search algo? does page rank still use
markov models?

i always felt these probabilistic models were a conflation of correlation and
causation

~~~
jamessb
_the breakthrough importance of markov chains_

 _i feel like i hear less and less about markov chains are they still in
research and use?_

Markov chains will always be important, because they are a fairly fundamental
concept (going back to the early 20th century).

They idea is certainly still widely used: two major classes of applications
are Hidden Markov Models (where you attempt to infer the hidden state of a
system from observations that depend on the state) [1], and Markov-Chain Monte
Carlo (MCMC) [2] (where you sample from a probability distribution function by
constructing a markov chain whose equilibrium distibution is that
distribution).

 _is page rank still the most prominent search algo?_

PageRank is really a ranking algorithm, rather than a search algorithm. It's
been applied to many things other than web searching, and has many variants
(e.g. see the review article "PageRank Beyond the Web" [3). That said, Google
rankings depend on many things other than PageRank.

 _i always felt these probabilistic models were a conflation of correlation
and causation_

What do you mean?

[1]:
[https://en.wikipedia.org/wiki/Hidden_Markov_model#Applicatio...](https://en.wikipedia.org/wiki/Hidden_Markov_model#Applications)

[2]:
[https://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo](https://en.wikipedia.org/wiki/Markov_chain_Monte_Carlo)

[3]:
[http://epubs.siam.org/doi/10.1137/140976649](http://epubs.siam.org/doi/10.1137/140976649)

~~~
justifier
> _i always felt these probabilistic models were a conflation of correlation
> and causation_

> What do you mean?

the example from the post of weather events is a simplified version of what i
mean

the collected data expresses that there is a probability of 50/50 rain versus
shine

the first string of possible outputs is scattered and more random than the
real data, so weights are introduced to nuance to the output and the second
string is more closely representative of the data

but this introduces a relative psuedo causation, what the author refers to as
stickyness

it's reminiscent of the monty hall problem(o)

altering the state of the model causes its probability to change relative to a
specific potential, but only within the limited scope of the probable space

choosing one door causes the probabilities associated with the state to change
but the system itself is unchanged by the choice

and what you see with the weather is a simulation of the collected data stead
the underlying system, which i feel conflates correlation with causation

(o)
[https://en.wikipedia.org/wiki/Monty_Hall_problem](https://en.wikipedia.org/wiki/Monty_Hall_problem)

------
vc98mvco
Sorry to be off-topic, but the site partially disables my input, i.e. causes
high lag. It makes it unusable. I'm using Firefox on a modern PC.

Opera seems to run fine, but it maxes out two cores. Uhhh...?

------
redsummer
I think I understand the concept. Extrapolating the example of Rainy and Sunny
days, how would you model this over a year, where there is seasonal variation?
In winter for instance, the rainy days would more likely to continue than
sunny days. And what are the recommended methods for creating models from
existing data?

------
Mauricio_
Those animations are seriously burning my CPU on chrome.

~~~
kamiheku
Yup, got my processor up to a toasty 94 degrees celcius/200 degrees
fahrenheit.

~~~
qsysmine
My computer has actually turned into a toaster.

