access graph edges on the triple_apply function

User 541 | 7/30/2014, 7:15:54 PM

I want to do do something like this: <code> graph.getedges(srcids=[originId],dst_ids=[None])['__dst_id']) </code>

I want to do this on the function that is passed to the triple_apply function. I know that (src, edge, dst) are parameters of the function we have to implement. Is there any way we can access specific edges on that function? the way it is posted above

Comments

User 14 | 7/30/2014, 8:19:16 PM

I guess you are trying to get the neighborhood of an specific vertex, like a "Gather" operation. 'tripleapply' is an edge based computation abstraction, so you cannot do "getedges" in side an edge apply function.

But all gather operations can be implemented using 'tripleapply'. For example, counting the degree of each vertex is the simplest gather operation, and we have example code of how to do that using tripleapply.

Degree is one example of neighborhood summary statistics, which can be cheaply computed and stored. If you really want to access the 'raw' neighborhood, you can use triple_apply to implement a similar gather like following:

\code g.vertices['neighborlist'] = gl.SArray.fromconst([], len(g.vertices)) def gatherneighborid(src, edge, dst): src['neighbor_list'].append(dst['__id']) dst['neighborlist'].append(src['__id']) return src, edge, dst g = g.tripleapply(gatherneighborid, ['neighbor_list']) \endcode

But remember, the size of neighborhood of some vertices maybe very large, especially in the social network, and it could require significant memory/disk to keep the 'neighbor_list' field.


User 1768 | 5/30/2015, 8:11:01 PM

Dear @JayGu , Your code was very useful for me. Now, I need to calculate Euclidean Distance between each user and his direct neighbors based on their features value. How I can do it with Triple_apply? If, it is not so complicated, can you please guide me? Thanks in advance