tidygraph icon indicating copy to clipboard operation
tidygraph copied to clipboard

Allow aggregation functions in node_distance_from/to

Open dmi3kno opened this issue 8 years ago • 4 comments

Closes #26

dmi3kno avatar Nov 10 '17 00:11 dmi3kno

I'm unsure what the use of this is for? Can you describe your intended use case in more detail than provided in #26?

In general the node_distance_[from|to]() functions are intended for calculating the distance between node pairs, not some statistic on the distance distribution to all nodes...

thomasp85 avatar Nov 14 '17 13:11 thomasp85

Currently node_distance_[from|to](nodes, mode, weights, algorithm) allow supplying node_type functions and therefore often used with node_is_root()) that is guaranteed to return single node. The function is relying on recycling without validating (or warning) whether such recycling makes sense.

What I am proposing is that the default behavior of the node_distance_from|to should be aggregation, unless user stipulates otherwise. In fact, calculating distance to single node is a particular example of an "identity" aggregation.

Let's say user wants to see how far is the node from center of the network using node_is_center(). If by any chance two nodes share same eccentricity, distance function will return meaningless results. However, if central nodes are close to each other, returning average of individual distances to those nodes might still make sense (central nodes are likely to be close to each other).

In my use case I needed to check the minimum distance to leaves in the tree to measure the node "hierarchy level". Again, I was interested in aggregation using min(), but other function might also make sense.

You may argue that the function that I am after shall be called node_distance_[from|to]_summarise().

dmi3kno avatar Dec 21 '17 15:12 dmi3kno

I will definitely not repurpose the node pair functions to return summaries. I do see and understand your use case but I’ll need a bit more time to think about the best API for it

thomasp85 avatar Dec 22 '17 18:12 thomasp85

Happy to discuss further and, once agreed on the vision, contribute PR. God Jul! 🎄

dmi3kno avatar Dec 22 '17 18:12 dmi3kno