[FEATURE] Hierarchy from arbitrary ordering.
JoOkuma opened this issue · comments
Hello, Benjamin
I need to build a hierarchy from an arbitrary ordering of the graph edges.
Do you think this is relevant and could be merged into the main branch?
I will probably just make a function similar to the c++ bpt_canonical
but without the edge_weights
parameter and the stable_sort
call.
Best,
Hi Jordão,
just to be sure to understand:
- do you have already sorted edge-weights ? or
- do you want edges to be taken in an arbitrary (random) order ?
FYI: I'm planning to do a refactoring of this part of the library in near future
It is closely related to the second item. I don't want to use the edge-weight for ordering. I want to give the ordering my self as an argument to build the tree.
OK I see, I plan to add this feature in the future interface. For the moment an easy way to do it is to use the ranks in your ordering as edge weights. E.g.
# complete graph with 3 vertices
g = UndirectedGraph(3)
# the edges are (in order) {0,1}, {0, 2}, and {1,2}
g.add_edges([0, 0, 1], [1, 2, 2])
# assume that we want to take edges in the following order {0,2} (rank 0), {1, 2} (rank 1) and {0,1} (rank 2)
rank_weights = [2, 0, 1]
tree, altitudes = bpt_canonical(g, rank_weights)
ok, thanks.