Skip to content

Added "initial_node" param to generate_random_paths() to allow a starting node to be specified for generated walks - #8002

Merged
Schefflera-Arboricola merged 3 commits into
networkx:mainfrom
khughitt:random_paths_from_x
Apr 30, 2025
Merged

Schefflera-Arboricola merged 3 commits into
networkx:mainfrom
khughitt:random_paths_from_x

Conversation

@khughitt

Copy link
Copy Markdown
Contributor

Small modification to allow the user to specify an initial node to begin all walks from.

…ng node to be specified for all generated paths.
Comment thread networkx/algorithms/similarity.py Outdated
index_map=None,
weight="weight",
seed=None,
initial_node=None,

@Schefflera-Arboricola Schefflera-Arboricola Apr 27, 2025 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @khughitt !

In most of the networkx algorithms, the starting node is referred to as source.

Suggested change
initial_node=None,
source=None,

Also, we can consider adding a target (ending node) parameter here too. btw, not a blocker for this PR :)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That's good to know.

I also tried to keep seed at the end of the args -- not always the case in networkx, but often the case -- but I ran into issues possibly relating to the dispatcher logic and eventually settled for adding the new arg at the end.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please make this new arg keyword-only. We won't do that for the existing keywords, but new keywords shouldn't be referred to by position. So put an argument *, just before the source=None line.

@dschult dschult left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. And it seems like a reasonable feature.

Question for you: Are you adding this as a helpful tool for panther similarity? Or are you using generate_random_paths without regard to panther similarity? Thanks!

@khughitt

Copy link
Copy Markdown
Contributor Author

I am adding this for it's own sake. I wasn't actually aware of panther similarity until this discussion / running the tests for the PR, so that was a pleasant discovery :)

@Schefflera-Arboricola Schefflera-Arboricola left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @khughitt and @dschult :)

@dschult

dschult commented Apr 30, 2025

Copy link
Copy Markdown
Member

Thanks for that feedback. We have an issue #8005 which is considering making this function more prominent and perhaps more aligned with what folks that need it would like. Constructing random walks seems like something we should provide more easily. If you have ideas or suggestions we'd like to hear them :)

MridulS pushed a commit that referenced this pull request May 2, 2025
* Refactor generate_random_paths with source test.

* Add test for source not in G.

* Add pytest.importorskip.
@jarrodmillman jarrodmillman added this to the 3.5 milestone May 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

4 participants