About avg_neighbour_corr
Dear Tiago, Graph-tool is a great and ultra-fast library. It saved me tons of hours doing some statistics with heavy graphs. Thank you so much for your great work. However, right now I'm having some troubles with the function avg_neighbour_corr. I must missing something, but I don't know what it is. Imagine we consider a directed graph g, and its reverse graph h. Then, if we calculate goo = avg_neighbour_corr(g, "out", "out") hii = avg_neighbour_corr(h, "in", "in") I guessed both results should be the same, but they are not. It must be related to the results of the function corr_hist, which returns the transposed matrix of g for h. However, I fail to see why, considering that the in-degree vertex property of h is the same as the out-degree vertex property of g, and all edges are reversed in h. Any help, please? Thanks in advance. Best, Sara. PS: Here is the code of a dummy example for a network g given by: (2) <==> (0) ----> (1) ----> (2) #### code g = gt.Graph() g.add_edge_list([(0,1), (0,2), (1,2), (2,0)]) h = gt.GraphView(g, reversed = True) goo = avg_neighbour_corr(g, "out", "out") hii = avg_neighbour_corr(h, "in", "in") #### end of code #### results # >>> goo[0] # array([ nan, 1.5, 1. ]) # >>> hii[0] # array([ nan, 1.66666667, 1. ]) -- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
On 18.02.2016 15:37, scuenda wrote:
Imagine we consider a directed graph g, and its reverse graph h. Then, if we calculate goo = avg_neighbour_corr(g, "out", "out") hii = avg_neighbour_corr(h, "in", "in") I guessed both results should be the same, but they are not.
They are not the same because the direction of the edge is used to determine the source and target. Although the out- and in-degrees are swapped in the reversed graphs, so are the sources and targets. For example, if we have an edge: (a) -> (b) and the in,out-degrees of a and b are (0, 3) and (4, 1), respectively. This edge will count the value "4" in the average for sources with out-degree 0. Once we transpose the graph we have (a) <- (b) with in,out-degrees (3, 0), (1, 4). This edge now will contribute the value "3" in the average for sources with in-degree 1. It is not quite the same as before. Best, Tiago -- Tiago de Paula Peixoto <tiago@skewed.de>
Tiago Peixoto wrote
They are not the same because the direction of the edge is used to determine the source and target. Although the out- and in-degrees are swapped in the reversed graphs, so are the sources and targets.
Thank you for your kind response I realized my mistake by playing with a python function which replicates the results of avg_neighbour_corr for both "in" and "out" neighbors using an integer vertex property for p1 (the equivalent to "source_deg" in the original function). I posted my own response in the forum, but I don't know if it got to the mailing list... problems with posting before subscription confirmation Just in case, here it goes: scuenda wrote
def avg_nn_corr(g, nn_dir, p1, p2): kmax = p1.a.max() dnorm = np.zeros(kmax+1, dtype = float) dsum = np.zeros(kmax+1, dtype = float) dsum2 = np.zeros(kmax+1, dtype = float) if nn_dir == "in": neighbours = lambda v: v.in_neighbours() elif nn_dir == "out": neighbours = lambda v: v.out_neighbours() for v in g.vertices(): k1 = p1[v] k2v = np.array([p2[w] for w in neighbours(v)]) dnorm[k1] += len(k2v) s = k2v.sum() s2 = (k2v**2).sum() dsum[k1] += s dsum2[k1] += s2 pnn = dsum/dnorm snn = np.sqrt((dsum2/dnorm - pnn**2)/(dnorm)) return pnn , snn
-- View this message in context: http://main-discussion-list-for-the-graph-tool-project.982480.n3.nabble.com/... Sent from the Main discussion list for the graph-tool project mailing list archive at Nabble.com.
participants (2)
-
scuenda -
Tiago de Paula Peixoto