8 ms·
markov chains are very simple at their core (e.g. simple version could be: take the probability of the next word given the known probabilities of words that fol
by localhostdotdev 7y ago
markov chains are very simple at their core (e.g. simple version could be: take the probability of the next word given the known probabilities of words that follow the previous word)
it can be implemented in a few lines of code, that's the beauty of it: https://github.com/justindomingue/markov_chains/blob/master/lib/markov_chains/dictionary.rb https://github.com/justindomingue/markov_chains/blob/master/...
obviously then you could take the previous n words into account, tweak the starting word, add randomness, etc.
now replace "word" with "state" and "probability(next state | previous state)" to edges of a graph: https://static1.squarespace.com/static/54e50c15e4b058fc6806d068/t/5650d16ee4b033f56d20ae6b/1459882428797/markov+chain+graph+all.png?format=1500w https://static1.squarespace.com/static/54e50c15e4b058fc6806d...
and you got a generic markov chain :)
footnotes: p(A | B) is probability of A given B, e.g. p(rain | clouds) > p(rain | sun) :)