Markov chain algorithms on a Python networkx tree graph