For my MMath dissertation I am exploring the medicinal applications of branching processes, including the Galton-Watson process, Bellman-Harris process ETC. I would like a way for these processes to be visualised and simulated via some code, preferably Python. For the most part, I have been creating arbitrary diagrams using TikZ, I will include some examples below.
Discrete Time Galton-Watson Process
Continuous Time Markov Branching Process
As mentioned, I would like a way to create these sorts of images using meaningful parameters, rather than my imagination. I have tried working with a number of options, including the treesim module from DendroPy. This has been the best option so far, but it has its limitations. Using the following code, I am able to create an output like this:
from dendropy.simulate import treesim
t = treesim.birth_death_tree(birth_rate = 1.0, death_rate = 0.5, num_extant_tips = 10)
t.print_plot()
/-------------- T3
/--------------+
/-----------------------------+ \-------------- T5
| |
| \----------------------------- T8
|
/-------------+ /----------------------------- T2
| | /--------------+
| | | | /-------------- T7
| | | \--------------+
| \--------------+ \-------------- T1
| |
+ | /----------------------------- T10
| \--------------+
| | /-------------- T6
| \--------------+
| \-------------- T4
|
\------------------------------------------------------------------------- T9
This is a great start to what I am wanting to produce but I have the following problems:
- As can be seen in the code, this is a Birth/Death process simulation, which while being a continuous time Markov branching process, is not general enough for my needs.
- The tree only leads to extinction of the branch, or the creation of two offspring, I'd ideally like something that can model any number of potential offspring, like my second diagram.
- The tree is printed to the console, rather than a figure being created. An output in a similar form to Matplotlib with a file I can easily upload and share would be ideal.
- The process tree doesn't look/feel inherently continuous, i.e with exponentially distributed lifetimes, as so many progeny seem to produce offspring at the same time.
This module also has the option to produce discrete-time Birth/Death process trees too, but with the same above problems.
If anyone had any suggestions to Python modules or resources that would help, it would be much appreciated. Thank you in advance.

