Markov chain algorithms on a Python NetworkX tree graph