generate_random_paths(G, sample_size, path_length=5, index_map=None)
A NetworkX graph
The number of paths to generate. This is R
in .
The maximum size of the path to randomly generate. This is T
in . According to the paper, T >= 5
is recommended.
If provided, this will be populated with the inverted index of nodes mapped to the set of generated random path indices within paths
.
Generator of :None:None:`sample_size`
paths each with length :None:None:`path_length`
.
Randomly generate :None:None:`sample_size`
paths of length :None:None:`path_length`
.
Note that the return value is the list of paths:
>>> G = nx.star_graph(3)
... random_path = nx.generate_random_paths(G, 2)
By passing a dictionary into :None:None:`index_map`
, it will build an inverted index mapping of nodes to the paths in which that node is present:
>>> G = nx.star_graph(3)See :
... index_map = {}
... random_path = nx.generate_random_paths(G, 3, index_map=index_map)
... paths_containing_node_0 = [random_path[path_idx] for path_idx in index_map.get(0, [])]
The following pages refer to to this document either explicitly or contain code examples using this.
networkx.algorithms.similarity.generate_random_paths
Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.
Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)
SVG is more flexible but power hungry; and does not scale well to 50 + nodes.
All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them