Python networkx.adamic_adar_index() Examples
The following are 8
code examples of networkx.adamic_adar_index().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
networkx
, or try the search function
.
Example #1
Source File: aa.py From GEM-Benchmark with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_edge_weight(self, i, j): aa_index = nx.adamic_adar_index(self._G, [(i, j)]) return six.next(aa_index)[2]
Example #2
Source File: link_prediction_utils.py From gcnn-survey-paper with Apache License 2.0 | 5 votes |
def adamic_adar(self): """Computes adamic adar scores.""" graph = nx.from_scipy_sparse_matrix(self.adj_matrix) scores = nx.adamic_adar_index(graph) return scores
Example #3
Source File: test_link_prediction.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 5 votes |
def setUp(self): self.func = nx.adamic_adar_index self.test = partial(_test_func, predict_func=self.func)
Example #4
Source File: test_link_prediction.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def setUp(self): self.func = nx.adamic_adar_index self.test = partial(_test_func, predict_func=self.func)
Example #5
Source File: test_link_prediction.py From aws-kube-codesuite with Apache License 2.0 | 5 votes |
def setUp(self): self.func = nx.adamic_adar_index self.test = partial(_test_func, predict_func=self.func)
Example #6
Source File: link_prediction.py From qgisSpaceSyntaxToolkit with GNU General Public License v3.0 | 4 votes |
def adamic_adar_index(G, ebunch=None): r"""Compute the Adamic-Adar index of all node pairs in ebunch. Adamic-Adar index of `u` and `v` is defined as .. math:: \sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|} where :math:`\Gamma(u)` denotes the set of neighbors of `u`. Parameters ---------- G : graph NetworkX undirected graph. ebunch : iterable of node pairs, optional (default = None) Adamic-Adar index will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all non-existent edges in the graph will be used. Default value: None. Returns ------- piter : iterator An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Adamic-Adar index. Examples -------- >>> import networkx as nx >>> G = nx.complete_graph(5) >>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)]) >>> for u, v, p in preds: ... '(%d, %d) -> %.8f' % (u, v, p) ... '(0, 1) -> 2.16404256' '(2, 3) -> 2.16404256' References ---------- .. [1] D. Liben-Nowell, J. Kleinberg. The Link Prediction Problem for Social Networks (2004). http://www.cs.cornell.edu/home/kleinber/link-pred.pdf """ if ebunch is None: ebunch = nx.non_edges(G) def predict(u, v): return sum(1 / math.log(G.degree(w)) for w in nx.common_neighbors(G, u, v)) return ((u, v, predict(u, v)) for u, v in ebunch)
Example #7
Source File: link_prediction.py From Carnets with BSD 3-Clause "New" or "Revised" License | 4 votes |
def adamic_adar_index(G, ebunch=None): r"""Compute the Adamic-Adar index of all node pairs in ebunch. Adamic-Adar index of `u` and `v` is defined as .. math:: \sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|} where $\Gamma(u)$ denotes the set of neighbors of $u$. Parameters ---------- G : graph NetworkX undirected graph. ebunch : iterable of node pairs, optional (default = None) Adamic-Adar index will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all non-existent edges in the graph will be used. Default value: None. Returns ------- piter : iterator An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Adamic-Adar index. Examples -------- >>> import networkx as nx >>> G = nx.complete_graph(5) >>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)]) >>> for u, v, p in preds: ... '(%d, %d) -> %.8f' % (u, v, p) ... '(0, 1) -> 2.16404256' '(2, 3) -> 2.16404256' References ---------- .. [1] D. Liben-Nowell, J. Kleinberg. The Link Prediction Problem for Social Networks (2004). http://www.cs.cornell.edu/home/kleinber/link-pred.pdf """ def predict(u, v): return sum(1 / log(G.degree(w)) for w in nx.common_neighbors(G, u, v)) return _apply_prediction(G, predict, ebunch)
Example #8
Source File: link_prediction.py From aws-kube-codesuite with Apache License 2.0 | 4 votes |
def adamic_adar_index(G, ebunch=None): r"""Compute the Adamic-Adar index of all node pairs in ebunch. Adamic-Adar index of `u` and `v` is defined as .. math:: \sum_{w \in \Gamma(u) \cap \Gamma(v)} \frac{1}{\log |\Gamma(w)|} where $\Gamma(u)$ denotes the set of neighbors of $u$. Parameters ---------- G : graph NetworkX undirected graph. ebunch : iterable of node pairs, optional (default = None) Adamic-Adar index will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples (u, v) where u and v are nodes in the graph. If ebunch is None then all non-existent edges in the graph will be used. Default value: None. Returns ------- piter : iterator An iterator of 3-tuples in the form (u, v, p) where (u, v) is a pair of nodes and p is their Adamic-Adar index. Examples -------- >>> import networkx as nx >>> G = nx.complete_graph(5) >>> preds = nx.adamic_adar_index(G, [(0, 1), (2, 3)]) >>> for u, v, p in preds: ... '(%d, %d) -> %.8f' % (u, v, p) ... '(0, 1) -> 2.16404256' '(2, 3) -> 2.16404256' References ---------- .. [1] D. Liben-Nowell, J. Kleinberg. The Link Prediction Problem for Social Networks (2004). http://www.cs.cornell.edu/home/kleinber/link-pred.pdf """ def predict(u, v): return sum(1 / log(G.degree(w)) for w in nx.common_neighbors(G, u, v)) return _apply_prediction(G, predict, ebunch)