@@ -1457,7 +1457,7 @@ def _n_choose_k(n, k):
14571457
14581458 The general equation is n! / (k! * (n - k)!). The below
14591459 implementation is a more efficient version.
1460-
1460+
14611461 Note: this will be removed in favor of Python 3.8's ``math.comb(n, k)``.
14621462
14631463 Parameters
@@ -1475,12 +1475,12 @@ def _n_choose_k(n, k):
14751475
14761476 Examples
14771477 --------
1478- >>> _n_choose_k(5, 2)
1479- 10
1480- >>> _n_choose_k(5, 4)
1481- 5
1482- >>> _n_choose_k(100, 100)
1483- 1
1478+ >>> _n_choose_k(5, 2)
1479+ 10
1480+ >>> _n_choose_k(5, 4)
1481+ 5
1482+ >>> _n_choose_k(100, 100)
1483+ 1
14841484
14851485 """
14861486 if k > n :
@@ -1494,7 +1494,7 @@ def _n_choose_k(n, k):
14941494
14951495
14961496def panther_similarity (G , source , k = 5 , path_length = 5 , c = 0.5 , delta = 0.1 , eps = None ):
1497- """Returns the Panther similarity of nodes in the graph ``G` ` to node ``v``.
1497+ """Returns the Panther similarity of nodes in the graph `G ` to node ``v``.
14981498
14991499 Panther is a similarity metric that says "two objects are considered
15001500 to be similar if they frequently appear on the same paths." [1]_.
@@ -1504,19 +1504,19 @@ def panther_similarity(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None
15041504 G : NetworkX graph
15051505 A NetworkX graph
15061506 source : node
1507- Source node for whom to find the top ``k` ` similar other nodes
1508- k : int
1507+ Source node for which to find the top `k ` similar other nodes
1508+ k : int (default = 5)
15091509 The number of most similar nodes to return
1510- path_length : int
1510+ path_length : int (default = 5)
15111511 How long the randomly generated paths should be (``T`` in [1]_)
15121512 c : float (default = 0.5)
15131513 A universal positive constant used to scale the number
15141514 of sample random paths to generate.
1515- delta : float
1515+ delta : float (default = 0.1)
15161516 The probability that the similarity $S$ is not an epsilon-approximation to (R, phi),
15171517 where $R$ is the number of random paths and $\phi$ is the probability
15181518 that an element sampled from a set $A \subseteq D$, where $D$ is the domain.
1519- eps : float
1519+ eps : float or None (default = None)
15201520 The error bound. Per [1]_, a good value is ``sqrt(1/|E|)``. Therefore,
15211521 if no value is provided, the recommended computed value will be used.
15221522
@@ -1529,8 +1529,8 @@ def panther_similarity(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None
15291529
15301530 Examples
15311531 --------
1532- >>> G = nx.star_graph(10)
1533- >>> sim = nx.panther_similarity(G, 0)
1532+ >>> G = nx.star_graph(10)
1533+ >>> sim = nx.panther_similarity(G, 0)
15341534
15351535 References
15361536 ----------
@@ -1558,17 +1558,14 @@ def panther_similarity(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None
15581558 node_map = np .array (G )
15591559
15601560 # Calculate the sample size ``R`` for how many paths
1561- # torandomly generate
1561+ # to randomly generate
15621562 t_choose_2 = _n_choose_k (path_length , 2 )
15631563 sample_size = int ((c / eps ** 2 ) * (np .log2 (t_choose_2 ) + 1 + np .log (1 / delta )))
15641564 index_map = {}
15651565 paths = generate_random_paths (
1566- G ,
1567- sample_size ,
1568- path_length = path_length ,
1569- index_map = index_map
1566+ G , sample_size , path_length = path_length , index_map = index_map
15701567 )
1571- S = np .zeros (G . number_of_nodes () )
1568+ S = np .zeros (num_nodes )
15721569
15731570 inv_sample_size = 1 / sample_size
15741571 # Calculate the path similarities
@@ -1604,17 +1601,17 @@ def panther_similarity(G, source, k=5, path_length=5, c=0.5, delta=0.1, eps=None
16041601
16051602
16061603def generate_random_paths (G , sample_size , path_length = 5 , index_map = None ):
1607- """Randomly generate `` sample_size`` paths of length `` path_length` `.
1604+ """Randomly generate `sample_size` paths of length `path_length`.
16081605
16091606 Parameters
16101607 ----------
16111608 G : NetworkX graph
16121609 A NetworkX graph
16131610 sample_size : integer
16141611 The number of paths to generate. This is ``R`` in [1]_.
1615- path_length : integer
1612+ path_length : integer (default = 5)
16161613 The maximum size of the path to randomly generate.
1617- This is ``T`` in [1]_. According to the paper, T >= 5 is
1614+ This is ``T`` in [1]_. According to the paper, `` T >= 5`` is
16181615 recommended.
16191616 index_map : dictionary, optional
16201617 If provided, this will be populated with the inverted
@@ -1624,22 +1621,22 @@ def generate_random_paths(G, sample_size, path_length=5, index_map=None):
16241621 Returns
16251622 -------
16261623 paths : generator of lists
1627- Generator of `` sample_size`` paths each with length `` path_length` `.
1624+ Generator of `sample_size` paths each with length `path_length`.
16281625
16291626 Examples
16301627 --------
1631- Note that the return value is the list of paths::
1628+ Note that the return value is the list of paths:
16321629
1633- >>> G = nx.star_graph(3)
1634- >>> random_path = nx.generate_random_paths(G, 2)
1630+ >>> G = nx.star_graph(3)
1631+ >>> random_path = nx.generate_random_paths(G, 2)
16351632
1636- By passing a dictionary into `` index_map` `, it will build an
1637- inverted index mapping of nodes to the paths in which that node is present::
1633+ By passing a dictionary into `index_map`, it will build an
1634+ inverted index mapping of nodes to the paths in which that node is present:
16381635
1639- >>> G = nx.star_graph(3)
1640- >>> index_map = {}
1641- >>> random_path = nx.generate_random_paths(G, 3, index_map=index_map)
1642- >>> paths_containing_node_0 = [random_path[path_idx] for path_idx in index_map.get(0, [])]
1636+ >>> G = nx.star_graph(3)
1637+ >>> index_map = {}
1638+ >>> random_path = nx.generate_random_paths(G, 3, index_map=index_map)
1639+ >>> paths_containing_node_0 = [random_path[path_idx] for path_idx in index_map.get(0, [])]
16431640
16441641 References
16451642 ----------
@@ -1681,8 +1678,7 @@ def generate_random_paths(G, sample_size, path_length=5, index_map=None):
16811678 # Randomly sample a neighbor (v_j) according
16821679 # to transition probabilities from ``node`` (v) to its neighbors
16831680 neighbor_index = np .random .choice (
1684- num_nodes ,
1685- p = transition_probabilities [starting_index ]
1681+ num_nodes , p = transition_probabilities [starting_index ]
16861682 )
16871683
16881684 # Set current vertex (v = v_j)
0 commit comments