networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
generate_random_paths(G, sample_size, path_length=5, index_map=None)

Parameters

G : NetworkX graph

A NetworkX graph

sample_size : integer

The number of paths to generate. This is R in .

path_length : integer (default = 5)

The maximum size of the path to randomly generate. This is T in . According to the paper, T >= 5 is recommended.

index_map : dictionary, optional

If provided, this will be populated with the inverted index of nodes mapped to the set of generated random path indices within paths .

Returns

paths : generator of lists

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`.

Examples

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)
... 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, [])]
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.similarity.generate_random_paths

Local connectivity graph

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


GitHub : /networkx/algorithms/similarity.py#1635
type: <class 'function'>
Commit: