Skip to content

Comment on Show HN: Markov chains explained visually

Comments

I created a Markov chain generator: https://gist.github.com/grant/561834963dc526495c45

var numNodes=10;var roundNum=100;var a=[];for(var i=0;i<numNodes;++i){var connections=[];var sum=0;for(var j=0;j<numNodes;++j){var randNum=Math.random()/numNodes;randNum=Math.round(randNumroundNum)/roundNum;connections[j]=randNum;sum+=randNum}connections=connections.map(function(e){var t=e(1/sum);t=Math.round(troundNum)/roundNum;return t});sum=connections.reduce(function(e,t){return e+t});connections[numNodes-1]+=1-sum;connections[numNodes-1]=Math.round(connections[numNodes-1]roundNum)/roundNum;a[i]=connections}console.log(JSON.stringify(a))

Copy and paste the output into the side bar.

Please indent each line with a double space so it's properly monospace formatted.

Yeah, your comment breaks the readability of this comment thread on my mobile (as in, everything is horrible stretched horizontally).

Nice!

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.