-
Notifications
You must be signed in to change notification settings - Fork 74
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document traversal arrays and illustrate usage #1788
Comments
It would indeed be good to write the docstrings for these methods. Re examples, I've looked though the standard docs and we don't really document examples of using tree traversals there. The main text describing traversals is in the tutorials. I think we should describe an example there and provide a link from the docstring. |
Here's a trivial example: count the average node arity of a tree
On a 100,000 tip tree this seems to be about 6 times faster than doing
A bit crap because it doesn't help with incremental calculations, but it is a very simple example, which is nice. |
That's a nice example @hyanwong, I like it. Might as well use |
Simplest example I can think of is time = ts.tables.nodes.time
nodes = tree.preorder()
branch_length = time[tree.parent_array[nodes]] - time[nodes]
branch_length[tree.parent_array[nodes] == tskit.NULL] = 0
print(branch_length)
print(np.array([tree.branch_length(u) for u in tree.nodes()])) This is tricky though as we have to be careful about the branch lengths of the roots. That's possibly a good thing to warn people about if they're using these arrays though, as Python will quite happily use |
I think we can close this, as my example is in the docs, and @jeromekelleher 's example is linked to from tskit-dev/tutorials#150 (comment) |
#1704 added numpy array versions of the basic tree traversal orders. Document these and provide an example of how they might be used. It would be neat if we could illustrate with some phylo algorithm that can be implemented directly with (non-obscure) numpy calls.
The text was updated successfully, but these errors were encountered: